2

My website is multi-store

Magento after upgrade 2.2.7 to 2.3.4, facing an issue which creates new order as below

countryId is required. Enter and try again.

On debug I came across that issue is in file

[2020-02-14 10:14:59] report.CRITICAL: "countryId" is required. Enter and try again. {"exception":"[object] (Magento\Framework\Exception\InputException(code: 0): \"countryId\" is required. Enter and try again. at vendor/magento/module-customer/Model/ResourceModel/AddressRepository.php:133)"}

I have verified this link https://github.com/magento/magento2/issues/14232 but not working

Following code is causing the issue

/*$countryElement = $this->_form->getElement('country_id');

    $this->processCountryOptions($countryElement);

    if ($countryElement->getValue()) {
        $countryId = $countryElement->getValue();
        $countryElement->setValue(null);
        foreach ($countryElement->getValues() as $country) {
            if ($country['value'] == $countryId) {
                $countryElement->setValue($countryId);
            }
        }
    }
    if ($countryElement->getValue() === null) {
        $countryElement->setValue(
            $this->directoryHelper->getDefaultCountry($this->getStore())
        );
    }*/
0

Go to Stores -> General -> State Option and then unselect all country and clear cache and try again

|improve this answer|||||
  • Not working. We have already this solution – Arjun Feb 26 at 8:53
0

Based on your code it looks like this when you are creating an order in the admin area?

It's hard to give a detailed answer without seeing your code base but these questions might help:

  1. Are there any custom changes to the address form that might mean the country id is removed or missing? (This might have been "ok" to do in 2.2 but not 2.3)

  2. Have you tried logging/dumping the value of $this->_form->getElement('country_id'); at that point?

  3. Does this happen when you create an order through the front end as well?

|improve this answer|||||
  • 1. We have not made any changes, 2. It is returning 'Null', 3. In frontend it is working fine – Arjun Mar 5 at 8:58
0

You need to run this command:

update eav_attribute set is_required = 0 where attribute_code = 'country_id'
|improve this answer|||||
  • We tried this but not working – Arjun Mar 12 at 8:55
  • please clear cache and try to run the command again. – LitExtension Magento Migration Mar 13 at 1:28
  • After making changes I have ran all magento commands – Arjun Mar 13 at 7:18
  • No it is not working – Arjun Mar 17 at 5:13

Your Answer

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

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