本文整理汇总了PHP中Mage_Sales_Model_Quote_Item_Abstract::getDiscountAmount方法的典型用法代码示例。如果您正苦于以下问题:PHP Mage_Sales_Model_Quote_Item_Abstract::getDiscountAmount方法的具体用法?PHP Mage_Sales_Model_Quote_Item_Abstract::getDiscountAmount怎么用?PHP Mage_Sales_Model_Quote_Item_Abstract::getDiscountAmount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mage_Sales_Model_Quote_Item_Abstract
的用法示例。
在下文中一共展示了Mage_Sales_Model_Quote_Item_Abstract::getDiscountAmount方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _calcUnitTaxAmount
/**
* Calculate tax for each product
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param type $rate
* @return Magestore_Magestore_Model_Total_Quote_Tax
*/
protected function _calcUnitTaxAmount(Mage_Sales_Model_Quote_Item_Abstract $item, $rate)
{
$discount = $item->getDiscountAmount();
$baseDiscount = $item->getBaseDiscountAmount();
if ($item->getIsPriceInclTax()) {
$item->setMagestoreDiscountTax($this->_calculator->calcTaxAmount($item->getMagestoreDiscount(), $rate, false, false));
$item->setMagestoreBaseDiscountTax($this->_calculator->calcTaxAmount($item->getMagestoreBaseDiscount(), $rate, false, false));
}
$item->setDiscountAmount($discount + $item->getMagestoreDiscount() + $item->getMagestoreDiscountTax());
$item->setBaseDiscountAmount($baseDiscount + $item->getMagestoreDiscount() + $item->getMagestoreBaseDiscountTax());
parent::_calcUnitTaxAmount($item, $rate);
$afterDiscount = (bool) Mage::getStoreConfig(Mage_Tax_Model_Config::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $this->_store);
if ($item->getIsPriceInclTax() && $afterDiscount) {
foreach ($this->_hiddenTaxes as $key => $taxInfoItem) {
if (isset($taxInfoItem['item']) && $item->getId() == $taxInfoItem['item']->getId() && $taxInfoItem['value'] >= $item->getMagestoreDiscountTax() && $item->getMagestoreDiscountTax() > 0) {
$this->_hiddenTaxes[$key]['value'] = $taxInfoItem['value'] - $item->getMagestoreDiscountTax();
$this->_hiddenTaxes[$key]['base_value'] = $taxInfoItem['base_value'] - $item->getMagestoreBaseDiscountTax();
break;
}
}
//fix 1.4
if ($item->getHiddenTaxAmount()) {
$item->setHiddenTaxAmount($item->getHiddenTaxAmount() - $item->getMagestoreDiscountTax());
$item->setBaseHiddenTaxAmount($item->getBaseHiddenTaxAmount() - $item->getMagestoreBaseDiscountTax());
}
}
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
return $this;
}
示例2: _calcUnitTaxAmount
/**
* Calculate tax for each product
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param type $rate
* @return Magestore_Customerreward_Model_Total_Quote_Tax
*/
protected function _calcUnitTaxAmount(Mage_Sales_Model_Quote_Item_Abstract $item, $rate)
{
$discount = $item->getDiscountAmount();
$baseDiscount = $item->getBaseDiscountAmount();
$item->setDiscountAmount($discount + $item->getAffiliateplusAmount() + $item->getCustomerrewardAmount());
$item->setBaseDiscountAmount($baseDiscount + $item->getBaseAffiliateplusAmount() + $item->getBaseCustomerrewardAmount());
parent::_calcUnitTaxAmount($item, $rate);
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
return $this;
}
示例3: _calcUnitTaxAmount
/**
* Calculate tax for each product
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param type $rate
* @return Magestore_Customerreward_Model_Total_Quote_Tax
*/
protected function _calcUnitTaxAmount(Mage_Sales_Model_Quote_Item_Abstract $item, $rate, &$taxGroups = null, $taxId = null, $recalculateRowTotalInclTax = false)
{
$discount = $item->getDiscountAmount();
$baseDiscount = $item->getBaseDiscountAmount();
/* hainh add this for calculating discount base on incl or excl tax price 22-04-2014 */
if (!$this->_discountIncludeTax()) {
$item->setDiscountAmount($discount + $item->getAffiliateplusAmount() + $item->getCustomerrewardAmount());
$item->setBaseDiscountAmount($baseDiscount + $item->getBaseAffiliateplusAmount() + $item->getBaseCustomerrewardAmount());
}
parent::_calcUnitTaxAmount($item, $rate, $taxGroups, $taxId, $recalculateRowTotalInclTax);
$item->setDiscountAmount($discount);
$item->setBaseDiscountAmount($baseDiscount);
return $this;
}
示例4: _aggregateItemDiscount
/**
* Aggregate item discount information to address data and related properties
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @return Mage_SalesRule_Model_Quote_Discount
*/
protected function _aggregateItemDiscount($item)
{
$this->_addAmount(-$item->getDiscountAmount());
$this->_addBaseAmount(-$item->getBaseDiscountAmount());
return $this;
}
示例5: _aggregateTaxPerRate
/**
* 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 ($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));
$taxGroups[$rateKey]['totals'][] = max(0, $taxSubtotal);
$taxGroups[$rateKey]['base_totals'][] = max(0, $baseTaxSubtotal);
return $this;
}
示例6: _aggregateTaxPerRate
/**
* 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;
$subtotal = $item->getTaxableAmount() + $item->getExtraRowTaxableAmount();
$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:
$discount = $item->getDiscountAmount();
$baseDiscount = $item->getBaseDiscountAmount();
$subtotal -= $discount;
$baseSubtotal -= $baseDiscount;
$rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax, false);
$baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax, false);
break;
}
$rowTax = $this->_deltaRound($rowTax, $rateKey, $inclTax);
$baseRowTax = $this->_deltaRound($baseRowTax, $rateKey, $inclTax, 'base');
if ($inclTax && !empty($discount)) {
$hiddenTax = $item->getRowTotalInclTax() - $item->getRowTotal() - $rowTax;
$baseHiddenTax = $item->getBaseRowTotalInclTax() - $item->getBaseRowTotal() - $baseRowTax;
}
$item->setTaxAmount(max(0, $rowTax));
$item->setBaseTaxAmount(max(0, $baseRowTax));
$item->setHiddenTaxAmount(max(0, $hiddenTax));
$item->setBaseHiddenTaxAmount(max(0, $baseHiddenTax));
$taxGroups[$rateKey]['totals'][] = max(0, $subtotal);
$taxGroups[$rateKey]['base_totals'][] = max(0, $baseSubtotal);
return $this;
}
示例7: apply
public function apply(Mage_Sales_Model_Quote_Item_Abstract $item)
{
# Do not apply any discount if Ext is Disabled
if (Mage::helper('referafriend')->getExtDisabled()) {
return $this;
}
$this->_quote = $quote = $item->getQuote();
if ($item instanceof Mage_Sales_Model_Quote_Address_Item) {
$address = $item->getAddress();
} elseif ($quote->isVirtual()) {
$address = $quote->getBillingAddress();
} else {
$address = $quote->getShippingAddress();
}
# allow additional discount logic start
$hasAdditional = $item->getQuote()->getCouponCode() ? true : false;
$helper = Mage::helper('referafriend/referrer');
$baseSubtotal = $address->getBaseSubtotal();
$clearUse = array();
if (!$this->_discount) {
Mage::helper('referafriend')->setCustomerDiscount(0);
$customer = $quote->getCustomer();
$referrerId = $customer->getId();
$discounts = Mage::getResourceModel('referafriend/discount_collection')->loadByReferrer($referrerId);
if (count($discounts)) {
foreach ($discounts as $discount) {
$rule = Mage::getSingleton('referafriend/rule')->load($discount->getRuleId());
if ($rule->getDiscountUsage() == 0 || $rule->getDiscountUsage() > $discount->getDiscountUsed()) {
# allow additional discount logic
if ($hasAdditional && $rule->getAllowAdditionalDiscount() || !$hasAdditional) {
$this->_discount[$discount->getId()] = $discount;
} else {
$clearUse[] = $discount->getId();
}
}
}
}
}
if (!count($this->_discount)) {
# Reset used discount
$customer = Mage::getSingleton('customer/session');
if ($customer->isLoggedIn()) {
$customer->setDiscountUsed(array());
}
return $this;
}
$this->_getCouponCode();
// $this->_couponCode = $this->_getCouponCode();
$customer = Mage::getSingleton('customer/session');
if ($customer->isLoggedIn()) {
$discountUsed = (array) $customer->getDiscountUsed();
}
$rafDiscount = Mage::helper('referafriend')->getCustomerDiscount(false) ? Mage::helper('referafriend')->getCustomerDiscount(false) : 0;
$notUsed = array();
foreach ($this->_discount as $discountId => $discount) {
$discountAmount = 0;
$baseDiscountAmount = 0;
$rule = Mage::getModel('referafriend/rule')->load($discount->getRuleId());
switch ($discount->getType()) {
case self::TYPE_PERCENT:
$discountPercent = min(100, $discount->getAmount());
$discountAmount = ($item->getRowTotal() - $item->getDiscountAmount()) * $discountPercent / 100;
$baseDiscountAmount = ($item->getBaseRowTotal() - $item->getBaseDiscountAmount()) * $discountPercent / 100;
$checkDiscountAmount = $baseSubtotal * $discountPercent / 100;
if (!($rule->getDiscountGreater() && $checkDiscountAmount < $rule->getDiscountGreater()) && !($rule->getTotalGreater() && $baseSubtotal < $rule->getTotalGreater())) {
if (isset($discountUsed)) {
if (!isset($discountUsed[$discountId])) {
$discountUsed[$discountId] = false;
}
}
$rafDiscount += $baseDiscountAmount;
$discountAmount = min($discountAmount + $item->getDiscountAmount(), $item->getRowTotal());
$baseDiscountAmount = min($baseDiscountAmount + $item->getBaseDiscountAmount(), $item->getBaseRowTotal());
//$discountPercent = min(100, $item->getDiscountPercent()+$percentDiscount);
$item->setDiscountPercent(min(100, $item->getDiscountPercent() + $discountPercent));
$discountAmount = $quote->getStore()->roundPrice($discountAmount);
$baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);
$item->setDiscountAmount($discountAmount);
$item->setBaseDiscountAmount($baseDiscountAmount);
} else {
$notUsed[] = $discountId;
if (isset($discountUsed[$discountId])) {
unset($discountUsed[$discountId]);
}
}
break;
case self::TYPE_FLATRATE:
$discountAmount = min($item->getRowTotal() - $item->getDiscountAmount(), $quote->getStore()->convertPrice($discount->getAmount()));
$baseDiscountAmount = min($item->getBaseRowTotal() - $item->getBaseDiscountAmount(), $discount->getAmount());
$checkDiscountAmount = $discount->getAmount();
if (!($rule->getDiscountGreater() && $checkDiscountAmount < $rule->getDiscountGreater()) && !($rule->getTotalGreater() && $baseSubtotal < $rule->getTotalGreater())) {
if (isset($discountUsed)) {
if (!isset($discountUsed[$discountId])) {
$discountUsed[$discountId] = false;
}
}
$rafDiscount += $baseDiscountAmount;
$this->_discount[$discountId]->setAmount($discount->getAmount() - $baseDiscountAmount);
/*$discountAmount = $quote->getStore()->roundPrice($discountAmount);
$baseDiscountAmount = $quote->getStore()->roundPrice($baseDiscountAmount);*/
//.........这里部分代码省略.........
示例8: _aggregateTaxPerRate
/**
* 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)
{
$store = $item->getStore();
$inclTax = $this->_usePriceIncludeTax($store);
if ($inclTax) {
$subtotal = $item->getTaxCalcRowTotal();
$baseSubtotal = $item->getBaseTaxCalcRowTotal();
} else {
if ($item->hasCustomPrice() && $this->_helper->applyTaxOnCustomPrice($store)) {
$subtotal = $item->getRowTotal();
$baseSubtotal = $item->getBaseRowTotal();
} else {
$subtotal = $item->getTotalQty() * $item->getOriginalPrice();
$baseSubtotal = $item->getTotalQty() * $item->getBaseOriginalPrice();
}
}
$discountAmount = $item->getDiscountAmount();
$baseDiscountAmount = $item->getBaseDiscountAmount();
$qty = $item->getTotalQty();
$rateKey = (string) $rate;
/**
* Add extra amounts which can be taxable too
*/
$calcTotal = $subtotal + $item->getExtraRowTaxableAmount();
$baseCalcTotal = $baseSubtotal + $item->getBaseExtraRowTaxableAmount();
$item->setTaxPercent($rate);
if (!isset($taxGroups[$rateKey]['totals'])) {
$taxGroups[$rateKey]['totals'] = array();
}
if (!isset($taxGroups[$rateKey]['totals'])) {
$taxGroups[$rateKey]['base_totals'] = array();
}
$calculationSequence = $this->_helper->getCalculationSequence($store);
switch ($calculationSequence) {
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
$rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false);
$baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
$rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false);
$baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false);
$discountPrice = $inclTax ? $subtotal / $qty : ($subtotal + $rowTax) / $qty;
$baseDiscountPrice = $inclTax ? $baseSubtotal / $qty : ($baseSubtotal + $baseRowTax) / $qty;
$item->setDiscountCalculationPrice($discountPrice);
$item->setBaseDiscountCalculationPrice($baseDiscountPrice);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
$calcTotal = $calcTotal - $discountAmount;
$baseCalcTotal = $baseCalcTotal - $baseDiscountAmount;
$rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false);
$baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false);
break;
}
/**
* "Delta" rounding
*/
$delta = isset($this->_roundingDeltas[$rateKey]) ? $this->_roundingDeltas[$rateKey] : 0;
$baseDelta = isset($this->_baseRoundingDeltas[$rateKey]) ? $this->_baseRoundingDeltas[$rateKey] : 0;
$rowTax += $delta;
$baseRowTax += $baseDelta;
$this->_roundingDeltas[$rateKey] = $rowTax - $this->_calculator->round($rowTax);
$this->_baseRoundingDeltas[$rateKey] = $baseRowTax - $this->_calculator->round($baseRowTax);
$rowTax = $this->_calculator->round($rowTax);
$baseRowTax = $this->_calculator->round($baseRowTax);
/**
* Renew item amounts in case if we are working with price include tax
*/
if ($inclTax) {
$unitTax = $this->_calculator->round($rowTax / $qty);
$baseUnitTax = $this->_calculator->round($baseRowTax / $qty);
if ($item->hasCustomPrice()) {
$item->setCustomPrice($item->getPriceInclTax() - $unitTax);
$item->setBaseCustomPrice($item->getBasePriceInclTax() - $baseUnitTax);
} else {
$item->setOriginalPrice($item->getPriceInclTax() - $unitTax);
$item->setPrice($item->getBasePriceInclTax() - $baseUnitTax);
$item->setBasePrice($item->getBasePriceInclTax() - $baseUnitTax);
}
$item->setRowTotal($item->getRowTotalInclTax() - $rowTax);
$item->setBaseRowTotal($item->getBaseRowTotalInclTax() - $baseRowTax);
}
$item->setTaxAmount($rowTax);
$item->setBaseTaxAmount($baseRowTax);
$taxGroups[$rateKey]['totals'][] = $calcTotal;
$taxGroups[$rateKey]['base_totals'][] = $baseCalcTotal;
return $this;
}
示例9: fixDiscounts
/**
* Round discount amounts and bound them to the total row price
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param string $currencyCode
* @param string $baseCurrencyCode
*
* @return Mage_Sales_Model_Quote_Item_Abstract
*/
protected function fixDiscounts(Mage_Sales_Model_Quote_Item_Abstract $item, $currencyCode, $baseCurrencyCode)
{
// Get discount amounts
$itemDiscountAmount = $item->getDiscountAmount();
$itemOriginalDiscountAmount = $item->getOriginalDiscountAmount();
$itemBaseDiscountAmount = $item->getBaseDiscountAmount();
$itemBaseOriginalDiscountAmount = $item->getBaseOriginalDiscountAmount();
// Round discount amounts
$itemDiscountAmount = $this->round($itemDiscountAmount, $currencyCode);
$itemOriginalDiscountAmount = $this->round($itemOriginalDiscountAmount, $currencyCode);
$itemBaseDiscountAmount = $this->round($itemBaseDiscountAmount, $baseCurrencyCode);
$itemBaseOriginalDiscountAmount = $this->round($itemBaseOriginalDiscountAmount, $baseCurrencyCode);
// Get item unit prices
$itemPrice = $this->getItemPrice($item);
$baseItemPrice = $this->getItemBasePrice($item);
$itemOriginalPrice = $this->getItemOriginalPrice($item);
$baseItemOriginalPrice = $this->getItemBaseOriginalPrice($item);
// Discount cannot exceed row total
$itemDiscountAmount = min($itemDiscountAmount, $itemPrice * $item->getQty());
$itemOriginalDiscountAmount = min($itemOriginalDiscountAmount, $itemOriginalPrice * $item->getQty());
$itemBaseDiscountAmount = min($itemBaseDiscountAmount, $baseItemPrice * $item->getQty());
$itemBaseOriginalDiscountAmount = min($itemBaseOriginalDiscountAmount, $baseItemOriginalPrice * $item->getQty());
// Save fixed discount amounts
$item->setDiscountAmount($itemDiscountAmount);
$item->setOriginalDiscountAmount($itemOriginalDiscountAmount);
$item->setBaseDiscountAmount($itemBaseDiscountAmount);
$item->setBaseOriginalDiscountAmount($itemBaseOriginalDiscountAmount);
return $item;
}
示例10: itemToOrderItem
/**
* 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;
}
示例11: _aggregateTaxPerRate
/**
* 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);
//.........这里部分代码省略.........