1

i am trying to city as dropdown in only checkout page with following script in Magento\Checkout\Block\Cart\LayoutProcessor.php

$elements = [
        'city' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('City'),
            'options' => [
                [
                    'value' => '',
                    'label' => 'Please Select',
                ],
                [
                    'value' => '1',
                    'label' => 'First Option',
                ]
            ],
            'value' =>  null
        ],
        'country_id' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('Country'),
            'options' => [],
            'value' => null
        ],
        'region_id' => [
            'visible' => true,
            'formElement' => 'select',
            'label' => __('State/Province'),
            'options' => [],
            'value' => null
        ],
        'postcode' => [
            'visible' => true,
            'formElement' => 'input',
            'label' => __('Zip/Postal Code'),
            'value' => null
        ]
    ];

but still it's showing as input text filed. Any one can please suggest best solution

2

1 Answer 1

0

You are working on wrong layoutProcessor. Please, read this documentation which will explain you how to modify existing field on checkout: http://devdocs.magento.com/guides/v2.0/howdoi/checkout/checkout_new_field.html

You should register your own layoutProcessor and modify layout array or, for tests purpose, you can modify vendor/magento/module-checkout/Block/Checkout/LayoutProcessor.php which is the proper class to work with.

2
  • Bartosz, i think that documentation informs that "how to add new field in checkout not exiting field
    – Ramesh
    Dec 14, 2017 at 9:37
  • Process is the same but instead of adding new you have to modify existing in your processor. So, in practice, instead of adding new data to layout array modify the part of array which holds city component data. Of course, there is a little bit more in docs due to a fact it is about creating a new field BUT a little more knowledge will not hurt anyone. Dec 14, 2017 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.