woocommerce
/
packages
/
woocommerce-admin
/
src
/
RemoteInboxNotifications
/
ProductCountRuleProcessor.php
BaseLocationCountryRuleProcessor.php
5 years ago
BaseLocationStateRuleProcessor.php
5 years ago
ComparisonOperation.php
5 years ago
DataSourcePoller.php
5 years ago
EvaluateAndGetStatus.php
5 years ago
FailRuleProcessor.php
5 years ago
GetRuleProcessor.php
5 years ago
IsEcommerceRuleProcessor.php
5 years ago
NotRuleProcessor.php
5 years ago
NoteStatusRuleProcessor.php
5 years ago
OnboardingProfileRuleProcessor.php
5 years ago
OptionRuleProcessor.php
5 years ago
OrRuleProcessor.php
5 years ago
OrderCountRuleProcessor.php
5 years ago
OrdersProvider.php
5 years ago
PassRuleProcessor.php
5 years ago
PluginVersionRuleProcessor.php
5 years ago
PluginsActivatedRuleProcessor.php
5 years ago
ProductCountRuleProcessor.php
5 years ago
PublishAfterTimeRuleProcessor.php
5 years ago
PublishBeforeTimeRuleProcessor.php
5 years ago
RemoteInboxNotificationsEngine.php
5 years ago
RuleEvaluator.php
5 years ago
RuleProcessorInterface.php
5 years ago
SpecRunner.php
5 years ago
StoredStateRuleProcessor.php
5 years ago
StoredStateSetupForProducts.php
5 years ago
WCAdminActiveForProvider.php
5 years ago
WCAdminActiveForRuleProcessor.php
5 years ago
ProductCountRuleProcessor.php
72 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor that performs a comparison operation against the number of |
| 4 | * products. |
| 5 | */ |
| 6 | |
| 7 | namespace Automattic\WooCommerce\Admin\RemoteInboxNotifications; |
| 8 | |
| 9 | defined( 'ABSPATH' ) || exit; |
| 10 | |
| 11 | /** |
| 12 | * Rule processor that performs a comparison operation against the number of |
| 13 | * products. |
| 14 | */ |
| 15 | class ProductCountRuleProcessor implements RuleProcessorInterface { |
| 16 | /** |
| 17 | * Constructor. |
| 18 | * |
| 19 | * @param object $product_query The product query. |
| 20 | */ |
| 21 | public function __construct( $product_query = null ) { |
| 22 | $this->product_query = null === $product_query |
| 23 | ? new \WC_Product_Query( |
| 24 | array( |
| 25 | 'limit' => 1, |
| 26 | 'paginate' => true, |
| 27 | 'return' => 'ids', |
| 28 | 'status' => array( 'publish' ), |
| 29 | ) |
| 30 | ) |
| 31 | : $product_query; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Performs a comparison operation against the number of products. |
| 36 | * |
| 37 | * @param object $rule The specific rule being processed by this rule processor. |
| 38 | * @param object $stored_state Stored state. |
| 39 | * |
| 40 | * @return bool The result of the operation. |
| 41 | */ |
| 42 | public function process( $rule, $stored_state ) { |
| 43 | $products = $this->product_query->get_products(); |
| 44 | $count = $products->total; |
| 45 | |
| 46 | return ComparisonOperation::compare( |
| 47 | $count, |
| 48 | $rule->value, |
| 49 | $rule->operation |
| 50 | ); |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Validates the rule. |
| 55 | * |
| 56 | * @param object $rule The rule to validate. |
| 57 | * |
| 58 | * @return bool Pass/fail. |
| 59 | */ |
| 60 | public function validate( $rule ) { |
| 61 | if ( ! isset( $rule->value ) ) { |
| 62 | return false; |
| 63 | } |
| 64 | |
| 65 | if ( ! isset( $rule->operation ) ) { |
| 66 | return false; |
| 67 | } |
| 68 | |
| 69 | return true; |
| 70 | } |
| 71 | } |
| 72 |