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().

Command icon 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

c_archer created an issue. See original summary.

valic’s picture

Title: Geo location based alerts » Restrict promo bars by country
Version: 1.0.1 » 1.0.x-dev
Issue summary: View changes

Update task requirements

valic’s picture

Status: Active » Fixed

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

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

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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