0

I'm working on one project and i wants some extra fields on cart page under estimate shipping and tax.

  1. Hide Country field
  2. Show State as "Province" Text
  3. Show City as "Canton" as a Dropdown (data will load from database).
  4. Show "District" custom field as Dropdown (data will load from database)
  5. Show Postal Code as Dropdown (data will load from database)

i've modified vendor/magento/module-checkout/Block/Cart/LayoutProcessor.php file

Original Code

$elements = [
            'city' => [
                'visible' => $this->isCityActive(),
                'formElement' => 'text',
                'label' => __('City'),
                'value' =>  null
            ],
            'country_id' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Country'),
                'options' => [],
                'value' => null
            ],
            'region_id' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('State'),
                'options' => [],
                'value' => null
            ],
            'postcode' => [
                'visible' => true,
                'formElement' => 'text',
                'label' => __('Postcode'),
                'value' => null
            ]
        ];

After Modification

$elements = [
            'city' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('cant贸n'),
                'value' =>  null
            ],
            'country_id' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Country'),
                'options' => [],
                'value' => null
            ],
            'region_id' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Provincia'),
                'options' => [],
                'value' => null
            ],
            'postcode' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Postal Code'),
                'value' => null
            ],
            'distro' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Distro'),
                'value' => null
            ]
        ];

this code isn't working I'm facing error

1 exception(s):
Exception #0 (Exception): Notice: Undefined index: sortOrder in /home/samarpan/mage.samarpanherbslife.com/vendor/magento/module-checkout/Block/Checkout/AttributeMerger.php on line 194

if i remove

            'distro' => [
                'visible' => true,
                'formElement' => 'select',
                'label' => __('Distro'),
                'value' => null
            ]

then it's working fine but City comes after postcode. so kindly please suggest or help me for

  1. How to load data from database to city field (Dropdown).
  2. How to add Custom field(Dropdown) and load data into it from database.
  3. How to move city above Postcode
  4. How to create, Manage and best way for Custom Tables, those link with another tables like, Country and State already linked. City Depends on State, District Depends on City, Postal Code Depends on District.

Thank you.

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.