From 27a6b4d967d7fdf13027c298d0beb78fedb43c62 Mon Sep 17 00:00:00 2001 From: Bec Scott Date: Tue, 29 Sep 2020 15:21:44 +1000 Subject: [PATCH] Add rule processors for country and state (https://github.com/woocommerce/woocommerce-admin/pull/5203) Co-authored-by: Rebecca Scott --- .../BaseLocationCountryRuleProcessor.php | 55 +++++++++++++++++++ .../BaseLocationStateRuleProcessor.php | 55 +++++++++++++++++++ .../GetRuleProcessor.php | 4 ++ .../src/RemoteInboxNotifications/README.md | 26 +++++++++ 4 files changed, 140 insertions(+) create mode 100644 plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php create mode 100644 plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php b/plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php new file mode 100644 index 00000000000..b517810c840 --- /dev/null +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationCountryRuleProcessor.php @@ -0,0 +1,55 @@ +value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php b/plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php new file mode 100644 index 00000000000..f2f70c3c4ab --- /dev/null +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/BaseLocationStateRuleProcessor.php @@ -0,0 +1,55 @@ +value, + $rule->operation + ); + } + + /** + * Validates the rule. + * + * @param object $rule The rule to validate. + * + * @return bool Pass/fail. + */ + public function validate( $rule ) { + if ( ! isset( $rule->value ) ) { + return false; + } + + if ( ! isset( $rule->operation ) ) { + return false; + } + + return true; + } +} diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php b/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php index d46ea442c8a..d21229b7e5f 100644 --- a/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/GetRuleProcessor.php @@ -48,6 +48,10 @@ class GetRuleProcessor { return new OnboardingProfileRuleProcessor(); case 'is_ecommerce': return new IsEcommerceRuleProcessor(); + case 'base_location_country': + return new BaseLocationCountryRuleProcessor(); + case 'base_location_state': + return new BaseLocationStateRuleProcessor(); } return new FailRuleProcessor(); diff --git a/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md b/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md index fd64229a9db..c47a9fabf28 100644 --- a/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md +++ b/plugins/woocommerce-admin/src/RemoteInboxNotifications/README.md @@ -342,4 +342,30 @@ This passes when the store is on a WordPress.com site with the eCommerce plan. `value` is required. +### Base location - country +This passes when the store is located in the specified country. + +``` +{ + "type": "base_location_country", + "value": "US", + "operation": "=" +} +``` + +`value` and `operation` are both required. + +### Base location - state +This passes when the store is located in the specified state. + +``` +{ + "type": "base_location_state", + "value": "TX", + "operation": "=" +} +``` + +`value` and `operation` are both required. +