0

I want to create a multiselect in the admin area which lists out payment methods.

Has anyone got any experience of this?

Just need system.xml and source model if applicable. I can sort rest.

enter image description here

2

Try this,

system.xml

<?xml version="1.0" ?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <tab id="getsquare" sortOrder="999" translate="label">
        <label>GetSquare</label>
    </tab>
    <section id="sales" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
        <label>Sales</label>
        <tab>GetSquare</tab>
         
  <resource>NameSpace_ModuleName::config_getsquare_adminpayments</resource>
        <group id="getsquare" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
            <label>NameSpace</label>
            <field id="adminpayments" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label" type="multiselect">
                <label>Admin Payments</label>
                <source_model>NameSpace\ModuleName\Model\Config\Source\Adminpayments</source_model>
            </field>
        </group>
    </section>
</system>
</config>

then add Source.php

<?php
namespace NameSpace\ModuleName\Model\Config\Source;

use \Magento\Framework\App\Config\ScopeConfigInterface;
use \Magento\Payment\Model\Config;

class Adminpayments extends \Magento\Framework\DataObject 
 implements \Magento\Framework\Data\OptionSourceInterface
{
  protected $_appConfigScopeConfigInterface;
  protected $_paymentModelConfig;
  public function __construct(
    ScopeConfigInterface $appConfigScopeConfigInterface,
    Config $paymentModelConfig
  ) {
      $this->_appConfigScopeConfigInterface = $appConfigScopeConfigInterface;
      $this->_paymentModelConfig = $paymentModelConfig;
 }
 public function toOptionArray()
 {
      $payments = $this->_paymentModelConfig->getActiveMethods();
      $methods = array();
      foreach ($payments as $paymentCode => $paymentModel) {
          $paymentTitle = $this->_appConfigScopeConfigInterface
            ->getValue('payment/'.$paymentCode.'/title');
          $methods[$paymentCode] = array(
            'label' => $paymentTitle,
            'value' => $paymentCode
        );
      }
      return $methods;
  }
}

Hope this helps.

6

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.