/**
  * Accepts an invoice or creditmemo and returns an \AvaTax\Line object
  *
  * @param \Magento\Sales\Api\Data\InvoiceInterface|\Magento\Sales\Api\Data\CreditmemoInterface $data
  * @param $credit
  * @return \AvaTax\Line|bool
  * @throws MetaData\ValidationException
  */
 public function getGiftWrapItemsLine($data, $credit)
 {
     $giftWrapItemsPrice = $data->getGwItemsBasePrice();
     if ($giftWrapItemsPrice <= 0) {
         return false;
     }
     //        $qty = $data->getTotalQty();
     //        $giftWrapItemAmount = $giftWrapItemsPrice * $qty;
     $giftWrapItemAmount = $giftWrapItemsPrice;
     if ($credit) {
         $giftWrapItemAmount *= -1;
     }
     $storeId = $data->getStoreId();
     $itemCode = $this->config->getSkuShippingGiftWrapItem($storeId);
     $data = ['No' => $this->getLineNumber(), 'ItemCode' => $itemCode, 'TaxCode' => $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId), 'Description' => self::GIFT_WRAP_ITEM_LINE_DESCRIPTION, 'Qty' => 1, 'Amount' => $giftWrapItemAmount, 'Discounted' => false];
     try {
         $data = $this->metaDataObject->validateData($data);
     } catch (ValidationException $e) {
         $this->avaTaxLogger->error('Error validating line: ' . $e->getMessage(), ['data' => var_export($data, true)]);
     }
     /** @var $line \AvaTax\Line */
     $line = $this->lineFactory->create();
     $this->populateLine($data, $line);
     return $line;
 }
Beispiel #2
0
 /**
  * Map item extra taxables
  *
  * @param QuoteDetailsItemInterfaceFactory $itemDataObjectFactory
  * @param Item\AbstractItem $item
  * @param bool $priceIncludesTax
  * @param bool $useBaseCurrency
  * @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface[]
  */
 public function mapItemExtraTaxables(QuoteDetailsItemInterfaceFactory $itemDataObjectFactory, Item\AbstractItem $item, $priceIncludesTax, $useBaseCurrency)
 {
     $itemDataObjects = parent::mapItemExtraTaxables($itemDataObjectFactory, $item, $priceIncludesTax, $useBaseCurrency);
     $storeId = $item->getStore()->getId();
     if (!$this->config->isModuleEnabled($storeId) || $this->config->getTaxMode($storeId) == Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT) {
         return $itemDataObjects;
     }
     foreach ($itemDataObjects as $itemDataObject) {
         switch ($itemDataObject->getType()) {
             case Giftwrapping::ITEM_TYPE:
                 $itemCode = $this->config->getSkuShippingGiftWrapItem($storeId);
                 $taxCode = $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId);
                 $this->addExtensionAttributesToTaxQuoteDetailsItem($itemDataObject, $itemCode, $taxCode, \ClassyLlama\AvaTax\Framework\Interaction\Line::GIFT_WRAP_ITEM_LINE_DESCRIPTION);
                 break;
         }
     }
     return $itemDataObjects;
 }