Closed (fixed)
Project:
Commerce Currency Resolver
Version:
8.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
28 Jan 2020 at 11:22 UTC
Updated:
7 Oct 2025 at 14:49 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
valicThat 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?
Comment #3
rob230 commentedThe 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.Comment #4
rob230 commentedThis 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.
Comment #5
rob230 commentedComment #6
valicTnx,
But the use case is really specific.
You want to 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
Comment #7
valicUnfortunately, 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
Comment #8
rob230 commentedIt 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.
Comment #9
valicThere 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
Comment #10
rob230 commentedThat would be great thank you.
Comment #11
vasiliyrepin commentedI look forward to that implementation in this module. It's often use cases. You can see to big projects: aliexpress, ebay, amazon...
Comment #12
valicComment #13
valicComment #14
valicComment #15
valicYou 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