Esempio n. 1
0
 /**
  * Return an array with relevant data from an credit memo item
  *
  * @param \Magento\Sales\Api\Data\CreditmemoItemInterface $item
  * @return array|bool
  */
 protected function convertCreditMemoItemToData(\Magento\Sales\Api\Data\CreditmemoItemInterface $item)
 {
     if (!$this->isProductCalculated($item->getOrderItem())) {
         return false;
     }
     // The AvaTax 15 API doesn't support the concept of line-based discounts, so subtract discount amount
     // from taxable amount
     $amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
     // Credit memo amounts need to be sent to AvaTax as negative numbers
     $amount *= -1;
     if ($item->getQty() == 0 || $amount == 0) {
         return false;
     }
     $product = $item->getOrderItem()->getProduct();
     $itemCode = $this->taxClassHelper->getItemCodeOverride($product);
     if (!$itemCode) {
         $itemCode = $item->getSku();
     }
     $storeId = $item->getStoreId();
     return ['StoreId' => $storeId, 'No' => $this->getLineNumber(), 'ItemCode' => $itemCode, 'TaxCode' => $this->taxClassHelper->getAvataxTaxCodeForProduct($product, $storeId), 'Description' => $item->getName(), 'Qty' => $item->getQty(), 'Amount' => $amount, 'Discounted' => (bool) ($item->getBaseDiscountAmount() > 0), 'TaxIncluded' => false, 'Ref1' => $this->taxClassHelper->getRef1ForProduct($product), 'Ref2' => $this->taxClassHelper->getRef2ForProduct($product)];
 }
Esempio n. 2
0
 /**
  * Map an item to item data object. Add AvaTax details to extension objects.
  *
  * @param QuoteDetailsItemInterfaceFactory $itemDataObjectFactory
  * @param Item\AbstractItem $item
  * @param bool $priceIncludesTax
  * @param bool $useBaseCurrency
  * @param string $parentCode
  * @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface
  */
 public function mapItem(QuoteDetailsItemInterfaceFactory $itemDataObjectFactory, Item\AbstractItem $item, $priceIncludesTax, $useBaseCurrency, $parentCode = null)
 {
     $quoteDetailsItem = parent::mapItem($itemDataObjectFactory, $item, $priceIncludesTax, $useBaseCurrency, $parentCode);
     $storeId = $item->getStore()->getId();
     if (!$this->config->isModuleEnabled($storeId) || $this->config->getTaxMode($storeId) == Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT) {
         return $quoteDetailsItem;
     }
     /** @var \Magento\Tax\Api\Data\QuoteDetailsItemExtensionInterface $extensionAttribute */
     $extensionAttribute = $quoteDetailsItem->getExtensionAttributes() ? $quoteDetailsItem->getExtensionAttributes() : $this->extensionFactory->create();
     $product = $item->getProduct();
     $taxCode = $this->taxClassHelper->getAvataxTaxCodeForProduct($product, $storeId);
     $itemCode = $this->taxClassHelper->getItemCodeOverride($product);
     if (!$itemCode) {
         $itemCode = $item->getSku();
     }
     $extensionAttribute->setAvataxItemCode($itemCode);
     $extensionAttribute->setAvataxTaxCode($taxCode);
     $extensionAttribute->setAvataxDescription($item->getName());
     $extensionAttribute->setAvataxRef1($this->taxClassHelper->getRef1ForProduct($product));
     $extensionAttribute->setAvataxRef2($this->taxClassHelper->getRef2ForProduct($product));
     $quoteDetailsItem->setExtensionAttributes($extensionAttribute);
     return $quoteDetailsItem;
 }