/** * Initialize creation data from existing order Item * * @param Mage_Sales_Model_Order_Item $orderItem * @param int $qty * @return Mage_Sales_Model_Quote_Item | string */ public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = null) { if (!$orderItem->getId()) { return $this; } $product = Mage::getModel('catalog/product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId()); if ($product->getId()) { $product->setSkipCheckRequiredOption(true); $buyRequest = $orderItem->getBuyRequest(); if (is_numeric($qty)) { $buyRequest->setQty($qty); } $item = $this->getQuote()->addProduct($product, $buyRequest); if (is_string($item)) { return $item; } /*********************************************Set custom price selected starts************************************************************/ if (!$this->getSession()->getReordered() && $orderItem->getOriginalPrice() != $orderItem->getPrice()) { if ($orderItem->getProductType() == 'configurable' || $orderItem->getProductType() == 'bundle') { $productId = $orderItem->getProductId(); $quoteItemId = $orderItem->getQuoteItemId(); $items = $this->getQuote()->getItemsCollection(); foreach ($items as $item) { if ($item->getProduct()->getId() == $productId && !$item->getApplyPriceFlag()) { if ($orderItem->getOriginalPrice() != $orderItem->getPrice()) { $item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice()); } //$item->setApplyPriceFlag(true); } } } else { $item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice()); } } /*********************************************Set custom price selected ends************************************************************/ if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) { $item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions)))); } Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item)); return $item; } return $this; }
/** * Set correct item prices ((original price / new qty) * old qty) * * @param Mage_Sales_Model_Order_Item $orderItem * @param int $oldQty * @param int $newQty * @return Mage_Sales_Model_Order_Item */ protected function _correctPrices($orderItem, $oldQty, $newQty) { $orderItem->setPrice($orderItem->getPrice() / $newQty * $oldQty); $orderItem->setBasePrice($orderItem->getBasePrice() / $newQty * $oldQty); $orderItem->setOriginalPrice($orderItem->getOriginalPrice() / $newQty * $oldQty); $orderItem->setBaseOriginalPrice($orderItem->getBaseOriginalPrice() / $newQty * $oldQty); $orderItem->setPriceInclTax($orderItem->getPriceInclTax() / $newQty * $oldQty); $orderItem->setBasePriceInclTax($orderItem->getBasePriceInclTax() / $newQty * $oldQty); return $orderItem; }