Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CountryResolver won't resolve country #7

Open
akosglue opened this issue Mar 22, 2021 · 4 comments
Open

CountryResolver won't resolve country #7

akosglue opened this issue Mar 22, 2021 · 4 comments

Comments

@akosglue
Copy link

m2: 2.3.6
mirakl module version: 1.3.0

In my opinion this method will always return false.

private function getCountryIdByLabel($countryLabel, $locale = null)

It is because the array_search won't find the country code. The countries array contains country_code => country_name pairs.
I needed to add an earlier return with array_key_exists
See screenshot
Screenshot 2021-03-22 at 11 59 13

With this patch country_id will be the same as country in the addresses.
I see also that the validation should be skipped explicitely:

->setShouldIgnoreValidation(true);

However, I always get this error: Some addresses can't be used due to the configurations for specific countries.
because the country id was null.

With the above patch it is not null.

@jreinke
Copy link
Collaborator

jreinke commented Jun 15, 2021

Hello,

Sorry for the late reply.

I have verified the method and I confirm that the default connector's method is working as expected since the $countries variable returns an array map <country_code> => <country_name> and the array_search function will look for the country label in the array values and return the associated country code if found.
For example, I have just tested the method with "United States" country name and the method returns US for the locale en_US.

Or maybe am I missing something?

Best,

Johann

@akosglue
Copy link
Author

I see, so you called
getCountryIdByLabel("United States","en_US")
right?

In my setup I got the countryLabel parameter as the 2 digit ISO code, for example: BE
(as on my screenshot)
so the call was getCountryIdByLabel("BE","nl_BE")

That is something that caused by magento I think, this call
$this->getCountryIdByLabel($data['country']
can be different depending on the setup. So you got the full name like 'United States' but in my case it was 'BE'.

If I remember correctly the magento module 'bpost' was also involved.

@jreinke
Copy link
Collaborator

jreinke commented Jun 15, 2021

In this case, are you able to create a custom plugin on the resolve method that would come after the connector's execution and that will check the $countryId value? If false, you can add your own logic and fix the issue.

@akosglue
Copy link
Author

That's possible yes.
For the moment I just leave there the composer patch, it's working good for me.

`diff --git a/vendor/mirakl/magento2-seller-connector/Sales/Model/Address/CountryResolver.php b/vendor/mirakl/magento2-seller-connector/Sales/Model/Address/CountryResolver.php
index 22ecd743..ccff1cc6 100644
--- a/vendor/mirakl/magento2-seller-connector/Sales/Model/Address/CountryResolver.php
+++ b/vendor/mirakl/magento2-seller-connector/Sales/Model/Address/CountryResolver.php
@@ -61,6 +61,10 @@ class CountryResolver
{
$countries = $this->orderHelper->getCountryList($locale);

  •    if(array_key_exists($countryLabel,$countries)){
    
  •        return $countryLabel;
    
  •    }
    
  •    return array_search($countryLabel, $countries);
    
    }

@@ -92,4 +96,4 @@ class CountryResolver

     return $countryId;
 }

-}
\ No newline at end of file
+}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants