Example #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 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;
 }