/**
  * Calculates the total quantity for this item.
  *
  * What this really means is that if this is a child item, it return the parent quantity times
  * the child quantity and return that as the child's quantity.
  *
  * @param QuoteDetailsItemInterface $item
  * @return float
  */
 protected function getTotalQuantity(QuoteDetailsItemInterface $item)
 {
     if ($item->getParentCode()) {
         $parentQuantity = $this->keyedItems[$item->getParentCode()]->getQuantity();
         return $parentQuantity * $item->getQuantity();
     }
     return $item->getQuantity();
 }
 /**
  * Convert \Magento\Tax\Model\Sales\Quote\ItemDetails to an array to be used for building an \AvaTax\Line object
  *
  * @param \Magento\Tax\Api\Data\QuoteDetailsItemInterface $item
  * @return array
  */
 protected function convertTaxQuoteDetailsItemToData(\Magento\Tax\Api\Data\QuoteDetailsItemInterface $item)
 {
     $extensionAttributes = $item->getExtensionAttributes();
     if ($extensionAttributes) {
         $quantity = $extensionAttributes->getTotalQuantity() !== null ? $extensionAttributes->getTotalQuantity() : $item->getQuantity();
     } else {
         $quantity = $item->getQuantity();
     }
     $itemCode = $extensionAttributes ? $extensionAttributes->getAvataxItemCode() : '';
     $description = $extensionAttributes ? $extensionAttributes->getAvataxDescription() : '';
     $taxCode = $extensionAttributes ? $extensionAttributes->getAvataxTaxCode() : null;
     // The AvaTax 15 API doesn't support the concept of line-based discounts, so subtract discount amount
     // from taxable amount
     $amount = $item->getUnitPrice() * $quantity - $item->getDiscountAmount();
     $ref1 = $extensionAttributes ? $extensionAttributes->getAvataxRef1() : null;
     $ref2 = $extensionAttributes ? $extensionAttributes->getAvataxRef2() : null;
     return ['No' => $item->getCode(), 'ItemCode' => $itemCode, 'TaxCode' => $taxCode, 'Description' => $description, 'Qty' => $item->getQuantity(), 'Amount' => $amount, 'Discounted' => (bool) ($item->getDiscountAmount() > 0), 'TaxIncluded' => false, 'Ref1' => $ref1, 'Ref2' => $ref2];
 }
 /**
  * Calculates the total quantity for this item.
  *
  * What this really means is that if this is a child item, it return the parent quantity times
  * the child quantity and return that as the child's quantity. This code is a duplicate of the
  * @see \Magento\Tax\Model\TaxCalculation::getTotalQuantity()
  * method, but is refactored to accept the $keyedItems array.
  *
  * @param QuoteDetailsItemInterface $item
  * @param array $keyedItems
  * @return float
  */
 public function calculateTotalQuantity(QuoteDetailsItemInterface $item, array $keyedItems)
 {
     if ($item->getParentCode()) {
         $parentQuantity = $keyedItems[$item->getParentCode()]->getQuantity();
         return $parentQuantity * $item->getQuantity();
     }
     return $item->getQuantity();
 }