2

I am trying to rewrite the model sales_order_credit_memo_api with my own "info" function. I have created all the files yet when I access the API call "order_creditmemo.info" it uses the base Mage model, instead of using the class defined in my rewrite.

I have successfully rewritten other models, but I cannot get this one to work. Does anyone know what I'm doing wrong?

With all the coding shown below in place if I use the magerun.phar tool and run this command magerun.phar dev:class:lookup model sales/order_creditmemo_api it results in Model sales/order_creditmemo_api resolves to Kane_MultiDiscountAPI_Model_Order_Creditmemo_Api which should mean everything is working.

The file that contains the class I'm trying to rewrite is: app/code/Mage/Sales/Model/Order/Creditmemo/Api.php

FILES IN MY EXTENSION:

app/etc/modules/Kane_MultiDiscountAPI.xml

<?xml version="1.0" encoding="UTF-8"?>
 <config>
    <modules>
        <Kane_MultiDiscountAPI>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Sales />
            </depends>
        </Kane_MultiDiscountAPI>
    </modules>
</config>

app/code/local/Kane/MultiDiscountAPI/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Kane_MultiDiscountAPI>
            <version>0.1.0</version>
        </Kane_MultiDiscountAPI>
    </modules>
    <global>
        <models>
            <sales>
                <rewrite>
                    <order_api>Kane_MultiDiscountAPI_Model_Order_Api</order_api>
                    <order_creditmemo_api>Kane_MultiDiscountAPI_Model_Order_Creditmemo_Api</order_creditmemo_api>
                </rewrite>
            </sales>
        </models>
    </global>
</config>

app/code/local/Kane/MultiDiscountAPI/Model/Order/Creditmemo/Api.php

class Kane_MultiDiscountAPI_Model_Order_Creditmemo_Api extends Mage_Sales_Model_Order_Creditmemo_Api
{
    public function info($creditmemoIncrementId)
    {
        $result = parent::info($creditmemoIncrementId);
        // Extended logic
        return $result;
    }
}
2
  • Have you registered your module in app/etc/modules (Kane_MultiDiscountAPI.xml) and set it to depend on Mage_Sales ?
    – scrowler
    Aug 10, 2015 at 23:48
  • See updated question. Yes, I have registered the module and set it to depend on Mage_Sales.
    – Kane Shaw
    Jul 25, 2016 at 8:42

2 Answers 2

0

I think your config.xml is totally fine.last override for credit memos is wrong,but first two rewrite is correct.Need to check the model class code.

my skye is kinex.sourav. & am magento developer. join me at skype

0

The only way I can reproduce this is by having something wrong with your module registration file (app/etc/modules/Kane_MultiShippingAPI.xml).

Considering the following:

# File: app/etc/modules/Kane_MultiShippingAPI.xml
<?xml version="1.0"?>
<config>
    <modules>
        <Kane_MultiDiscountAPI>
            <active>true</active>
            <codePool>local</codePool>
        </Kane_MultiDiscountAPI>
    </modules>
</config>

If I use that with the rest of the code you've provided and test the class lookup with Magerun, I get your model:

$ magerun.phar dev:class:lookup model sales/order_api
Model sales/order_api resolves to Kane_MultiDiscountAPI_Model_Order_Api

However, if you use codepool instead of codePool, or anything else is broken in your module then it will resolve back to Mage_Sales_Model_Order_Api.

As KESHAV_SOURAV has already mentioned, this line of your config.xml is not necessary (presume its a hangover from testing) - there is no Mage_Sales_Sales class path:

<sales_order_creditmemo_api>Kane_MultiDiscountAPI_Model_Order_Creditmemo_Api</sales_order_creditmemo_api>

Also - it must be said: make sure you've cleared your cache (or disabled it while testing).

3
  • I don't really expect followup from you but I've only just looked at this problem again and still can't get it working. My Sales Order API rewrite works fine, it's the Credit Memo API rewrite that will NOT work. I've checked over my code time and time again and can't see anything wrong. When I use magerun.phar dev:class:lookup model sales/order_creditmemo_api it says it correctly resolves to my class, yet when I access the API method it still uses the Mage core credit memo API class instead. I checked this by putting a mage::log command in the core api class, and my class.
    – Kane Shaw
    Jul 25, 2016 at 8:19
  • Also, I have updated my question to be more concise.
    – Kane Shaw
    Jul 25, 2016 at 8:42
  • It might sound silly but have you ensured your cache is properly cleared? Your code looks fine
    – scrowler
    Jul 25, 2016 at 19:04

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.