DragonByte eCommerce : Country List not showing

swift

Well-known member
Registered
Joined
Apr 7, 2019
Messages
76
Points
28

Reputation:

I'm unable to set up current add-on, I have filled all details in invoice options and the only thing left is country but there are no options in the list to select other than "NONE"

Is there anyway of bypassing this or fixing this?

Screenshot 2021-10-09 004215.jpg


Screenshot 2021-10-09 004311.png
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

swift

Well-known member
Registered
Joined
Apr 7, 2019
Messages
76
Points
28

Reputation:

Hondo

Well-known member
Registered
Joined
Aug 22, 2021
Messages
45
Points
28

Reputation:

Self Issue here, no countrys....
Addon error?
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

For physical items you need to add Shipping zones, then the country.

Where did you get this dropdown list, is it if you buy your product, like this:
1633940562900.jpg
 

swift

Well-known member
Registered
Joined
Apr 7, 2019
Messages
76
Points
28

Reputation:

For physical items you need to add Shipping zones, then the country.

Where did you get this dropdown list, is it if you buy your product, like this:
View attachment 25868
BattleKingThat comes to another issue you can't enter the shipping zone:

Screenshot 2021-10-11 174518.jpg

Again you can't buy your own products because your locked out with further errors:

Screenshot 2021-10-11 174004.jpg


It just simply fudged unless there is something i can tweak to bypass this country bug, the settings are set up but it's the country that's stopping us going further
 

WinSys32

Collaborate
Collaborate
Registered
Joined
Oct 10, 2019
Messages
60
Points
63

Reputation:

In your admin panel, go to dragonbyte ecommerce, go to settings and their you find the settings. Fill in some, no one will see it as long as you don't offer bank transfers :)
 

Hondo

Well-known member
Registered
Joined
Aug 22, 2021
Messages
45
Points
28

Reputation:

No chance, Country pulldown is empty.

best regards
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

Here we got a problem with the restcountries api, this has been changed and it requires now an API key, even the URL has been changed.

This has been solved with the 2.4.0 version

Fix: Updated the Country API to account for changes in 3rd party services (now requires an API key)
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

I made some changes on the file: src\addons\DBTech\eCommerce\Repository\Country.php

getUntrusted('https://restcountries.eu/rest/v2/all');
is getting to
getUntrusted('http://api.countrylayer.com/v2/all?access_key=YOUR_API_KEY');

Example entry of requested api:
[{"name":"Afghanistan","topLevelDomain":[".af"],"alpha2Code":"AF","alpha3Code":"AFG","callingCodes":["93"],"capital":"Kabul","altSpellings":["AF","Af\u0121\u0101nist\u0101n"],"region":"Asia"}

The native_name do not exist any more, so I changed as well:
'native_name' => $country['native_name'],
to
'native_name' => $country['name'],

PHP:
    public function updateCountryList(): bool
    {
        $reader = $this->app()
            ->http()
            ->reader()
        ;

        $countryList = null;
       
        try
        {
            $response = $reader->getUntrusted('http://api.countrylayer.com/v2/all?access_key=YOUR_API_KEY');
            if ($response)
            {
                $jsonText = $response->getBody()->getContents();
               
                $response->getBody()->close();
               
                if ($response->getStatusCode() == 200)
                {
                    try
                    {
                        $countryList = \GuzzleHttp\json_decode($jsonText, true);
                    }
                    catch (\InvalidArgumentException $e)
                    {
                        \XF::logException($e, false, 'Security error:');
                        return false;
                    }
                }
                else
                {
                    \XF::logError(\XF::phraseDeferred('received_unexpected_response_code_x_message_y', [
                        'code' => $response->getStatusCode(),
                        'message' => $response->getReasonPhrase()
                    ]));
                    return false;
                }
            }
        }
        catch (\GuzzleHttp\Exception\RequestException $e)
        {
            \XF::logException($e, false, 'eCommerce error:');
            return false;
        }

        if (!is_array($countryList))
        {
            return false;
        }
       
        /** @var \DBTech\eCommerce\Entity\Country[]|\XF\Mvc\Entity\ArrayCollection $existingCountries */
        $existingCountries = $this->findCountriesForList()->fetch();

        $currentCountries = [];
        foreach ($countryList as $country)
        {
            if (!isset($existingCountries[$country['alpha2Code']]))
            {
                /** @var \DBTech\eCommerce\Entity\Country $newCountry */
                $newCountry = $this->em->create('DBTech\eCommerce:Country');
                $newCountry->bulkSet([
                        'country_code' => $country['alpha2Code'],
                        'name' => $country['name'],
                        'native_name' => $country['name'],
                        'iso_code' => $country['alpha3Code'],
                    ]);
                $newCountry->save();
               
                $currentCountries[$country['alpha2Code']] = $newCountry;
            }
            else
            {
                /** @var \DBTech\eCommerce\Entity\Country $newCountry */
                $newCountry = $existingCountries[$country['alpha2Code']];
               
                if ($newCountry->name != $country['name'])
                {
                    $newCountry->fastUpdate('name', $country['name']);
                }
               
                $currentCountries[$country['alpha2Code']] = $newCountry;
            }
        }
       
        $missingCountries = array_diff_key($existingCountries->toArray(), $currentCountries);
       
        /** @var \DBTech\eCommerce\Entity\Country $country */
        foreach ($missingCountries as $country)
        {
            $country->delete();
        }
       
        return true;
    }

After that run the two cron entries:

  1. DragonByte eCommerce: Update country list DragonByte eCommerce
  2. DragonByte eCommerce: Update VAT rates DragonByte eCommerce
 

swift

Well-known member
Registered
Joined
Apr 7, 2019
Messages
76
Points
28

Reputation:

I made some changes on the file: src\addons\DBTech\eCommerce\Repository\Country.php

getUntrusted('https://restcountries.eu/rest/v2/all');
is getting to
getUntrusted('http://api.countrylayer.com/v2/all?access_key=YOUR_API_KEY');

Example entry of requested api:
[{"name":"Afghanistan","topLevelDomain":[".af"],"alpha2Code":"AF","alpha3Code":"AFG","callingCodes":["93"],"capital":"Kabul","altSpellings":["AF","Af\u0121\u0101nist\u0101n"],"region":"Asia"}

The native_name do not exist any more, so I changed as well:
'native_name' => $country['native_name'],
to
'native_name' => $country['name'],

PHP:
    public function updateCountryList(): bool
    {
        $reader = $this->app()
            ->http()
            ->reader()
        ;

        $countryList = null;
       
        try
        {
            $response = $reader->getUntrusted('http://api.countrylayer.com/v2/all?access_key=YOUR_API_KEY');
            if ($response)
            {
                $jsonText = $response->getBody()->getContents();
               
                $response->getBody()->close();
               
                if ($response->getStatusCode() == 200)
                {
                    try
                    {
                        $countryList = \GuzzleHttp\json_decode($jsonText, true);
                    }
                    catch (\InvalidArgumentException $e)
                    {
                        \XF::logException($e, false, 'Security error:');
                        return false;
                    }
                }
                else
                {
                    \XF::logError(\XF::phraseDeferred('received_unexpected_response_code_x_message_y', [
                        'code' => $response->getStatusCode(),
                        'message' => $response->getReasonPhrase()
                    ]));
                    return false;
                }
            }
        }
        catch (\GuzzleHttp\Exception\RequestException $e)
        {
            \XF::logException($e, false, 'eCommerce error:');
            return false;
        }

        if (!is_array($countryList))
        {
            return false;
        }
       
        /** @var \DBTech\eCommerce\Entity\Country[]|\XF\Mvc\Entity\ArrayCollection $existingCountries */
        $existingCountries = $this->findCountriesForList()->fetch();

        $currentCountries = [];
        foreach ($countryList as $country)
        {
            if (!isset($existingCountries[$country['alpha2Code']]))
            {
                /** @var \DBTech\eCommerce\Entity\Country $newCountry */
                $newCountry = $this->em->create('DBTech\eCommerce:Country');
                $newCountry->bulkSet([
                        'country_code' => $country['alpha2Code'],
                        'name' => $country['name'],
                        'native_name' => $country['name'],
                        'iso_code' => $country['alpha3Code'],
                    ]);
                $newCountry->save();
               
                $currentCountries[$country['alpha2Code']] = $newCountry;
            }
            else
            {
                /** @var \DBTech\eCommerce\Entity\Country $newCountry */
                $newCountry = $existingCountries[$country['alpha2Code']];
               
                if ($newCountry->name != $country['name'])
                {
                    $newCountry->fastUpdate('name', $country['name']);
                }
               
                $currentCountries[$country['alpha2Code']] = $newCountry;
            }
        }
       
        $missingCountries = array_diff_key($existingCountries->toArray(), $currentCountries);
       
        /** @var \DBTech\eCommerce\Entity\Country $country */
        foreach ($missingCountries as $country)
        {
            $country->delete();
        }
       
        return true;
    }

After that run the two cron entries:

  1. DragonByte eCommerce: Update country list DragonByte eCommerce
  2. DragonByte eCommerce: Update VAT rates DragonByte eCommerce
BattleKingHat off to you dude, That fixed my issue i was about to give up but you saved the day! Thanks again for your help with this.
 

soner

Collaborate
Collaborate
Registered
Joined
Jul 28, 2021
Messages
39
Points
93

Reputation:

I did what you said, it didn't work, it's a country problem, am I missing somewhere, I wonder where these two updates are?

my version 2.3.2
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

I did what you said, it didn't work, it's a country problem, am I missing somewhere, I wonder where these two updates are?

my version 2.3.2
sonerCheck under cron jobs and execute them manually, but if you got the original code it will fail, because the URL do not exist or is not supported anymore.

I did my tests with 2.3.4 so far as I remember, but my changes should also work with your version.

If you need more help, you can sent me a login to your site via PM
 

soner

Collaborate
Collaborate
Registered
Joined
Jul 28, 2021
Messages
39
Points
93

Reputation:

now i'm migrating to php4, if not, let's deal with it together
 

soner

Collaborate
Collaborate
Registered
Joined
Jul 28, 2021
Messages
39
Points
93

Reputation:

tup.png


I found the easy way Go to phpmyadmin, search for country, it will be empty, you will say add immediately and add it according to the example in the picture

For example: name: usa native_name: usa iso_code: usd
 
Last edited:

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

View attachment 26001

I found the easy way Go to phpmyadmin, search for country, it will be empty, you will say add immediately and add it according to the example in the picture

For example: name: usa native_name: usa iso_code: usd
sonerThis is also a possible solution, but it would be much nicer to get it created automatically. But you mentioned that my solution do not work, did you created the API Key to access the new URL to receive the data ?

Thanks for your findings.
 

soner

Collaborate
Collaborate
Registered
Joined
Jul 28, 2021
Messages
39
Points
93

Reputation:

I didn't do anything else. works flawlessly
 

DarKMaSk

Active member
Registered
Joined
Apr 2, 2021
Messages
30
Points
18

Reputation:

Without a proper documentation, we are facing many issues which would be actually very simple to handle. Like this problem of adding country list. After getting the 'CountryLayer API Key', it has to be put in the designated space in DragonByte eCommerce > settings and then we have to go to cron jobs at Tools > Cron entries in Xenforo Admin Control Panel. Now we have to run 'DragonByte eCommerce: Update country list' by clicking on the 'Run Now' button (two rounded arrows) on the right hand side of the entry and we are done.
Now go to DragonByte eCommerce > Settings and look where you were looking for Countries and you will find all the countries of the world.

So no hard-coding is needed, no database entry has to be modified. Hope this will help.
 

BattleKing

Spirit of darkness
Staff member
Administrator
Moderator
+Lifetime VIP+
S.V.I.P Member
Collaborate
Registered
Joined
May 24, 2020
Messages
3,497
Points
523

Reputation:

Without a proper documentation, we are facing many issues which would be actually very simple to handle. Like this problem of adding country list. After getting the 'CountryLayer API Key', it has to be put in the designated space in DragonByte eCommerce > settings and then we have to go to cron jobs at Tools > Cron entries in Xenforo Admin Control Panel. Now we have to run 'DragonByte eCommerce: Update country list' by clicking on the 'Run Now' button (two rounded arrows) on the right hand side of the entry and we are done.
Now go to DragonByte eCommerce > Settings and look where you were looking for Countries and you will find all the countries of the world.

So no hard-coding is needed, no database entry has to be modified. Hope this will help.
DarKMaSkThis happened in 2.4.0 first
Another important change in this version is an update to support the new API for fetching the list of countries. You now require a (free) API key in order to fetch this data, added via the new setting.
with the newer version since 2.4.2 no API key is required anymore
This version updates the country fetching code to be more reliable, and no longer requires an API key. If you previously had problems fetching the country list, please run the "Update country list" cron job one more time manually, after which the list should populate itself correctly.

Furthermore, since no API key is needed, fresh installation should once again find the country list pre-populated.
 
View previous replies…
Top