public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $subject, $result)
{
$districtAttributeCode = 'district_id';
$districtField = [
'component' => 'Vendor_Module/js/form/element/district',
'config' => [
'customScope' => 'shippingAddress',
'customEntry' => 'shippingAddress.district',
'template' => 'ui/form/field',
'elementTmpl' => 'ui/form/element/select',
],
'dataScope' => 'shippingAddress.district_id',
'provider' => 'checkoutProvider',
'filterBy' => [
'target' => '${ $.provider }:${ $.parentScope }.region_id',
'field' => 'region_id',
],
'customEntry' => 'shippingAddress.region_id'
];
$result['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$districtAttributeCode] = $districtField;
return $result;
}
public function afterProcess(\Magento\Checkout\Block\Checkout\DirectoryDataProcessor $directoryDataProcessor, $jsLayout)
{
if (!isset($jsLayout['components']['checkoutProvider']['dictionaries']['district_id'])) {
$jsLayout['components']['checkoutProvider']['dictionaries']['district_id'] =
[
[
'value' => ’’,
'label' => ‘’,
'title' => ‘’,
‘region_id’ => ‘’,
],….
];
}
return $jsLayout;
}
enter code here
define([
'Magento_Ui/js/form/element/select'
], function ( Select) {
'use strict';
return Select.extend({
defaults: {
skipValidation: false,
imports: {
update: '${ $.parentName }.region_id:value',
initialOptions: "index =
checkoutProvider:dictionaries.district_id",
setOptions: "index = checkoutProvider:dictionaries.district_id"
}
},
});
});
Best Answer
Here are the few free extensions for Magento 2 city Dropdwon
If you are not willing to use any extension then you will need to overwrite this file
vendor\magento\module-checkout\Block\Cart\LayoutProcessor.php
and replace the process function with this one. Option array is empty in below codeThere should be custom option array for cities in array options
I hope this will help