3

my client runs a multishop with very different products, different layouts and different domains. I developed an extension for the checkout process for one of the stores and now don't see a way to tell Magento only to work with this specific store.

I expect this to be mentioned in the /app/etc/modules/sampleextension.xml, but didn't find any information on this in the internet.

Is there a way to make an extension shop-specific?

Thanks Thomas

Thomas
  • 136
  • 3
  • 10

2 Answers2

4

There are two solutions. 1) Programmatically: You can make any configuration field, store specific. And from that you can check, in code if you need to activate your module or not. With the file /app/code//yourcompany/yourmodule/etc/system.xml, thanks to the tags show_in_default, show_in_store, show_in_website, you can set a configuration field store view, website or by default.

So you must create a configuration field "active". It means that the path of the payment method configuration field "active" will be payment/yourpaymentname/active.

And from this path and if you have extended your payment class with the class Mage_Payment_Model_Method_Abstract, Magento will check if the payment module is available.

Check the class and method Mage_Payment_Model_Method_Abstract::isAvailable at the file app/code/core/Mage/Payment/Model/Method/Abstract.php

When you will configure your payment method in backend, you will have to set to "1" the field "active" for the store view or website or by default, following your wish.

Here an example for the configuration file system.xml for your payment module

<config>
   <sections>
    <payment translate="label" module="payment">
        <label>Payment Methods</label>
        <tab>sales</tab>
        <frontend_type>text</frontend_type>
        <sort_order>400</sort_order>
        <show_in_default>1</show_in_default>
        <show_in_website>1</show_in_website>
        <show_in_store>1</show_in_store>
        <groups>
            <yourpaymentname translate="label">
                <label>Your new Payment method</label>
                <frontend_type>text</frontend_type>
                <sort_order>1</sort_order>
                <show_in_default>1</show_in_default>
                <show_in_website>1</show_in_website>
                <show_in_store>1</show_in_store>
                <fields>
                    <active translate="label">
                        <label>Enabled</label>
                        <frontend_type>select</frontend_type>
                        <source_model>adminhtml/system_config_source_yesno</source_model>
                        <sort_order>1</sort_order>
                        <show_in_default>1</show_in_default>
                        <show_in_website>1</show_in_website>
                        <show_in_store>0</show_in_store>
                    </active>
            <yourpaymentname>
        </groups>
        ....
    </sales>
<sections>

2) The second solution can be done through the backend, the easiest way maybe, in the tab Advanced of the configuration page, at the bottom left of the configuration page. You will have a list of all enabled or disabled modules in your shop. You select which store view you want to display or not, in the store switcher, at the top left of the page then you choose which module to enable or not thanks to the drop down menu in front of each module name.

Hope it helps Regards

Sylvain Rayé
  • 2,456
  • 16
  • 23
  • Not correct. The panel under System > Configuration > Advanced disabled module output only. The extension and its configuration are still active. – benmarks Oct 19 '11 at 18:02
  • @Ben: yes it's true and it will not show the payment method on the frontend and don't allow a customer to use it during the checkout process. At the end, the need is completed. The customer has no access to the payment method output. It's the easiest way if the poster is not a developer. – Sylvain Rayé Oct 19 '11 at 20:48
  • @Diglin thanks for your solutions. I probably have to review the first solution again. The second way seems much easier and I will give it a try. – Thomas Oct 20 '11 at 17:22
  • @Ben: yes. You are right, the advanced tab disable the output display of a module normally. By doing this, it should not display the payment method too but I admit I didn't tried for a payment method because default payment method has an active field to enable or not a payment method per store view. – Sylvain Rayé Oct 20 '11 at 20:16
0

you could/should have a "active" field, in your system.xml, which'd be a dropdown "yes/no", and then you can (des)active it for every website/store/store view.
Of course in some strategic points of your code you will check if it's active for this view :)

OSdave
  • 8,538
  • 7
  • 45
  • 60