Add remote inbox notifications contains comparison and fix product count rule (https://github.com/woocommerce/woocommerce-admin/pull/6073)

* add remote inbox notifications contains comparison and fix product count rule

* Use stored state instead of another option

* Add change log to readme

* add new_product_count to remote inbox notifications documentation

* ensure new_product_count exists
This commit is contained in:
Bec Scott 2021-01-19 17:14:51 +10:00 committed by GitHub
parent 35a448a8f3
commit 0fd35e9a35
5 changed files with 49 additions and 2 deletions

View File

@ -75,6 +75,7 @@ Release and roadmap notes are available on the [WooCommerce Developers Blog](htt
- Fix: allow for more terms to be shown for product attributes in the Analytics orders report. #5868
- Tweak: update the content and timing of the NeedSomeInspiration note. #6076
- Add: Remote inbox notifications contains comparison and fix product rule. #6073
== Changelog ==

View File

@ -32,6 +32,10 @@ class ComparisonOperation {
return $left_operand >= $right_operand;
case '!=':
return $left_operand !== $right_operand;
case 'contains':
return in_array( $right_operand, $left_operand, true );
case '!contains':
return ! in_array( $right_operand, $left_operand, true );
}
return false;

View File

@ -40,8 +40,11 @@ class ProductCountRuleProcessor implements RuleProcessorInterface {
* @return bool The result of the operation.
*/
public function process( $rule, $stored_state ) {
$products = $this->product_query->get_products();
$count = $products->total;
$products = $this->product_query->get_products();
$new_product_count = property_exists( $stored_state, 'new_product_count' )
? $stored_state->new_product_count
: 0;
$count = $products->total + $new_product_count;
return ComparisonOperation::compare(
$count,

View File

@ -128,6 +128,34 @@ The `status` is what the status of the created note will be set to after interac
## Rule
Rules in an array are executed as an AND operation. If there are no rules in the array the result is false and the specified notification is not shown.
### Operations
Some rule types support an `operation` value, which is used to compare two
values. The following operations are implemented:
- `=`
- `<`
- `<=`
- `>`
- `>=`
- `!=`
- `contains`
- `!contains`
`contains` and `!contains` allow checking if the provided value is present (or
not present) in the haystack value. An example of this is using the
`onboarding_profile` rule to match on a value in the `product_types` array -
this rule matches if `physical` was selected as a product type in the
onboarding profile:
```json
{
'type': 'onboarding_profile',
'index': 'product_types',
'operation': 'contains',
'value': 'physical'
}
```
### Plugins activated
This passes if all of the listed plugins are installed and activated.
@ -265,6 +293,7 @@ The currently available indices are:
```
there_were_no_products
there_are_now_products
new_product_count
```
`index`, `operation`, and `value` are required.

View File

@ -95,8 +95,18 @@ class StoredStateSetupForProducts {
$stored_state = RemoteInboxNotificationsEngine::get_stored_state();
$stored_state->there_are_now_products = true;
// This is used to increment the product count yielded by the query,
// which is one less than the actual product count at this point in the
// product publish lifecycle. This is currently being used by
// ProductCountRuleProcessor.
$stored_state->new_product_count = 1;
RemoteInboxNotificationsEngine::update_stored_state( $stored_state );
RemoteInboxNotificationsEngine::run();
$stored_state->new_product_count = 0;
RemoteInboxNotificationsEngine::update_stored_state( $stored_state );
}
}