Problem/Motivation
Promo bars often target a single market, such as free shipping thresholds, a local sale, or a delivery promise. Today, limiting a bar to a market means one store per market, or custom code in a FilterPromoBarsEvent subscriber.
Proposed resolution
Use Commerce's own country resolution instead of a dependency on Smart IP or GeoIP. commerce.current_country goes through commerce.country_resolver services, so a site can resolve the country from a CDN header, GeoIP, a cookie or the customer's profile. It falls back to the site's default country.
- Add a countries base field: address_country, unlimited cardinality, not translatable, with the address_country_default widget. address is already a Commerce dependency.
- Add a country_visibility base field: a boolean with the labels "Show for the listed countries" and "Hide for the listed countries", the same pattern as pages/visibility.
- Filter in PromoBarStorage::loadAvailable() against commerce.current_country. An empty countries value means available everywhere. Filter before FilterPromoBarsEvent is dispatched, so subscribers only see bars that are available.
- Add the country cache context to PromoBarBlock.
- Add an update hook that installs both field storage definitions.
Remaining tasks
- MR
- Kernel tests: no countries, show-listed, hide-listed, and a country resolver that returns a different country
User interface changes
The promo bar form gets two new fields, Countries and Country visibility.
API changes
- New getters: PromoBarInterface::getCountries(): array and isCountryVisibility(): bool
- The storage service gets commerce.current_country injected in createInstance(). The loadAvailable() signature is unchanged.
Data model changes
Two new base fields, countries and country_visibility, installed by commerce_promo_bar_update_10002().
Issue fork commerce_promo_bar-3455406
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
valicUpdate task requirements
Comment #4
valic