0

I followed two guides to create a shipping method and a payment method, the two works normally, but I want to show the payment method only if the shipping method is selected, and because I think it's the best way, I put all the code in the same extension... now, the payment method doesn't appear in the frontend because is inactive.

And I don't understand why.

My code:

config.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <modules>
        <Namespace_ModuleName>
            <module>0.0.1</module>
        </Namespace_ModuleName>
    </modules>
    <global>
        <helpers>
            <modulename>
                <class>Namespace_ModuleName_Helper</class>
            </modulename>
        </helpers>
        <models>
            <modulename>
                <class>Namespace_ModuleName_Model</class>
            </modulename>
        </models>
    </global>
    <default>
        <carriers>
            <modulename>
                <active>1</active>
                <title>Custom Title ship</title>
                <model>modulename/carrier_ship</model>
                <sort_order>10</sort_order>
            </modulename>
        </carriers>
        <payment>
            <modulename>
                <active>1</active>
                <title>Custom Title pay</title>
                <model>modulename/payment_pay</model>
                <order_status>processing</order_status>
                <payment_action>sale</payment_action>
                <allowspecific>0</allowspecific>
                <sort_order>1</sort_order>
            </modulename>
        </payment>
    </default>
    <frontend>
        <events>
            <payment_method_is_active>
                <observers>
                    <modulename_payment_method_is_active>
                        <type>singleton</type>
                        <class>modulename/observer</class>
                        <method>paymentMethodIsActive</method>
                    </modulename_payment_method_is_active>
                </observers>
            </payment_method_is_active>
        </events>
    </frontend>
</config>

System:

system.xml

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <sections>
        <carriers>
            <groups>
                <modulename translate="label" module="modulename">
                    <label>Custom Label Carrier</label>
                    <frontend_type>text</frontend_type>
                    <sort_order>2</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</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>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </title>
                        <sort_order translate="label">
                            <label>Sort Order</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>100</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sort_order>
                        <sallowspecific translate="label">
                            <label>Ship to Applicable Countries</label>
                            <frontend_type>select</frontend_type>
                            <sort_order>90</sort_order>
                            <frontend_class>shipping-applicable-country</frontend_class>
                            <source_model>adminhtml/system_config_source_shipping_allspecificcountries</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </sallowspecific>
                        <specificcountry translate="label">
                            <label>Ship to Specific Countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>91</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                    </fields>
                </modulename>
            </groups>
        </carriers>
        <payment>
            <groups>
                <modulename translate="label" module="modulename">
                    <label>Custom Label Payment</label>
                    <sort_order>670</sort_order>
                    <show_in_default>1</show_in_default>
                    <show_in_website>1</show_in_website>
                    <show_in_store>0</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>
                        <order_status translate="label">
                            <label>New order status</label>
                            <frontend_type>select</frontend_type>
                            <source_model>adminhtml/system_config_source_order_status_processing</source_model>
                            <sort_order>2</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </order_status>
                        <allowspecific translate="label">
                            <label>Payment from applicable countries</label>
                            <frontend_type>allowspecific</frontend_type>
                            <sort_order>40</sort_order>
                            <source_model>adminhtml/system_config_source_payment_allspecificcountries</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                        </allowspecific>
                        <specificcountry translate="label">
                            <label>Payment from Specific countries</label>
                            <frontend_type>multiselect</frontend_type>
                            <sort_order>50</sort_order>
                            <source_model>adminhtml/system_config_source_country</source_model>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>0</show_in_store>
                            <can_be_empty>1</can_be_empty>
                        </specificcountry>
                        <title translate="label">
                            <label>Title</label>
                            <frontend_type>text</frontend_type>
                            <sort_order>3</sort_order>
                            <show_in_default>1</show_in_default>
                            <show_in_website>1</show_in_website>
                            <show_in_store>1</show_in_store>
                        </title>
                    </fields>
                </modulename>
            </groups>
        </payment>
    </sections>
</config>

My model

Pay.php

<?php

class Namespace_ModuleName_Model_Payment_Pay extends Mage_Payment_Model_Method_Abstract
{
    protected $_code = 'pay';


/* I tried with and without it
    protected $canUseCheckout    = true;
    public function validate()
    {
        parent::validate();
    }*/
}

I can see my custom payment method in the database:

path           value
.../active      1

But in

app/code/core/Mage/Payment/Model/Method/Abstract.php
        public function isAvailable($quote = null)
        {
            $checkResult = new StdClass;
            $isActive = (bool)(int)$this->getConfigData('active', $quote ? $quote->getStoreId() : null);

Here $isActive isn't 1, like the payment methods I can see in the frontend

  • Post your payment model <model>modulename/payment_pay</model> – Keyur Shah Jan 17 '18 at 19:01
  • It was at the end of the config files, but I put it separately – oootramas Jan 18 '18 at 8:04
  • So it contains only protected $_code = 'pay'; ? – Keyur Shah Jan 18 '18 at 8:12
  • I tried the guide only for the payment method and it's works only with that, it's when I add the shipping method that I can't see it – oootramas Jan 18 '18 at 8:16
0

If your want to get your config field instead of configData... you get it like this:

$isActive = Mage::getStoreConfig('section/group/field'); // it returns 0 or 1

Frontend_type select of "adminhtml/system_config_source_yesno" return this:
0 = disabled, No
1 = enabled, Yes
| improve this answer | |
  • I get the data to check the state of my payment method, what's I'm really want is to see it on the frontend, and for this, I need to set it active – oootramas Jan 18 '18 at 8:05

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.