Пример #1
0
 /**
  * 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 getGiftWrapOrderLine($data, $credit)
 {
     $giftWrapOrderAmount = $data->getGwBasePrice();
     if ($giftWrapOrderAmount <= 0) {
         return false;
     }
     if ($credit) {
         $giftWrapOrderAmount *= -1;
     }
     $storeId = $data->getStoreId();
     $itemCode = $this->config->getSkuGiftWrapOrder($storeId);
     $data = ['No' => $this->getLineNumber(), 'ItemCode' => $itemCode, 'TaxCode' => $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId), 'Description' => self::GIFT_WRAP_ORDER_LINE_DESCRIPTION, 'Qty' => 1, 'Amount' => $giftWrapOrderAmount, '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;
 }
Пример #2
0
 /**
  * Map extra taxables associated with quote. Add AvaTax details to extension objects.
  *
  * @param QuoteDetailsItemInterfaceFactory $itemDataObjectFactory
  * @param Address $address
  * @param bool $useBaseCurrency
  * @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface[]
  */
 public function mapQuoteExtraTaxables(QuoteDetailsItemInterfaceFactory $itemDataObjectFactory, Address $address, $useBaseCurrency)
 {
     $itemDataObjects = parent::mapQuoteExtraTaxables($itemDataObjectFactory, $address, $useBaseCurrency);
     $storeId = $address->getQuote()->getStore()->getId();
     if (!$this->config->isModuleEnabled($storeId) || $this->config->getTaxMode($storeId) == Config::TAX_MODE_NO_ESTIMATE_OR_SUBMIT || !$this->config->isAddressTaxable($address, $storeId)) {
         return $itemDataObjects;
     }
     foreach ($itemDataObjects as $itemDataObject) {
         switch ($itemDataObject->getType()) {
             case Giftwrapping::QUOTE_TYPE:
                 $itemCode = $this->config->getSkuGiftWrapOrder($storeId);
                 $taxCode = $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId);
                 $this->addExtensionAttributesToTaxQuoteDetailsItem($itemDataObject, $itemCode, $taxCode, \ClassyLlama\AvaTax\Framework\Interaction\Line::GIFT_WRAP_ORDER_LINE_DESCRIPTION);
                 break;
             case Giftwrapping::PRINTED_CARD_TYPE:
                 $itemCode = $this->config->getSkuShippingGiftWrapCard($storeId);
                 $taxCode = $this->taxClassHelper->getAvataxTaxCodeForGiftOptions($storeId);
                 $this->addExtensionAttributesToTaxQuoteDetailsItem($itemDataObject, $itemCode, $taxCode, \ClassyLlama\AvaTax\Framework\Interaction\Line::GIFT_WRAP_ORDER_LINE_DESCRIPTION);
                 break;
         }
     }
     return $itemDataObjects;
 }