I am trying to get my custom module working and I am not sure where I am wrong.
Here is my app/etc/[namespace]_CustomPriceRevert.xml
:
<?xml version="1.0"?>
<config>
<modules>
<[Namespace]_CustomPriceRevert>
<active>true</active>
<codePool>local</codePool>
</[Namespace]_CustomPriceRevert>
</modules>
</config>
I guess that works fine as I can see the module in Admin Panel > System > Configuration > Advanced > Advanced
and it is enabled.
Here is the content of app/code/local/[Namespace]/CustomPriceRevert/etc/config.xml
:
<?xml version="1.0"?>
<config>
<modules>
<[Namespace]_CustomPriceRevert>
<version>0.1.0</version>
</[Namespace]_CustomPriceRevert>
</modules>
<global>
<models>
<adminhtml>
<rewrite>
<sales_order_create> Namespace]_CustomPriceRevert_Model_Sales_Order_Create</sales_order_create>
</rewrite>
</adminhtml>
</models>
</global>
</config>
Something wrong in here?
Here is content of my model app/code/local/[Namespace]/CustomPriceRevert/Model/Sales/Order/Create.php
:
<?php
class [Namespace]_CustomPriceRevert_Model_Sales_Order_Create extends Mage_Adminhtml_Model_Sales_Order_Create {
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;
}
// Custom-code
if (
!$this->getSession()->getReordered()
&& $orderItem->getOriginalPrice() != $orderItem->getPrice()
) {
$item->setCustomPrice($orderItem->getPrice());
$item->setOriginalCustomPrice($orderItem->getPrice());
}
// end Custom-code
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;
}
}
The custom code seems to work because when I added it to the core file it worked fine.
I'm working on magento 1.9.2.4. Can anyone tell me what I am doing wrong?
// Custom-code
in theCreate.php
file. Basically it saves the custom price as magento custom price is lost on Order Edit. Also the code is working, I tried adding it to the coreCreate.php
file and worked fine, it's just the module that's not working.extends Mage_Adminhtml_Model_Sales_Order_Create
.