Esempio n. 1
0
 /**
  * Makes a Line object from a product item object
  *
  * @param Varien_Object|Mage_Sales_Model_Quote_Item $item
  * @return int|bool
  */
 protected function _newLine($item)
 {
     if (!$item->getId()) {
         $this->setCanSendRequest(false);
         return $this;
     }
     $this->_addGwItemsAmount($item);
     if ($this->isProductCalculated($item)) {
         return false;
     }
     $product = $this->_getProductByProductId($this->_retrieveProductIdFromQuoteItem($item));
     $taxClass = $this->_getTaxClassCodeByProduct($product);
     $price = $item->getBaseRowTotal();
     if ($this->_getTaxDataHelper()->applyTaxAfterDiscount($item->getStoreId())) {
         $price = $item->getBaseRowTotal() - $item->getBaseDiscountAmount();
     }
     $lineNumber = count($this->_lines);
     $line = new Line();
     $line->setNo($lineNumber);
     $line->setItemCode($this->_getCalculationHelper()->getItemCode($this->_getProductForItemCode($item), $item->getStoreId()));
     $line->setDescription($item->getName());
     $line->setQty($item->getTotalQty());
     $line->setAmount($price);
     $line->setDiscounted((double) $item->getDiscountAmount() && $this->_getTaxDataHelper()->applyTaxAfterDiscount($item->getStoreId()));
     if ($this->_getTaxDataHelper()->priceIncludesTax($item->getStoreId())) {
         $line->setTaxIncluded(true);
     }
     if ($taxClass) {
         $line->setTaxCode($taxClass);
     }
     $ref1Value = $this->_getRefValueByProductAndNumber($product, 1, $item->getStoreId());
     if ($ref1Value) {
         $line->setRef1($ref1Value);
     }
     $ref2Value = $this->_getRefValueByProductAndNumber($product, 2, $item->getStoreId());
     if ($ref2Value) {
         $line->setRef2($ref2Value);
     }
     $this->_lines[$lineNumber] = $line;
     $this->_lineToLineId[$lineNumber] = $item->getId();
     return $lineNumber;
 }
Esempio n. 2
0
 /**
  * Makes a Line object from a product item object
  *
  * @param Mage_Sales_Model_Order_Invoice_Item|Mage_Sales_Model_Order_Creditmemo_Item $item
  * @param bool $credit
  * @return null
  */
 protected function _newLine($item, $credit = false)
 {
     if ($this->isProductCalculated($item->getOrderItem())) {
         return false;
     }
     if ($item->getQty() == 0) {
         return false;
     }
     $line = new Line();
     $storeId = $this->_retrieveStoreIdFromItem($item);
     $price = $item->getBaseRowTotal();
     if ($this->_getTaxDataHelper()->priceIncludesTax($storeId)) {
         $line->setTaxIncluded(true);
         $price = $item->getBaseRowTotalInclTax();
     }
     if ($this->_getTaxDataHelper()->applyTaxAfterDiscount($storeId)) {
         $price -= $item->getBaseDiscountAmount();
     }
     if ($credit) {
         //@startSkipCommitHooks
         $price *= -1;
         //@finishSkipCommitHooks
     }
     $line->setNo(count($this->_lines));
     $line->setItemCode($this->_getCalculationHelper()->getItemCode($this->_getProductForItemCode($item), $storeId, $item));
     $line->setDescription($item->getName());
     $line->setQty($item->getQty());
     $line->setAmount($price);
     $line->setDiscounted((double) $item->getBaseDiscountAmount() && $this->_getTaxDataHelper()->applyTaxAfterDiscount($storeId));
     $productData = $this->_getLineProductData($item, $storeId);
     $line->setTaxCode($productData->getTaxCode());
     $line->setRef1($productData->getRef1());
     $line->setRef2($productData->getRef2());
     $this->_lineToItemId[count($this->_lines)] = $item->getOrderItemId();
     $this->_lines[] = $line;
 }
Esempio n. 3
0
 /**
  * Adds adjustments to request as items
  *
  * @param float $positive
  * @param float $negative
  * @param int   $storeId
  * @return array
  */
 protected function _addAdjustments($positive, $negative, $storeId)
 {
     if ($positive != 0) {
         $lineNumber = count($this->_lines);
         $identifier = Mage::helper('avatax')->getPositiveAdjustmentSku($storeId);
         $line = new Line();
         $line->setNo($lineNumber);
         $line->setItemCode($identifier ? $identifier : 'adjustment');
         $line->setDescription('Adjustment refund');
         $line->setTaxCode($identifier);
         $line->setQty(1);
         $line->setAmount($positive * -1);
         $line->setDiscounted(false);
         $line->setTaxIncluded(true);
         $this->_lineToItemId[$lineNumber] = 'positive-adjustment';
         $this->_lines[$lineNumber] = $line;
         $this->_request->setLines($this->_lines);
     }
     if ($negative != 0) {
         $lineNumber = count($this->_lines);
         $identifier = Mage::helper('avatax')->getNegativeAdjustmentSku($storeId);
         $line = new Line();
         $line->setNo($lineNumber);
         $line->setItemCode($identifier ? $identifier : 'adjustment');
         $line->setDescription('Adjustment fee');
         $line->setTaxCode($identifier);
         $line->setQty(1);
         $line->setAmount($negative);
         $line->setDiscounted(false);
         $line->setTaxIncluded(true);
         $this->_lineToItemId[$lineNumber] = 'negative-adjustment';
         $this->_lines[$lineNumber] = $line;
         $this->_request->setLines($this->_lines);
     }
 }