I don't think these should be either/or, because there is a common use case to have a currency selector which has the country's default currency automatically selected.

Comments

Rob230 created an issue. See original summary.

valic’s picture

That really depends on the use case.

Do you need to vary by currencies only, which are assigned to specific countries?
Or you need to vary by country, but you also have currencies per country.

I have the second case. Regardless of currencies, I am in need of varying by country.
Currency per specific country is the only an addition.

In that case, all cache tags and context is based upon user country, therefore no need for currency cookie.

Can you explain your current use case?

rob230’s picture

The two modes - "Cookie (currency block selector)" and "By Country" - are mutually exclusive. If you use "By Country" (i.e. GeoIP) then it will ignore whatever you choose with the currency selector, and vice versa.

I want to get it so that the user can choose the currency, but on their first visit to the site it will be chosen for them based on their IP address. I am not sure how I can achieve this.

The currency mapping methods are not plugins, they are hardcoded in CommerceCurrencyResolverForm::getAvailableMapping(), so I think I will have to patch the module.

rob230’s picture

This patch adds what I need. It adds an option for 'By Cookie and Country'. So if the user has chosen a currency with the currency block, it will use that. If they have not, it will use GeoIP and the detected currency will be selected in the currency block.

by cookie and country

rob230’s picture

Status: Active » Needs review
valic’s picture

Tnx,

But the use case is really specific.

You want to achieve this:

I want to get it so that the user can choose the currency, but on their first visit to the site, it will be chosen for them based on their IP address. I am not sure how I can achieve this.

So, if there is no cookie, you geolocated the user and create a cookie for that country.
(you could do that with Kernel Event I think)
Mapping for that country/currency can be done in your event.

Or if you use varnish, fastly or Cloudflare, you could set cookie based on IP even earlier prior request reaching Drupal

valic’s picture

Unfortunately, module is not robust enough to easily plug anyone's implementation.

Even declaring event on resolving currency or hook could solve that maybe ?
There will be easier for people to resolve current currency diferently

rob230’s picture

It would be good if the resolving methods were plugins, so that someone could create one in their own module and it would appear in the list on the config page as a method of currency mapping. But that would be a big piece of work to achieve.

valic’s picture

Status: Needs review » Postponed

There is a planned slightly different approach but would allow flexibility.

I have a plan for 2.x rewrite soon but also involve part of resolver which is going to the core
https://www.drupal.org/project/commerce/issues/3039854

Following that landing in the core, each resolver type (cookie, GeoIP, etc..) is going to be a separate submodule with its own resolver.

Then you will be able to enable GeoIP and cookie submodule, and the cookie is going to have bigger weight,
it will do exactly what you need

- resolve by cookie -> if there is no cookie -> proceeding to next resolver -> geoip

rob230’s picture

That would be great thank you.

vasiliyrepin’s picture

I look forward to that implementation in this module. It's often use cases. You can see to big projects: aliexpress, ebay, amazon...

valic’s picture

Related issues: +#3179459: Version 2.x
valic’s picture

Status: Postponed » Active
valic’s picture

Issue tags: +currency-resolver-2
Parent issue: » #3179459: Version 2.x
Related issues: -#3179459: Version 2.x
valic’s picture

Status: Active » Fixed

You can now use both cookie an geo resolving with new 2.0.0. version.

Note that cookie resolver is executed before geo resolver.

If there is no cookie, the next resolver would be fired is geo
You need to enable on 2.0.0. version the new submodules - cookie and geoip or smartip

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.