0

In Magento 2 checkout page, I have to convert zip code/Postal code text field to drop down.

Drop down portion is done, but I am not able to display the options (drop down values) under the drop down.

Magento_Checkout\layout\checkout_index_index.xml for postcode field change looks like below:

<referenceBlock name="checkout.root">
    <arguments>
        <argument name="jsLayout" xsi:type="array">
            <item name="components" xsi:type="array">
                <item name="checkout" xsi:type="array">
                    <item name="children" xsi:type="array">
                        <item name="steps" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="shipping-step" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shippingAddress" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="shipping-address-fieldset" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="postcode" xsi:type="array">
                                                            <item name="component" xsi:type="string">Magento_Ui/js/form/element/select</item>
                                                            <item name="options" xsi:type="array">Sm/Multe/Model/Config/Source/Options</item>
                                                            <item name="config" xsi:type="array">
                                                                 <item name="formElement" xsi:type="string">select</item>
                                                                 <item name="elementTmpl" xsi:type="string">ui/form/element/select</item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </item>
            </item>
        </argument>
    </arguments>
</referenceBlock>

Model\Config\Source\Options code is like below:

<?php
namespace Sm\Multe\Model\Config\Source;

use Magento\Framework\Option\ArrayInterface;

class Options implements ArrayInterface
{
    /**
     * @return array
     */
    public function toOptionArray()
    {
        $options = [
            0 => [
                'label' => 'Please select',
                'value' => 'sa'
            ],
            1 => [
                'label' => 'Option 1',
                'value' => 'sasa'
            ],
            2  => [
                'label' => 'Option 2',
                'value' => 'sasasa'
            ],
            3 => [
                'label' => 'Option 3',
                'value' => 'sasa'
            ],
        ];

        return $options;
    }
}

I am new to Magento, please let me know what I am doing wrong.

  • Can you post your full checkout_index_index.xml code and also you write wrong folder name it should be Magento_Checkout not Magento_checkout. – Sukumar Gorai Jul 25 '18 at 7:58
  • @SukumarGorai, folder name was a typo, also I updated the full checkout_index_index_xml code. Thanks – sapo Jul 25 '18 at 8:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.