0

I want to pass boolean argument to class method from uicomponent_form.xml

My xml code is

<field name="allow_shipping_method">
            <argument name="data" xsi:type="array">
                <item name="options" xsi:type="object">Magento\Shipping\Model\Config\Source\Allmethods</item>
                <item name="config" xsi:type="array">
                    <item name="formElement" xsi:type="string">multiselect</item>
                    <item name="source" xsi:type="string">myform</item>
                    <item name="dataScope" xsi:type="string">allow_shipping_method</item>
                    <item name="label" xsi:type="string" translate="true">Allow Shipping Method</item>
                </item>
            </argument>
        </field>   

This is calling public function toOptionArray($isActiveOnlyFlag = false) method of Magento\Shipping\Model\Config\Source\Allmethods.

There is anyway to pass argument?? is magento is providing such kind of things?

| improve this question | | | | |
0

if you look at the checkout_index_index.xml the boolean passed as below,

<item name="visible" xsi:type="boolean">false</item>

Can you please try to use similar in your following code and try to access it in class.

<field name="allow_shipping_method">
<argument name="data" xsi:type="array">
    <item name="options" xsi:type="object">Magento\Shipping\Model\Config\Source\Allmethods</item>
    <item name="config" xsi:type="array">
        <item name="formElement" xsi:type="string">multiselect</item>
        <item name="source" xsi:type="string">myform</item>
        <item name="dataScope" xsi:type="string">allow_shipping_method</item>
        <item name="visible" xsi:type="boolean">false</item>
        <item name="label" xsi:type="string" translate="true">Allow Shipping Method</item>
    </item>
</argument>

Let me know your thoughts.

Thanks,Sam

| improve this answer | | | | |
  • Still all methods are coming, I have checked with both visible false & true. – Himanshu Oct 5 '18 at 12:51
0

you can make your custom class over there and use :

<?php

    namespace Vendor\Namespace\Model;

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

   class Method extends \Magento\Framework\DataObject 
         implements \Magento\Framework\Option\ArrayInterface
   {
      /**
       * @var ScopeConfigInterface
       */
         protected $_scopeConfig;

      /**
       * @var Config
       */
         protected $_deliveryModelConfig;

      /**
       * @param ScopeConfigInterface $scopeConfig
       * @param Config    $deliveryModelConfig
       */
        public function __construct(
            ScopeConfigInterface $scopeConfig,
            Config $deliveryModelConfig
        ) {

             $this->_scopeConfig = $scopeConfig;
             $this->_deliveryModelConfig = $deliveryModelConfig;
         }

         public function toOptionArray()
         {
             $deliveryMethods = $this->_deliveryModelConfig->getActiveCarriers();
             $deliveryMethodsArray = array();
             foreach ($deliveryMethods as $shippigCode => $shippingModel) {
               $shippingTitle = $this->_scopeConfig->getValue('carriers/'.$shippigCode.'/title');
               $deliveryMethodsArray[$shippigCode] = array(
               'label' => $shippingTitle,
               'value' => $shippigCode
              );
             }
            return $deliveryMethodsArray;
          }
    }
| improve this answer | | | | |

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.