0

I need to rewrite some classes per website level in Magento 1.x. Is it possible?

Basically looking some way as If website is "A" then rewrite this class & its method. But if website is "B" then don't do anything.

As for layout control per website we can do this & if we disable mymodule from backend per website my layout will not be visible.

    <layout>
        <updates>
            <mymodule module="Akhil_Mymodule">
                <file>mymodule.xml</file>
            </mymodule>
        </updates>
    </layout>

Like same way can we do something for rewrite also?

3
  • you can check a website condition in class. – Ashish Madankar M2 Professiona May 9 '16 at 11:20
  • Yes but need something like "If website is "A" then rewrite this class & its method. But if website is "B" then don't do anything." – Akhil Gupta May 9 '16 at 11:32
  • Added more description. – Akhil Gupta May 9 '16 at 11:34
3

you cannot rewrite classes at website level, because classes (as entities) are website agnostic.
But you can use some tricks like this.

Let's say that you need to rewrite a method called doSomething the class A for website w1 only.
Rewrite the class, and make the doSomething method look like this:

class B extends A 
{
    public function doSomething()
    {
        $website = Mage::app()->getWebsite();  
        if ($website->getCode() != 'w1') {
             return parent::doSomething();
        }
        //your awesome code here
    }   
}
1
  • Thanks..! I had also module conflict-ion issue (Three modules A,B,C(in local codepool)). So instead parent i used the classname of model for my third module C. It's working as expected. – Akhil Gupta May 9 '16 at 13:20

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.