0

I want to load all available payment methods in a multiselect system config in admin. Could some one help?

2

In system.xml

,

<test translate="label">
      <label>Available Payments</label>
      <frontend_type>select</frontend_type>
      <source_model>module_name/system_config_source_payment</source_model>
      <sort_order>5</sort_order>
      <show_in_default>1</show_in_default>
      <show_in_website>1</show_in_website>
      <show_in_store>1</show_in_store>
</test>

In Namespace/Modulename/Model/System/Config/Source/Payment.php

class Namespace_Modulename_Model_System_Config_Source_Payment
{
        public function toOptionArray()
        {
           $payments = Mage::getSingleton('payment/config')->getActiveMethods();

           //$methods = array(array('value'=>'', 'label'=>Mage::helper('adminhtml')->__('--Please Select--')));

           foreach ($payments as $paymentCode=>$paymentModel) {
                $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
                $methods[$paymentCode] = array(
                    'label'   => $paymentTitle,
                    'value' => $paymentCode,
                );
            }
            return $methods;
        }
}
  • This doesn't work anymore , there is issue near foreach ($payments as $paymentCode=>$paymentModel) {, specifically with $paymentCode – Kumar A. Feb 12 '18 at 14:39
  • Works fine for me... no issue near foreach... – Wayne Theisinger May 15 '18 at 17:23
0

Slight improvement on above answer - makes solution store specific.

 class Namespace_Module_Model_System_Config_Source_Payment
 {
   public function toOptionArray()
   {
    //need to workout which store we are on
    $methods = [];
    $currentStoreId = null;

    /* Get current configuration store code */
    if(strlen($currentStoreCode = Mage::getSingleton('adminhtml/config_data')->getStore())){
        $currentStoreId = Mage::getModel('core/store')->load($currentStoreCode)->getId();
    }

    $payments = Mage::getSingleton('payment/config')->getActiveMethods($currentStoreId);

    foreach ($payments as $paymentCode=>$paymentModel) {
        $paymentTitle = Mage::getStoreConfig('payment/'.$paymentCode.'/title');
        $paymentTitle .= ' ('.$paymentCode.')';
        $methods[$paymentCode] = array(
            'label'   => $paymentTitle,
            'value' => $paymentCode,
        );
    }
    return $methods;
}

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.