예제 #1
0
 /**
  * Convert quote item to order item
  *
  * @param   Mage_Sales_Model_Quote_Item_Abstract $item
  * @return  Mage_Sales_Model_Order_Item
  */
 public function itemToOrderItem(Mage_Sales_Model_Quote_Item_Abstract $item)
 {
     $orderItem = Mage::getModel('sales/order_item')->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setProductId($item->getProductId())->setSuperProductId($item->getSuperProductId())->setParentProductId($item->getParentProductId())->setSku($item->getSku())->setName($item->getName())->setDescription($item->getDescription())->setWeight($item->getWeight())->setIsQtyDecimal($item->getIsQtyDecimal())->setQtyOrdered($item->getQty())->setOriginalPrice($item->getOriginalPrice())->setAppliedRuleIds($item->getAppliedRuleIds())->setAdditionalData($item->getAdditionalData())->setPrice($item->getCalculationPrice())->setTaxPercent($item->getTaxPercent())->setTaxAmount($item->getTaxAmount())->setRowWeight($item->getRowWeight())->setRowTotal($item->getRowTotal())->setBasePrice($item->getBaseCalculationPrice())->setBaseOriginalPrice($item->getPrice())->setBaseTaxAmount($item->getBaseTaxAmount())->setBaseRowTotal($item->getBaseRowTotal());
     if (!$item->getNoDiscount()) {
         $orderItem->setDiscountPercent($item->getDiscountPercent())->setDiscountAmount($item->getDiscountAmount())->setBaseDiscountAmount($item->getBaseDiscountAmount());
     }
     Mage::dispatchEvent('sales_convert_quote_item_to_order_item', array('order_item' => $orderItem, 'item' => $item));
     return $orderItem;
 }
예제 #2
0
파일: Tax.php 프로젝트: nemphys/magento2
 /**
  * Aggregate row totals per tax rate in array
  *
  * @param   Mage_Sales_Model_Quote_Item_Abstract $item
  * @param   float $rate
  * @param   array $taxGroups
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _aggregateTaxPerRate($item, $rate, &$taxGroups)
 {
     $inclTax = $item->getIsPriceInclTax();
     $rateKey = (string) $rate;
     $taxSubtotal = $subtotal = $item->getTaxableAmount() + $item->getExtraRowTaxableAmount();
     $baseTaxSubtotal = $baseSubtotal = $item->getBaseTaxableAmount() + $item->getBaseExtraRowTaxableAmount();
     $item->setTaxPercent($rate);
     if (!isset($taxGroups[$rateKey]['totals'])) {
         $taxGroups[$rateKey]['totals'] = array();
         $taxGroups[$rateKey]['base_totals'] = array();
     }
     $hiddenTax = null;
     $baseHiddenTax = null;
     switch ($this->_helper->getCalculationSequence($this->_store)) {
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
             $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false);
             $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false);
             break;
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
             if ($this->_helper->applyTaxOnOriginalPrice($this->_store)) {
                 $discount = $item->getOriginalDiscountAmount();
                 $baseDiscount = $item->getBaseOriginalDiscountAmount();
             } else {
                 $discount = $item->getDiscountAmount();
                 $baseDiscount = $item->getBaseDiscountAmount();
             }
             $taxSubtotal = max($subtotal - $discount, 0);
             $baseTaxSubtotal = max($baseSubtotal - $baseDiscount, 0);
             $rowTax = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, $inclTax, false);
             $baseRowTax = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, $inclTax, false);
             if (!$item->getNoDiscount() && $item->getWeeeTaxApplied()) {
                 $rowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false);
                 $baseRowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false);
             }
             if ($inclTax && $discount > 0) {
                 $hiddenTax = $this->_calculator->calcTaxAmount($discount, $rate, $inclTax, false);
                 $baseHiddenTax = $this->_calculator->calcTaxAmount($baseDiscount, $rate, $inclTax, false);
                 $this->_hiddenTaxes[] = array('rate_key' => $rateKey, 'qty' => 1, 'item' => $item, 'value' => $hiddenTax, 'base_value' => $baseHiddenTax, 'incl_tax' => $inclTax);
             }
             break;
     }
     $rowTax = $this->_deltaRound($rowTax, $rateKey, $inclTax);
     $baseRowTax = $this->_deltaRound($baseRowTax, $rateKey, $inclTax, 'base');
     $item->setTaxAmount(max(0, $rowTax));
     $item->setBaseTaxAmount(max(0, $baseRowTax));
     if (isset($rowTaxBeforeDiscount) && isset($baseRowTaxBeforeDiscount)) {
         $taxBeforeDiscount = max(0, $this->_deltaRound($rowTaxBeforeDiscount, $rateKey, $inclTax));
         $baseTaxBeforeDiscount = max(0, $this->_deltaRound($baseRowTaxBeforeDiscount, $rateKey, $inclTax, 'base'));
         $item->setDiscountTaxCompensation($taxBeforeDiscount - max(0, $rowTax));
         $item->setBaseDiscountTaxCompensation($baseTaxBeforeDiscount - max(0, $baseRowTax));
     }
     $taxGroups[$rateKey]['totals'][] = max(0, $taxSubtotal);
     $taxGroups[$rateKey]['base_totals'][] = max(0, $baseTaxSubtotal);
     return $this;
 }
예제 #3
0
파일: Tax.php 프로젝트: blazeriaz/youguess
 /**
  * Aggregate row totals per tax rate in array
  *
  * @param   Mage_Sales_Model_Quote_Item_Abstract $item
  * @param   float $rate
  * @param   array $taxGroups
  * @return  Mage_Tax_Model_Sales_Total_Quote
  */
 protected function _aggregateTaxPerRate($item, $rate, &$taxGroups)
 {
     $inclTax = $item->getIsPriceInclTax();
     $rateKey = (string) $rate;
     $taxSubtotal = $subtotal = $item->getTaxableAmount();
     $baseTaxSubtotal = $baseSubtotal = $item->getBaseTaxableAmount();
     $isWeeeEnabled = $this->_weeeHelper->isEnabled();
     $isWeeeTaxable = $this->_weeeHelper->isTaxable();
     $item->setTaxPercent($rate);
     if (!isset($taxGroups[$rateKey]['totals'])) {
         $taxGroups[$rateKey]['totals'] = array();
         $taxGroups[$rateKey]['base_totals'] = array();
         $taxGroups[$rateKey]['weee_tax'] = array();
         $taxGroups[$rateKey]['base_weee_tax'] = array();
     }
     $hiddenTax = null;
     $baseHiddenTax = null;
     switch ($this->_helper->getCalculationSequence($this->_store)) {
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
             $rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false);
             $baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false);
             if ($isWeeeEnabled && $isWeeeTaxable) {
                 $weeeTax = $item->getWeeeTaxAppliedRowAmount() * $rate / 100;
                 $baseWeeeTax = $item->getBaseWeeeTaxAppliedRowAmount() * $rate / 100;
                 $rowTax += $weeeTax;
                 $baseRowTax += $baseWeeeTax;
                 $taxGroups[$rateKey]['weee_tax'][] = $this->_deltaRound($weeeTax, $rateKey, $inclTax);
                 $taxGroups[$rateKey]['base_weee_tax'][] = $this->_deltaRound($baseWeeeTax, $rateKey, $inclTax);
             }
             break;
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
         case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
             if ($this->_helper->applyTaxOnOriginalPrice($this->_store)) {
                 $discount = $item->getOriginalDiscountAmount();
                 $baseDiscount = $item->getBaseOriginalDiscountAmount();
             } else {
                 $discount = $item->getDiscountAmount();
                 $baseDiscount = $item->getBaseDiscountAmount();
             }
             //weee discount should be removed when calculating hidden tax
             if ($isWeeeEnabled) {
                 $discount = $discount - $item->getWeeeDiscount();
                 $baseDiscount = $baseDiscount - $item->getBaseWeeeDiscount();
             }
             $taxSubtotal = max($subtotal - $discount, 0);
             $baseTaxSubtotal = max($baseSubtotal - $baseDiscount, 0);
             $rowTax = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, $inclTax, false);
             $baseRowTax = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, $inclTax, false);
             if ($isWeeeEnabled && $this->_weeeHelper->isTaxable()) {
                 $weeeTax = ($item->getWeeeTaxAppliedRowAmount() - $item->getWeeeDiscount()) * $rate / 100;
                 $rowTax += $weeeTax;
                 $baseWeeeTax = ($item->getBaseWeeeTaxAppliedRowAmount() - $item->getBaseWeeeDiscount()) * $rate / 100;
                 $baseRowTax += $baseWeeeTax;
                 $taxGroups[$rateKey]['weee_tax'][] = $weeeTax;
                 $taxGroups[$rateKey]['base_weee_tax'][] = $baseWeeeTax;
             }
             if (!$item->getNoDiscount() && $item->getWeeeTaxApplied()) {
                 $rowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false);
                 $baseRowTaxBeforeDiscount = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false);
                 if ($isWeeeTaxable) {
                     $rowTaxBeforeDiscount += $item->getWeeeTaxAppliedRowAmount() * $rate / 100;
                     $baseRowTaxBeforeDiscount += $item->getBaseWeeeTaxAppliedRowAmount() * $rate / 100;
                 }
             }
             if ($inclTax && $discount > 0) {
                 $hiddenTax = $this->_calculator->calcTaxAmount($discount, $rate, $inclTax, false);
                 $baseHiddenTax = $this->_calculator->calcTaxAmount($baseDiscount, $rate, $inclTax, false);
                 $this->_hiddenTaxes[] = array('rate_key' => $rateKey, 'qty' => 1, 'item' => $item, 'value' => $hiddenTax, 'base_value' => $baseHiddenTax, 'incl_tax' => $inclTax);
             }
             break;
     }
     $rowTax = $this->_deltaRound($rowTax, $rateKey, $inclTax);
     $baseRowTax = $this->_deltaRound($baseRowTax, $rateKey, $inclTax, 'base');
     $item->setTaxAmount(max(0, $rowTax));
     $item->setBaseTaxAmount(max(0, $baseRowTax));
     if (isset($rowTaxBeforeDiscount) && isset($baseRowTaxBeforeDiscount)) {
         $taxBeforeDiscount = max(0, $this->_deltaRound($rowTaxBeforeDiscount, $rateKey, $inclTax, 'tax_before_discount'));
         $baseTaxBeforeDiscount = max(0, $this->_deltaRound($baseRowTaxBeforeDiscount, $rateKey, $inclTax, 'tax_before_discount_base'));
         $item->setDiscountTaxCompensation($taxBeforeDiscount - max(0, $rowTax));
         $item->setBaseDiscountTaxCompensation($baseTaxBeforeDiscount - max(0, $baseRowTax));
     }
     $rowTotalInclTax = $item->getRowTotalInclTax();
     if (!isset($rowTotalInclTax)) {
         $weeeTaxBeforeDiscount = 0;
         $baseWeeeTaxBeforeDiscount = 0;
         if ($isWeeeTaxable) {
             $weeeTaxBeforeDiscount = $item->getWeeeTaxAppliedRowAmount() * $rate / 100;
             $baseWeeeTaxBeforeDiscount = $item->getBaseWeeeTaxAppliedRowAmount() * $rate / 100;
         }
         if ($this->_config->priceIncludesTax($this->_store)) {
             $item->setRowTotalInclTax($subtotal + $weeeTaxBeforeDiscount);
             $item->setBaseRowTotalInclTax($baseSubtotal + $baseWeeeTaxBeforeDiscount);
         } else {
             $taxCompensation = $item->getDiscountTaxCompensation() ? $item->getDiscountTaxCompensation() : 0;
             $item->setRowTotalInclTax($subtotal + $rowTax + $taxCompensation);
             $item->setBaseRowTotalInclTax($baseSubtotal + $baseRowTax + $item->getBaseDiscountTaxCompensation());
         }
     }
     $taxGroups[$rateKey]['totals'][] = max(0, $taxSubtotal);
     $taxGroups[$rateKey]['base_totals'][] = max(0, $baseTaxSubtotal);
     return $this;
 }