I use magento 2.0.7 is it possible to custom the checkout page city field(text) to dropdown list?
2 Answers
Yes.
The easiest would be to add a new entity where the values for your cities are stored. In the frontend, just change the input type to dropdown and load the list of cities. When a user selects a field from the dropdown, store the text value (as it is now). You could even do a check if the selected city is a valid one from your city list before storing the data. This way you don't have to change a lot.
A more advanced approach (if needed) would be to also add relations to the directory_country and/or directory_country_region tables to only show cities which belong to the specific country or region selected in the checkout.
- Can you please share screen of the table as i am not finding any city field these tablesMukesh Prajapati– Mukesh Prajapati2019-11-20 12:02:26 +00:00Commented Nov 20, 2019 at 12:02
for the sesion of estimate shipping and Tax of magento you will need overwrite of the class \Magento\Checkout\Block\Cart\LayoutProcessor.
$elements = [ 'city' => [ 'visible' => true, 'formElement' => 'select', 'label' => __('City'), 'value' => '', 'options' => array_option(), ], 