You are here

public function ProductVariationTaxCodeResolver::resolve in Drupal Commerce Connector for AvaTax 8

Resolves the tax code of a given order item..

Parameters

\Drupal\commerce_order\Entity\OrderItemInterface $order_item: The purchaseable entity.

Return value

string The tax code.

Overrides TaxCodeResolverInterface::resolve

File

src/Resolver/ProductVariationTaxCodeResolver.php, line 16

Class

ProductVariationTaxCodeResolver
Resolves tax code based on product variation value.

Namespace

Drupal\commerce_avatax\Resolver

Code

public function resolve(OrderItemInterface $order_item) {
  $purchased_entity = $order_item
    ->getPurchasedEntity();
  if ($purchased_entity instanceof ProductVariationInterface) {
    if (!$purchased_entity
      ->get('avatax_tax_code')
      ->isEmpty()) {
      return $purchased_entity
        ->get('avatax_tax_code')->value;
    }
  }
}