/** * @param array $args Must contain key/value for: * - order_item_iterable => eBayEnterprise\RetailOrderManagement\Payload\TaxDutyFee\IOrderItemRequestIterable * - address => Mage_Sales_Model_Quote_Address * - item => Mage_Sales_Model_Quote_Item_Abstract * May contain key/value for: * - tax_helper => EbayEnterprise_Tax_Helper_Data * - payload_helper => EbayEnterprise_Tax_Helper_Payload * - tax_config => EbayEnterprise_Eb2cCore_Model_Config_Registry * - discount_helper => EbayEnterprise_Eb2cCore_Helper_Discount * - logger => EbayEnterprise_MageLog_Helper_Data * - log_context => EbayEnterprise_MageLog_Helper_Context */ public function __construct(array $args) { list($this->_orderItemIterable, $this->_address, $this->_item, $this->_taxHelper, $this->_payloadHelper, $this->_taxConfig, $this->_discountHelper, $this->_logger, $this->_logContext) = $this->_checkTypes($args['order_item_iterable'], $args['address'], $args['item'], $this->_nullCoalesce($args, 'tax_helper', Mage::helper('ebayenterprise_tax')), $this->_nullCoalesce($args, 'payload_helper', Mage::helper('ebayenterprise_tax/payload')), $this->_nullCoalesce($args, 'tax_config', Mage::helper('ebayenterprise_tax')->getConfigModel()), $this->_nullCoalesce($args, 'discount_helper', Mage::helper('eb2ccore/discount')), $this->_nullCoalesce($args, 'logger', Mage::helper('ebayenterprise_magelog')), $this->_nullCoalesce($args, 'log_context', Mage::helper('ebayenterprise_magelog/context'))); $this->_itemProduct = $this->_item->getProduct() ?: Mage::getModel('catalog/product')->load($this->_item->getProductId()); $this->_orderItem = $this->_orderItemIterable->getEmptyOrderItem(); $this->_populateRequest(); }
/** * Convert quote item to order item. Most part of the code was taken from Mage_Sales_Model_Convert_Quote::itemToOrderItem() * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param null|Mage_Sales_Model_Order_Item $orderItem * @return Mage_Sales_Model_Order_Item */ public function itemToOrderItem(Mage_Sales_Model_Quote_Item_Abstract $item, $orderItem = null) { if (is_null($orderItem)) { $orderItem = Mage::getModel('sales/order_item'); } $orderItem->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setQuoteParentItemId($item->getParentItemId())->setProductId($item->getProductId())->setProductType($item->getProductType())->setQtyBackordered($item->getBackorders())->setProduct($item->getProduct())->setBaseOriginalPrice($item->getBaseOriginalPrice()); $options = $item->getProductOrderOptions(); if (!$options) { $options = $item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()); } $orderItem->setProductOptions($options); Mage::helper('core')->copyFieldset('sales_convert_quote_item', 'to_order_item', $item, $orderItem); if ($item->getParentItem()) { $orderItem->setQtyOrdered($orderItem->getQtyOrdered() * $item->getParentItem()->getQty()); } if (!$item->getNoDiscount()) { Mage::helper('core')->copyFieldset('sales_convert_quote_item', 'to_order_item_discount', $item, $orderItem); } Mage::dispatchEvent('sales_convert_quote_item_to_order_item', array('order_item' => $orderItem, 'item' => $item)); return $orderItem; }
/** * Get a passed in item product stock item. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return Mage_CatalogInventory_Model_Stock_Item */ protected function getItemProductStockItem(Mage_Sales_Model_Quote_Item_Abstract $quoteItem) { return $quoteItem->getProduct()->getStockItem(); }
/** * return true if the item's manage stock setting is on * * @param Mage_Sales_Model_Quote_Item_Abstract * @return bool */ public function isStockManaged(Mage_Sales_Model_Quote_Item_Abstract $item) { $stock = $item->getProduct()->getStockItem(); return (bool) $stock->getManageStock(); }
/** * Recollect item price and row total using after taxes subtract. * Declare item price including tax attributes * * @deprecated after 1.4.1 * * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _recollectItem($address, Mage_Sales_Model_Quote_Item_Abstract $item) { $store = $address->getQuote()->getStore(); $request = $this->_getStoreTaxRequest($address); $request->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($request); $qty = $item->getTotalQty(); $price = $taxPrice = $item->getCalculationPriceOriginal(); $basePrice = $baseTaxPrice = $item->getBaseCalculationPriceOriginal(); $subtotal = $taxSubtotal = $item->getRowTotal(); $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal(); if ($this->_config->discountTax($store)) { $item->setDiscountCalculationPrice($price); $item->setBaseDiscountCalculationPrice($basePrice); } /** * Use original price for tax calculation */ if ($item->hasCustomPrice() && !$this->_helper->applyTaxOnCustomPrice($store)) { $taxPrice = $item->getOriginalPrice(); $baseTaxPrice = $item->getBaseOriginalPrice(); $taxSubtotal = $taxPrice * $qty; $baseTaxSubtotal = $baseTaxPrice * $qty; } if ($this->_areTaxRequestsSimilar) { $item->setRowTotalInclTax($subtotal); $item->setBaseRowTotalInclTax($baseSubtotal); $item->setPriceInclTax($price); $item->setBasePriceInclTax($basePrice); $item->setTaxCalcPrice($taxPrice); $item->setBaseTaxCalcPrice($baseTaxPrice); $item->setTaxCalcRowTotal($taxSubtotal); $item->setBaseTaxCalcRowTotal($baseTaxSubtotal); } $this->_subtotalInclTax += $subtotal; $this->_baseSubtotalInclTax += $baseSubtotal; if ($this->_config->getAlgorithm($store) == Mage_Tax_Model_Calculation::CALC_UNIT_BASE) { $taxAmount = $this->_calculator->calcTaxAmount($taxPrice, $rate, true); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxPrice, $rate, true); $unitPrice = $this->_calculator->round($price - $taxAmount); $baseUnitPrice = $this->_calculator->round($basePrice - $baseTaxAmount); $subtotal = $this->_calculator->round($unitPrice * $qty); $baseSubtotal = $this->_calculator->round($baseUnitPrice * $qty); } else { $taxAmount = $this->_calculator->calcTaxAmount($taxSubtotal, $rate, true, false); $baseTaxAmount = $this->_calculator->calcTaxAmount($baseTaxSubtotal, $rate, true, false); $unitPrice = ($subtotal - $taxAmount) / $qty; $baseUnitPrice = ($baseSubtotal - $baseTaxAmount) / $qty; $subtotal = $this->_calculator->round($subtotal - $taxAmount); $baseSubtotal = $this->_calculator->round($baseSubtotal - $baseTaxAmount); } if ($item->hasCustomPrice()) { $item->setCustomPrice($unitPrice); $item->setBaseCustomPrice($baseUnitPrice); } $item->setPrice($baseUnitPrice); $item->setOriginalPrice($unitPrice); $item->setBasePrice($baseUnitPrice); $item->setRowTotal($subtotal); $item->setBaseRowTotal($baseSubtotal); return $this; }
/** * determine if the item's amounts should be put into the request. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return bool */ protected function canIncludeAmounts(Mage_Sales_Model_Quote_Item_Abstract $item) { return !($item->getProduct()->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $item->isChildrenCalculated()); }
/** * Get tax rate based on store shipping origin address settings * This rate can be used for conversion store price including tax to * store price excluding tax * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param null|Mage_Core_Model_Store $store * @return float */ public function getStoreRateForItem($item, $store = null) { $storeRequest = $this->getRateOriginRequest($store)->setProductClassId($item->getProduct()->getTaxClassId()); return $this->getRate($storeRequest); }
/** * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param Varien_Object $taxRateRequest * @param array $taxGroups * @param array $itemTaxGroups * @param boolean $catalogPriceInclTax */ protected function _totalBaseProcessItemTax($item, $taxRateRequest, &$taxGroups, &$itemTaxGroups, $catalogPriceInclTax) { $taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $this->_calculator->getRate($taxRateRequest); $item->setTaxAmount(0); $item->setBaseTaxAmount(0); $item->setHiddenTaxAmount(0); $item->setBaseHiddenTaxAmount(0); $item->setTaxPercent($rate); $item->setDiscountTaxCompensation(0); $rowTotalInclTax = $item->getRowTotalInclTax(); $recalculateRowTotalInclTax = false; if (!isset($rowTotalInclTax)) { $item->setRowTotalInclTax($item->getTaxableAmount()); $item->setBaseRowTotalInclTax($item->getBaseTaxableAmount()); $recalculateRowTotalInclTax = true; } $appliedRates = $this->_calculator->getAppliedRates($taxRateRequest); if ($catalogPriceInclTax) { $taxGroups[(string) $rate]['applied_rates'] = $appliedRates; $taxGroups[(string) $rate]['incl_tax'] = $item->getIsPriceInclTax(); $this->_aggregateTaxPerRate($item, $rate, $taxGroups); } else { //need to calculate each tax separately foreach ($appliedRates as $appliedTax) { $taxId = $appliedTax['id']; $taxRate = $appliedTax['percent']; $taxGroups[$taxId]['applied_rates'] = array($appliedTax); $taxGroups[$taxId]['incl_tax'] = $item->getIsPriceInclTax(); $this->_aggregateTaxPerRate($item, $taxRate, $taxGroups, $taxId, $recalculateRowTotalInclTax); } //We need to calculate weeeAmountInclTax using multiple tax rate here //because the _calculateWeeeTax and _calculateRowWeeeTax only take one tax rate if ($this->_weeeHelper->isEnabled() && $this->_weeeHelper->isTaxable()) { $this->_calculateWeeeAmountInclTax($item, $appliedRates, false); $this->_calculateWeeeAmountInclTax($item, $appliedRates, true); } } if ($rate > 0) { $itemTaxGroups[$item->getId()] = $appliedRates; } return; }
/** * Process item fixed taxes * * @deprecated since 1.3.2.3 * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param bool $updateParent * @return Mage_Weee_Model_Total_Quote_Weee */ protected function _processItem(Mage_Sales_Model_Quote_Address $address, $item, $updateParent = false) { $store = $address->getQuote()->getStore(); if (!$this->_helper->isEnabled($store)) { return $this; } $custTaxClassId = $address->getQuote()->getCustomerTaxClassId(); $taxCalculationModel = Mage::getSingleton('tax/calculation'); /* @var $taxCalculationModel Mage_Tax_Model_Calculation */ $request = $taxCalculationModel->getRateRequest($address, $address->getQuote()->getBillingAddress(), $custTaxClassId, $store); $defaultRateRequest = $taxCalculationModel->getRateRequest(false, false, false, $store); $attributes = $this->_helper->getProductWeeeAttributes($item->getProduct(), $address, $address->getQuote()->getBillingAddress(), $store->getWebsiteId()); $applied = array(); $productTaxes = array(); foreach ($attributes as $k => $attribute) { $baseValue = $attribute->getAmount(); $value = $store->convertPrice($baseValue); $rowValue = $value * $item->getQty(); $baseRowValue = $baseValue * $item->getQty(); $title = $attribute->getName(); /** * Apply discount to fixed tax */ if ($item->getDiscountPercent() && $this->_helper->isDiscounted($store)) { $valueDiscount = $value / 100 * $item->getDiscountPercent(); $baseValueDiscount = $baseValue / 100 * $item->getDiscountPercent(); $rowValueDiscount = $rowValue / 100 * $item->getDiscountPercent(); $baseRowValueDiscount = $baseRowValue / 100 * $item->getDiscountPercent(); $address->setDiscountAmount($address->getDiscountAmount() + $rowValueDiscount); $address->setBaseDiscountAmount($address->getBaseDiscountAmount() + $baseRowValueDiscount); $address->setGrandTotal($address->getGrandTotal() - $rowValueDiscount); $address->setBaseGrandTotal($address->getBaseGrandTotal() - $baseRowValueDiscount); } $oneDisposition = $baseOneDisposition = $disposition = $baseDisposition = 0; /** * Apply tax percent to fixed tax */ if ($this->_helper->isTaxable($store)) { $currentPercent = $item->getTaxPercent(); $defaultPercent = $taxCalculationModel->getRate($defaultRateRequest->setProductClassId($item->getProduct()->getTaxClassId())); $valueBeforeVAT = $rowValue; $baseValueBeforeVAT = $baseRowValue; $oneDisposition = $store->roundPrice($value / (100 + $defaultPercent) * $currentPercent); $baseOneDisposition = $store->roundPrice($baseValue / (100 + $defaultPercent) * $currentPercent); $disposition = $store->roundPrice($rowValue / (100 + $defaultPercent) * $currentPercent); $baseDisposition = $store->roundPrice($baseRowValue / (100 + $defaultPercent) * $currentPercent); $item->setBaseTaxAmount($item->getBaseTaxAmount() + $baseDisposition); $item->setTaxAmount($item->getTaxAmount() + $disposition); $value -= $oneDisposition; $baseValue -= $baseOneDisposition; $rowValue -= $baseDisposition; $baseRowValue -= $disposition; $item->setWeeeTaxDisposition($item->getWeeeTaxDisposition() + $oneDisposition); $item->setBaseWeeeTaxDisposition($item->getBaseWeeeTaxDisposition() + $baseOneDisposition); $item->setWeeeTaxRowDisposition($item->getWeeeTaxRowDisposition() + $disposition); $item->setBaseWeeeTaxRowDisposition($item->getBaseWeeeTaxRowDisposition() + $baseDisposition); // $item->setTaxBeforeDiscount($item->getTaxBeforeDiscount() + $disposition); // $item->setBaseTaxBeforeDiscount($item->getBaseTaxBeforeDiscount() + $baseDisposition); $address->setTaxAmount($address->getTaxAmount() + $disposition); $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseDisposition); $rate = $taxCalculationModel->getRate($request->setProductClassId($item->getProduct()->getTaxClassId())); $this->_saveAppliedTaxes($address, $taxCalculationModel->getAppliedRates($request), $store->roundPrice($valueBeforeVAT - $rowValue), $store->roundPrice($baseValueBeforeVAT - $baseRowValue), $rate); $address->setGrandTotal($address->getGrandTotal() + $store->roundPrice($valueBeforeVAT - $rowValue)); $address->setBaseGrandTotal($address->getBaseGrandTotal() + $store->roundPrice($baseValueBeforeVAT - $baseRowValue)); } /** * Check if need include fixed tax amount to subtotal */ if ($this->_helper->includeInSubtotal($store)) { $address->setSubtotal($address->getSubtotal() + $rowValue); $address->setBaseSubtotal($address->getBaseSubtotal() + $baseRowValue); // $address->setSubtotalWithDiscount($address->getSubtotalWithDiscount() + $rowValue); // $address->setBaseSubtotalWithDiscount($address->getBaseSubtotalWithDiscount() + $baseRowValue); } else { $address->setTaxAmount($address->getTaxAmount() + $rowValue); $address->setBaseTaxAmount($address->getBaseTaxAmount() + $baseRowValue); } $productTaxes[] = array('title' => $title, 'base_amount' => $baseValue, 'amount' => $value, 'row_amount' => $rowValue, 'base_row_amount' => $baseRowValue, 'base_amount_incl_tax' => $baseValue + $baseOneDisposition, 'amount_incl_tax' => $value + $oneDisposition, 'row_amount_incl_tax' => $rowValue + $disposition, 'base_row_amount_incl_tax' => $baseRowValue + $baseDisposition); $applied[] = array('id' => $attribute->getCode(), 'percent' => null, 'hidden' => $this->_helper->includeInSubtotal($store), 'rates' => array(array('amount' => $rowValue, 'base_amount' => $baseRowValue, 'base_real_amount' => $baseRowValue, 'code' => $attribute->getCode(), 'title' => $title, 'percent' => null, 'position' => 1, 'priority' => -1000 + $k))); $item->setBaseWeeeTaxAppliedAmount($item->getBaseWeeeTaxAppliedAmount() + $baseValue); $item->setBaseWeeeTaxAppliedRowAmount($item->getBaseWeeeTaxAppliedRowAmount() + $baseRowValue); $item->setWeeeTaxAppliedAmount($item->getWeeeTaxAppliedAmount() + $value); $item->setWeeeTaxAppliedRowAmount($item->getWeeeTaxAppliedRowAmount() + $rowValue); } $this->_helper->setApplied($item, array_merge($this->_helper->getApplied($item), $productTaxes)); if ($updateParent) { $parent = $item->getParentItem(); $parent->setBaseWeeeTaxDisposition($parent->getBaseWeeeTaxDisposition() + $item->getBaseWeeeTaxDisposition()); $parent->setWeeeTaxDisposition($parent->getWeeeTaxDisposition() + $item->getWeeeTaxDisposition()); $parent->setBaseWeeeTaxRowDisposition($parent->getBaseWeeeTaxRowDisposition() + $item->getBaseWeeeTaxRowDisposition()); $parent->setWeeeTaxRowDisposition($parent->getWeeeTaxRowDisposition() + $item->getWeeeTaxRowDisposition()); $parent->setBaseWeeeTaxAppliedAmount($parent->getBaseWeeeTaxAppliedAmount() + $item->getBaseWeeeTaxAppliedAmount()); $parent->setBaseWeeeTaxAppliedRowAmount($parent->getBaseWeeeTaxAppliedRowAmount() + $item->getBaseWeeeTaxAppliedRowAmount()); $parent->setWeeeTaxAppliedAmount($parent->getWeeeTaxAppliedAmount() + $item->getWeeeTaxAppliedAmount()); $parent->setWeeeTaxAppliedRowAmount($parent->getWeeeTaxAppliedRowAmount() + $item->getWeeeTaxAppliedRowAmount()); } if ($applied) { $this->_saveAppliedTaxes($address, $applied, $item->getWeeeTaxAppliedAmount(), $item->getBaseWeeeTaxAppliedAmount(), null); } }
/** * Notify the customer if the quote item is backorderable with setting to notify customer. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return self */ protected function _notifyCustomerIfItemBackorderable(Mage_Sales_Model_Quote_Item_Abstract $quoteItem) { /** @var Mage_CatalogInventory_Model_Stock_Item $stockItem */ $stockItem = $quoteItem->getProduct()->getStockItem(); if ((int) $stockItem->getBackorders() === Mage_CatalogInventory_Model_Stock::BACKORDERS_YES_NOTIFY) { /** @var float */ $qty = $quoteItem->getQty(); /** @var float */ $rowQty = $this->_calculateTotalQuantityRequested($quoteItem); /** @var Varien_Object */ $result = $stockItem->checkQuoteItemQty($rowQty, $qty); if (!is_null($result->getMessage())) { $quoteItem->setMessage($result->getMessage()); } if (!is_null($result->getItemBackorders())) { $quoteItem->setBackorders($result->getItemBackorders()); } } return $this; }
/** * Calculate item price and row total including/excluding tax based on total price rounding level * * @param Mage_Sales_Model_Quote_Item_Abstract $item * @param Varien_Object $request * @return Mage_Tax_Model_Sales_Total_Quote_Subtotal */ protected function _totalBaseCalculation($item, $request) { $calc = $this->_calculator; $request->setProductClassId($item->getProduct()->getTaxClassId()); $rate = $calc->getRate($request); $qty = $item->getTotalQty(); $price = $taxPrice = $item->getCalculationPriceOriginal(); $basePrice = $baseTaxPrice = $item->getBaseCalculationPriceOriginal(); $subtotal = $taxSubtotal = $item->getRowTotal(); $baseSubtotal = $baseTaxSubtotal = $item->getBaseRowTotal(); $taxOnOrigPrice = !$this->_helper->applyTaxOnCustomPrice($this->_store) && $item->hasCustomPrice(); if ($taxOnOrigPrice) { $origSubtotal = $item->getOriginalPrice() * $qty; $baseOrigSubtotal = $item->getBaseOriginalPrice() * $qty; } $item->setTaxPercent($rate); if ($this->_config->priceIncludesTax($this->_store)) { if ($this->_sameRateAsStore($request)) { if ($taxOnOrigPrice) { $rowTax = $this->_deltaRound($calc->calcTaxAmount($origSubtotal, $rate, true, false), $rate, true); $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseOrigSubtotal, $rate, true, false), $rate, true, 'base'); $taxable = $origSubtotal; $baseTaxable = $baseOrigSubtotal; } else { $rowTax = $this->_deltaRound($calc->calcTaxAmount($subtotal, $rate, true, false), $rate, true); $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseSubtotal, $rate, true, false), $rate, true, 'base'); $taxable = $subtotal; $baseTaxable = $baseSubtotal; } $taxPrice = $price; $baseTaxPrice = $basePrice; $taxSubtotal = $subtotal; $baseTaxSubtotal = $baseSubtotal; $subtotal = $subtotal - $rowTax; $baseSubtotal = $baseSubtotal - $baseRowTax; $price = $calc->round($subtotal / $qty); $basePrice = $calc->round($baseSubtotal / $qty); $isPriceInclTax = true; } else { $storeRate = $calc->getStoreRate($request, $this->_store); if ($taxOnOrigPrice) { $storeTax = $calc->calcTaxAmount($origSubtotal, $storeRate, true, false); $baseStoreTax = $calc->calcTaxAmount($baseOrigSubtotal, $storeRate, true, false); } else { $storeTax = $calc->calcTaxAmount($subtotal, $storeRate, true, false); $baseStoreTax = $calc->calcTaxAmount($baseSubtotal, $storeRate, true, false); } $subtotal = $calc->round($subtotal - $storeTax); $baseSubtotal = $calc->round($baseSubtotal - $baseStoreTax); $price = $calc->round($subtotal / $qty); $basePrice = $calc->round($baseSubtotal / $qty); $rowTax = $this->_deltaRound($calc->calcTaxAmount($subtotal, $rate, false, false), $rate, true); $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseSubtotal, $rate, false, false), $rate, true, 'base'); $taxSubtotal = $subtotal + $rowTax; $baseTaxSubtotal = $baseSubtotal + $baseRowTax; $taxPrice = $calc->round($taxSubtotal / $qty); $baseTaxPrice = $calc->round($baseTaxSubtotal / $qty); $taxable = $subtotal; $baseTaxable = $baseSubtotal; $isPriceInclTax = false; } } else { if ($taxOnOrigPrice) { $rowTax = $this->_deltaRound($calc->calcTaxAmount($origSubtotal, $rate, false, false), $rate, true); $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseOrigSubtotal, $rate, false, false), $rate, true, 'base'); $taxable = $origSubtotal; $baseTaxable = $baseOrigSubtotal; } else { $rowTax = $this->_deltaRound($calc->calcTaxAmount($subtotal, $rate, false, false), $rate, true); $baseRowTax = $this->_deltaRound($calc->calcTaxAmount($baseSubtotal, $rate, false, false), $rate, true, 'base'); $taxable = $subtotal; $baseTaxable = $baseSubtotal; } $taxSubtotal = $subtotal + $rowTax; $baseTaxSubtotal = $baseSubtotal + $baseRowTax; $taxPrice = $calc->round($taxSubtotal / $qty); $baseTaxPrice = $calc->round($baseTaxSubtotal / $qty); $isPriceInclTax = false; } if ($item->hasCustomPrice()) { /** * Initialize item original price before declaring custom price */ $item->getOriginalPrice(); $item->setCustomPrice($price); $item->setBaseCustomPrice($basePrice); } else { $item->setConvertedPrice($price); } $item->setPrice($basePrice); $item->setBasePrice($basePrice); $item->setRowTotal($subtotal); $item->setBaseRowTotal($baseSubtotal); $item->setPriceInclTax($taxPrice); $item->setBasePriceInclTax($baseTaxPrice); $item->setRowTotalInclTax($taxSubtotal); $item->setBaseRowTotalInclTax($baseTaxSubtotal); $item->setTaxableAmount($taxable); $item->setBaseTaxableAmount($baseTaxable); $item->setIsPriceInclTax($isPriceInclTax); if ($this->_config->discountTax($this->_store)) { $item->setDiscountCalculationPrice($taxSubtotal / $qty); $item->setBaseDiscountCalculationPrice($baseTaxSubtotal / $qty); } elseif ($isPriceInclTax) { $item->setDiscountCalculationPrice($subtotal / $qty); $item->setBaseDiscountCalculationPrice($baseSubtotal / $qty); } return $this; }
/** * 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 = AO::getModel('sales/order_item')->setStoreId($item->getStoreId())->setQuoteItemId($item->getId())->setQuoteParentItemId($item->getParentItemId())->setProductId($item->getProductId())->setProductType($item->getProductType())->setProductOptions($item->getProduct()->getTypeInstance(true)->getOrderOptions($item->getProduct()))->setQtyBackordered($item->getBackorders()); AO::helper('core')->copyFieldset('sales_convert_quote_item', 'to_order_item', $item, $orderItem); if ($item->getParentItem()) { $orderItem->setQtyOrdered($orderItem->getQtyOrdered() * $item->getParentItem()->getQty()); } // ->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()) { AO::helper('core')->copyFieldset('sales_convert_quote_item', 'to_order_item_discount', $item, $orderItem); // $orderItem->setDiscountPercent($item->getDiscountPercent()) // ->setDiscountAmount($item->getDiscountAmount()) // ->setBaseDiscountAmount($item->getBaseDiscountAmount()); } AO::dispatchEvent('sales_convert_quote_item_to_order_item', array('order_item' => $orderItem, 'item' => $item)); return $orderItem; }
/** * Determine if an item is possible to send inventory detail request. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return bool */ protected function isItemAllowInventoryDetail(Mage_Sales_Model_Quote_Item_Abstract $item) { if ($item->getHasChildren()) { foreach ($item->getChildren() as $childItem) { $childStock = $childItem->getProduct()->getStockItem(); if ($this->isAllowedInventoryDetail($childStock)) { return true; } } return false; } return $this->isAllowedInventoryDetail($item->getProduct()->getStockItem()); }
/** * Calculate item fixed tax and prepare information for discount and recular taxation * * @param Mage_Sales_Model_Quote_Address $address * @param Mage_Sales_Model_Quote_Item_Abstract $item * @return Mage_Weee_Model_Total_Quote_Weee */ protected function _process(Mage_Sales_Model_Quote_Address $address, $item) { if (!$this->_helper->isEnabled($this->_store)) { return $this; } $attributes = $this->_helper->getProductWeeeAttributes($item->getProduct(), $address, $address->getQuote()->getBillingAddress(), $this->_store->getWebsiteId()); $applied = array(); $productTaxes = array(); $totalValue = 0; $baseTotalValue = 0; $totalRowValue = 0; $baseTotalRowValue = 0; foreach ($attributes as $k => $attribute) { $baseValue = $attribute->getAmount(); $value = $this->_store->convertPrice($baseValue); $rowValue = $value * $item->getTotalQty(); $baseRowValue = $baseValue * $item->getTotalQty(); $title = $attribute->getName(); $totalValue += $value; $baseTotalValue += $baseValue; $totalRowValue += $rowValue; $baseTotalRowValue += $baseRowValue; $productTaxes[] = array('title' => $title, 'base_amount' => $baseValue, 'amount' => $value, 'row_amount' => $rowValue, 'base_row_amount' => $baseRowValue, 'base_amount_incl_tax' => $baseValue, 'amount_incl_tax' => $value, 'row_amount_incl_tax' => $rowValue, 'base_row_amount_incl_tax' => $baseRowValue); $applied[] = array('id' => $attribute->getCode(), 'percent' => null, 'hidden' => $this->_helper->includeInSubtotal($this->_store), 'rates' => array(array('base_real_amount' => $baseRowValue, 'base_amount' => $baseRowValue, 'amount' => $rowValue, 'code' => $attribute->getCode(), 'title' => $title, 'percent' => null, 'position' => 1, 'priority' => -1000 + $k))); } $item->setWeeeTaxAppliedAmount($totalValue)->setBaseWeeeTaxAppliedAmount($baseTotalValue)->setWeeeTaxAppliedRowAmount($totalRowValue)->setBaseWeeeTaxAppliedRowAmnt($baseTotalRowValue); $this->_processTaxSettings($item, $totalValue, $baseTotalValue, $totalRowValue, $baseTotalRowValue)->_processTotalAmount($address, $totalRowValue, $baseTotalRowValue)->_processDiscountSettings($item, $totalValue, $baseTotalValue); $this->_helper->setApplied($item, array_merge($this->_helper->getApplied($item), $productTaxes)); if ($applied) { $this->_saveAppliedTaxes($address, $applied, $item->getWeeeTaxAppliedAmount(), $item->getBaseWeeeTaxAppliedAmount(), null); } }
/** * Get the product the item represents. * * @param Mage_Sales_Model_Quote_Item_Abstract * @return Mage_Catalog_Model_Product */ protected function getItemProduct(Mage_Sales_Model_Quote_Item_Abstract $item) { // When dealing with configurable items, need to get tax data from // the child product and not the parent. if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { $sku = $item->getSku(); $children = $item->getChildren(); if ($children) { foreach ($children as $childItem) { $childProduct = $childItem->getProduct(); // If the SKU of the child product matches the SKU of the // item, the simple product being ordered was found and should // be used. if ($childProduct->getSku() === $sku) { return $childProduct; } } } } return $item->getProduct() ?: Mage::getModel('catalog/product')->load($item->getProductId()); }