4

I want to rewrite a model from an extension in the "local"-folder. My Extension is also in the "local"-folder but it doesn't work and i have no clue what I'm doing wrong.

The relevant part of the config.xml from the extension i want to override. (app/code/local/Customweb/Saferpay/etc/config.xml)

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Customweb_Saferpay>
        <version>1.0.0</version>
    </Customweb_Saferpay>
</modules>
<global>
    <models>
        <saferpay>
            <class>Customweb_Saferpay_Model</class>
            <resourceModel>saferpay_mysql4</resourceModel>
        </saferpay>
    ...

My config.xml (app/code/local/Etagen/SaferpayGuestOrderFix/etc/config.xml)

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Etagen_SaferpayGuestOrderFix>
            <version>0.1.0</version>
        </Etagen_SaferpayGuestOrderFix>
    </modules>
    <global>
        <models>
            <etagen_saferpayguestorderfix>
                <class>Etagen_SaferpayGuestOrderFix_Model</class>
            </etagen_saferpayguestorderfix>
            <saferpay>
                <rewrite>
                    <method>Etagen_SaferpayGuestOrderFix_Model_Method</method>
                </rewrite>
            </saferpay>
        </models>
    </global>
</config>

My Model (app/code/local/Etagen/SaferpayGuestOrderFix/Model/Method.php)

<?php
class Etagen_SaferpayGuestOrderFix_Model_Method extends Customweb_Saferpay_Model_Method
{
    public function getPaymentPageLink()
    {
        ...code...
    }
}

Extension activation (app/etc/modules/Etagen_SaferpayGuestOrderFix.xml)

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Etagen_SaferpayGuestOrderFix>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Customweb_Saferpay />
            </depends>
        </Etagen_SaferpayGuestOrderFix>
    </modules>
</config>

(The Extension is active in Backend System > Configuration > Advanced)

But the change i made in the getPaymentPageLink is ignored.

Thanks for help

* UPDATE *

The whole config.xml without comment part (app/code/local/Customweb/Saferpay/etc/config.xml)

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
    <Customweb_Saferpay>
        <version>1.0.0</version>
    </Customweb_Saferpay>
</modules>
<global>
    <models>
        <saferpay>
            <class>Customweb_Saferpay_Model</class>
            <resourceModel>saferpay_mysql4</resourceModel>
        </saferpay>
        <saferpay_mysql4>
            <class>Customweb_Saferpay_Model_Mysql4</class>
                <entities>
                    <carddata>
                        <table>saferpay_card_data</table>
                    </carddata>
                </entities>
        </saferpay_mysql4>
    </models>
    <blocks>
        <saferpay><class>Customweb_Saferpay_Block</class></saferpay>
    </blocks>
    <helpers>
        <saferpay>
            <class>Customweb_Saferpay_Helper</class>
        </saferpay>
    </helpers>
    <resources>
        <saferpay_write>
            <connection>
                <use>core_write</use>
            </connection>
        </saferpay_write>
        <saferpay_read>
            <connection>
                <use>core_read</use>
            </connection>
        </saferpay_read>
        <saferpay_setup>
             <setup>
                <module>Customweb_Saferpay</module>
                <class>Customweb_Saferpay_Model_Resource_Setup</class>
             </setup>
        </saferpay_setup>
    </resources>
    <events>
        <core_block_abstract_to_html_before>
            <observers>
                <saferpay_html_before>
                    <type>singleton</type>
                    <class>Customweb_Saferpay_Model_Observer</class>
                    <method>htmlBefore</method>
                </saferpay_html_before>
            </observers>
        </core_block_abstract_to_html_before>
        <payment_info_block_prepare_specific_information>
            <observers>
                <saferpay_payment_info_block>
                    <type>singleton</type>
                    <class>Customweb_Saferpay_Model_Observer</class>
                    <method>paymentInfoBlock</method>
                </saferpay_payment_info_block>
            </observers>
        </payment_info_block_prepare_specific_information>
    </events>
    <sales>
        <order>
            <statuses>
                <canceled_saferpay translate="label">
                    <label>Canceled Saferpay</label>
                </canceled_saferpay>
                <pending_saferpay translate="label">
                    <label>Pending Saferpay</label>
                </pending_saferpay>
            </statuses>
            <states>
                <canceled>
                    <statuses>
                        <canceled_saferpay />
                    </statuses>
                </canceled>
                <pending_payment>
                    <statuses>
                        <pending_saferpay />
                    </statuses>
                </pending_payment>
            </states>
        </order>
    </sales>
</global>

<adminhtml>
    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <saferpay translate="title" module="Saferpay">
                                        <title>Saferpay</title>
                                    </saferpay>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
</adminhtml>

<frontend>
    <blocks>
        <Saferpay>
            <class>Customweb_Saferpay_Block</class>
        </Saferpay>
    </blocks>
    <layout>
        <updates>
            <saferpay>
                <file>saferpay.xml</file>
            </saferpay>
        </updates>
    </layout>
    <routers>
        <Saferpay>
            <use>standard</use>
            <args>
                <module>Customweb_Saferpay</module>
                <frontName>Saferpay</frontName>
            </args>
        </Saferpay>
    </routers>

    <translate>
        <modules>
            <Customweb_Saferpay>
                <files>
                    <default>Customweb_Saferpay.csv</default>
                </files>
            </Customweb_Saferpay>
        </modules>
    </translate>
</frontend>

<default>
    <saferpay>
        <general>
            <mode>1</mode>
            <create_pay_init_url>https://www.saferpay.com/hosting/CreatePayInit.asp</create_pay_init_url>
            <verify_pay_confirm_url>https://www.saferpay.com/hosting/verifypayconfirm.asp</verify_pay_confirm_url>
            <verify_enrollment_url>https://www.saferpay.com/hosting/VerifyEnrollment.asp</verify_enrollment_url>
            <execute_url>https://www.saferpay.com/hosting/Execute.asp</execute_url>
            <pay_complete_url>https://www.saferpay.com/hosting/PayComplete.asp</pay_complete_url>
            <test_account_id>99867-94913159</test_account_id>
            <test_password>XAjc3Kna</test_password>
            <cardref_count>0</cardref_count>
            <cardref_id_scheme>cardref_{ID}</cardref_id_scheme>
            <order_id_schema>order_{ID}</order_id_schema>
            <invoice_settlement>manual</invoice_settlement>
            <capture_invoice>manual</capture_invoice>
            <liability_shift_only>1</liability_shift_only>
            <can_use_scd>0</can_use_scd>
            <safe_cc_data>0</safe_cc_data>
            <usernotify>0</usernotify>
            <notifyaddress>0</notifyaddress>
        </general>
        <paymentpage>
            <autoclose>0</autoclose>
            <ccname>1</ccname>
            <showlanguages>1</showlanguages>
        </paymentpage>
    </saferpay>
</default>

7
  • Are you sure the model is not instantiated directly, without using Mage::getModel() factory? I assume you are trying to rewrite a payment extension. Can you post the config.xml definition of the payment method? This is found in the XML node default/payment/[payment method code]/model
    – fmrng
    Commented May 31, 2013 at 12:18
  • No I'm not sure how the model is beeing instantiated, easy/quick way to check? Yes it's a payment extension. Du you mean the config.xml of the Payment Extension?
    – Manuel
    Commented May 31, 2013 at 13:08
  • Post the part of the config.xml under default/payment, this is where the payment model is defined.
    – fmrng
    Commented May 31, 2013 at 13:15
  • There is no default/payment. I add the whole config.xml now.
    – Manuel
    Commented May 31, 2013 at 13:46
  • I would have a look in Customweb_Saferpay_Model_Observer::paymentInfoBlock(), where the info block is loaded configured. From what it looks like, they don't use Magento [class_group]/[class] convention, so it could be that they instantiate the model directly. In that case, your rewrites won't work, since they are not found in the configuration.
    – fmrng
    Commented May 31, 2013 at 14:48

2 Answers 2

2

It is strange! I just copy your logic and test it, not worked after that I start to debug model load flow, edited and review logs. So finally it worked! But my code same as yours: Customweb_Saferpay module:

    <models>
        <saferpay>
            <class>Customweb_Saferpay_Model</class>
            <resourceModel>saferpay_mysql4</resourceModel>
        </saferpay>
    </models>

Etagen_SaferpayGuestOrderFix module:

   <models>
        <etagen_saferpayguestorderfix>
            <class>Etagen_SaferpayGuestOrderFix_Model</class>
        </etagen_saferpayguestorderfix>
        <saferpay>
            <rewrite>
                <method>Etagen_SaferpayGuestOrderFix_Model_Method</method>
            </rewrite>
        </saferpay>
    </models>

Method.php:

class Customweb_Saferpay_Model_Method
{
    public function getPaymentPageLink()
    {
        return get_class($this);
    }

}

Second one:

class Etagen_SaferpayGuestOrderFix_Model_Method extends  Customweb_Saferpay_Model_Method{

}

Testing code:

$model = Mage::getModel('saferpay/method');
echo $model->getPaymentPageLink();

But result sometimes correct, sometimes incorrect (incorrect after cleaning of cache). Finally I found such xml config and it gives correct result alltime:

    <models>
        <etagen_saferpayguestorderfix>
            <class>Etagen_SaferpayGuestOrderFix_Model</class>
        </etagen_saferpayguestorderfix>
        <saferpay>
            <deprecatedNode>etagen_saferpay</deprecatedNode>
        </saferpay>
        <etagen_saferpay>
            <rewrite>
                <method>Etagen_SaferpayGuestOrderFix_Model_Method</method>
            </rewrite>
        </etagen_saferpay>
    </models>

Who reads this question, please, test it and I can't find reason of such behavior of Magento. Location of models are located in same code pool and maybe this is reason of such understandable situation.

6
  • Thanks for your effort! I copied your last xml model snippet into my config.xml, clean cache and tried it 3 times but it didn't worked once.
    – Manuel
    Commented May 31, 2013 at 13:45
  • What environment do you use? Do you test with my snippet? Can you give us full config file? If you use as Payment method, magento loads payment classes a little differ way. But I get correct result via this snippet.
    – mageUz
    Commented May 31, 2013 at 13:52
  • What do you mean exactly with environment? I don't use your Testing code, i test it within the ordering process. My full config file is in my starting post (but the <model> block is replaced by your code)
    – Manuel
    Commented May 31, 2013 at 13:59
  • The getPaymentPageLink(); is called in the ProcessController from the Extension in the redirectAction: header('Location: ' . $payment->getMethodInstance()->getPaymentPageLink());
    – Manuel
    Commented May 31, 2013 at 14:05
  • Simple way to do this, edit original payment model function. By the way I can't find standard Magento approach for payment module in your config.xml file.
    – mageUz
    Commented May 31, 2013 at 14:31
2

I got the same problem.

First step was to install modules-conflict-detector. So you could see what rewrite is created and if there is a confliced you need to resolve with <depends>.

Second was a blog post the first correct explanation of the rewrite I have ever seen. I added 1 and 2 to make it even clearer. You like to overwrite this:

 Mage::getModel('customer1/customer2')
                  |           |_ Is the <customer2> tag inside the <rewrite> element.
                  |_ Is the <customer1> tag outside the <rewrite> element.

So you name your tags like that:

 <global>
        <models>
            <customer1>
                <rewrite>
                    <customer2>Super_Awesome_Model_Customer</customer2>
                </rewrite>
            </customer1>
        </models>
  </global>

and create a file Super/Awesome/Model/Customer.php with:

class Super_Awesome_Model_Customer extends Mage_Customer_Model_Customer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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