Transformers
1 year ago
BaseLocationCountryRuleProcessor.php
2 years ago
BaseLocationStateRuleProcessor.php
2 years ago
ComparisonOperation.php
2 years ago
ContextPluginsRuleProcessor.php
1 year ago
EvaluateAndGetStatus.php
2 years ago
EvaluateOverrides.php
1 year ago
EvaluationLogger.php
1 year ago
FailRuleProcessor.php
2 years ago
GetRuleProcessor.php
2 years ago
GetRuleProcessorForContext.php
1 year ago
IsEcommerceRuleProcessor.php
2 years ago
IsWooExpressRuleProcessor.php
2 years ago
NotRuleProcessor.php
2 years ago
NoteStatusRuleProcessor.php
2 years ago
OnboardingProfileRuleProcessor.php
2 years ago
OptionRuleProcessor.php
2 years ago
OrRuleProcessor.php
2 years ago
OrderCountRuleProcessor.php
2 years ago
OrdersProvider.php
2 years ago
PassRuleProcessor.php
2 years ago
PluginVersionRuleProcessor.php
2 years ago
PluginsActivatedRuleProcessor.php
2 years ago
ProductCountRuleProcessor.php
1 year ago
PublishAfterTimeRuleProcessor.php
2 years ago
PublishBeforeTimeRuleProcessor.php
2 years ago
RuleEvaluator.php
1 year ago
RuleProcessorInterface.php
2 years ago
StoredStateRuleProcessor.php
2 years ago
StoredStateSetupForProducts.php
2 years ago
TotalPaymentsVolumeProcessor.php
1 year ago
WCAdminActiveForProvider.php
2 years ago
WCAdminActiveForRuleProcessor.php
2 years ago
WooCommerceAdminUpdatedRuleProcessor.php
2 years ago
OrderCountRuleProcessor.php
70 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Rule processor for publishing based on the number of orders. |
| 4 | */ |
| 5 | |
| 6 | namespace Automattic\WooCommerce\Admin\RemoteSpecs\RuleProcessors; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | /** |
| 11 | * Rule processor for publishing based on the number of orders. |
| 12 | */ |
| 13 | class OrderCountRuleProcessor implements RuleProcessorInterface { |
| 14 | |
| 15 | /** |
| 16 | * The orders provider. |
| 17 | * |
| 18 | * @var OrdersProvider |
| 19 | */ |
| 20 | protected $orders_provider; |
| 21 | |
| 22 | /** |
| 23 | * Constructor. |
| 24 | * |
| 25 | * @param object $orders_provider The orders provider. |
| 26 | */ |
| 27 | public function __construct( $orders_provider = null ) { |
| 28 | $this->orders_provider = null === $orders_provider |
| 29 | ? new OrdersProvider() |
| 30 | : $orders_provider; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Process the rule. |
| 35 | * |
| 36 | * @param object $rule The rule to process. |
| 37 | * @param object $stored_state Stored state. |
| 38 | * |
| 39 | * @return bool Whether the rule passes or not. |
| 40 | */ |
| 41 | public function process( $rule, $stored_state ) { |
| 42 | $count = $this->orders_provider->get_order_count(); |
| 43 | |
| 44 | return ComparisonOperation::compare( |
| 45 | $count, |
| 46 | $rule->value, |
| 47 | $rule->operation |
| 48 | ); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Validates the rule. |
| 53 | * |
| 54 | * @param object $rule The rule to validate. |
| 55 | * |
| 56 | * @return bool Pass/fail. |
| 57 | */ |
| 58 | public function validate( $rule ) { |
| 59 | if ( ! isset( $rule->value ) ) { |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | if ( ! isset( $rule->operation ) ) { |
| 64 | return false; |
| 65 | } |
| 66 | |
| 67 | return true; |
| 68 | } |
| 69 | } |
| 70 |