protected function _writeOrderItem(Mage_Sales_Model_Order_Item $item, XMLWriter $xml, $storeId = null) { // inherit some attributes from parent order item if ($item->getParentItemId() && !$item->getParentItem()) { $item->setParentItem(Mage::getModel('sales/order_item')->load($item->getParentItemId())); } // only inherit if parent has been hidden if ($item->getParentItem() && $item->getPrice() == 0.0 && Mage::helper('auctaneapi')->isExcludedProductType($item->getParentItem()->getProductType())) { $item->setPrice($item->getParentItem()->getPrice()); } /* @var $gift Mage_GiftMessage_Model_Message */ $gift = Mage::helper('giftmessage/message')->getGiftMessage(!$item->getGiftMessageId() && $item->getParentItem() ? $item->getParentItem()->getGiftMessageId() : $item->getGiftMessageId()); $item->setGift($gift->isObjectNew() ? 'false' : 'true'); if (!$gift->isObjectNew()) { $item->setGiftMessage(sprintf("From: %s\nTo: %s\nMessage: %s", $gift->getSender(), $gift->getRecipient(), $gift->getMessage())); } /* @var $product Mage_Catalog_Model_Product */ $product = Mage::getModel('catalog/product')->setStoreId($storeId)->load($item->getProductId()); // inherit some attributes from parent product item if ($parentProduct = $this->_getOrderItemParentProduct($item, $storeId)) { if (!$product->getImage() || $product->getImage() == 'no_selection') { $product->setImage($parentProduct->getImage()); } if (!$product->getSmallImage() || $product->getSmallImage() == 'no_selection') { $product->setSmallImage($parentProduct->getSmallImage()); } if (!$product->getThumbnail() || $product->getThumbnail() == 'no_selection') { $product->setThumbnail($parentProduct->getThumbnail()); } } $xml->startElement('Item'); $helper = Mage::helper('auctaneapi'); if (Mage::helper('auctaneapi')->getExportPriceType($item->getOrder()->getStoreId()) == Auctane_Api_Model_System_Source_Config_Prices::BASE_PRICE) { $helper->fieldsetToXml('base_sales_order_item', $item, $xml); } else { $helper->fieldsetToXml('sales_order_item', $item, $xml); } /* using emulation so that product images come from the correct store */ $appEmulation = Mage::getSingleton('core/app_emulation'); $initialEnvironmentInfo = $appEmulation->startEnvironmentEmulation($product->getStoreId()); Mage::helper('auctaneapi')->fieldsetToXml('sales_order_item_product', $product, $xml); $appEmulation->stopEnvironmentEmulation($initialEnvironmentInfo); $xml->startElement('Options'); $this->_writeOrderProductAttribute($product, $xml, $storeId); // items may have several custom options chosen by customer foreach ((array) $item->getProductOptionByCode('options') as $option) { $this->_writeOrderItemOption($option, $xml, $storeId); } $buyRequest = $item->getProductOptionByCode('info_buyRequest'); if ($buyRequest && @$buyRequest['super_attribute']) { // super_attribute is non-null and non-empty, there must be a Configurable involved $parentItem = $this->_getOrderItemParent($item); /* export configurable custom options as they are stored in parent */ foreach ((array) $parentItem->getProductOptionByCode('options') as $option) { $this->_writeOrderItemOption($option, $xml, $storeId); } foreach ((array) $parentItem->getProductOptionByCode('attributes_info') as $option) { $this->_writeOrderItemOption($option, $xml, $storeId); } } $xml->endElement(); // Options $xml->endElement(); // Item }
/** * 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; }