1

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?

  • what the expected results and what's happening? all you have is code and saying it doesn't work – treyBake Nov 22 '17 at 15:57
  • The custom code is commented as // Custom-code in the Create.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 core Create.php file and worked fine, it's just the module that's not working. – Greg Nov 22 '17 at 15:59
  • Your code seems fine. Check everything in app/code/local and app/code/community to ensure that nothing else is overriding the same class. Search for extends Mage_Adminhtml_Model_Sales_Order_Create. – seanbreeden Nov 22 '17 at 17:58
  • Check for conflict, see if your function initFromOrderItem are executed or not – Mohamed El Mrabet Nov 22 '17 at 20:43
  • 2
    @BareFeet your initialization file is not in correct place. It should be in app/etc/modules – Zefiryn Nov 24 '17 at 5:03
0

I think try this.

app/etc/modules/Test_CustomPriceRevert.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Test_CustomPriceRevert>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Test_CustomPriceRevert>
  </modules>
</config>

app/code/local/Test/CustomPriceRevert/etc/config/xml

<?xml version="1.0"?>
<config>
  <modules>
    <Test_CustomPriceRevert>
      <version>0.1.0</version>
    </Test_CustomPriceRevert>
  </modules>
  <global>
    <helpers>
      <custompricerevert>
        <class>Test_CustomPriceRevert_Helper</class>
      </custompricerevert>
    </helpers>
    <models>
      <custompricerevert>
        <class>Test_CustomPriceRevert_Model</class>
        <resourceModel>custompricerevert_mysql4</resourceModel>
      </custompricerevert>
            <adminhtml>
                <rewrite>
                    <sales_order_create>Test_CustomPriceRevert_Model_Adminhtml_Sales_Order_Create</sales_order_create>
                </rewrite>
            </adminhtml>
    </models>
  </global>

app/code/local/Test/CustomPriceRevert/Model/Adminhtml/Sales/Order/Create.php

<?php
class Test_CustomPriceRevert_Model_Adminhtml_Sales_Order_Create extends Mage_Adminhtml_Model_Sales_Order_Create
{

}
  • That did not work :/ – Greg Nov 24 '17 at 11:50
0

I guess you are missing something on your

app/etc/modules/[namespace]_CustomPriceRevert.xml

Update with below code

<?xml version="1.0"?>
<config>
    <modules>
        <[Namespace]_CustomPriceRevert>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                 <Mage_Core />
            </depends>
        </[Namespace]_CustomPriceRevert>
    </modules>
</config>
  • File is correct, location should be app/etc/modules/[namespace]_CustomPriceRevert.xml – Zefiryn Nov 24 '17 at 5:01
  • Ain't working :/ I am really not sure what is the problem now. Could it be that some other modules are extending this class somewhere else? I used MageRun to see if there are any conflicts but it didn't show anything. – Greg Nov 24 '17 at 11:57
  • Can you check your local and community code pool for this class Mage_Adminhtml_Model_Sales_Order_Create may be some extension has already extended this class or not? – Asheem Patro Nov 25 '17 at 2:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.