PluginProbe ʕ •ᴥ•ʔ
Hostinger Reach – AI-Powered Email Marketing for WordPress / 1.7.1
Hostinger Reach – AI-Powered Email Marketing for WordPress v1.7.1
1.7.1 1.7.0 1.6.0 1.5.9 1.5.8 1.5.7 1.5.6 1.5.5 1.5.4 1.5.3 1.5.2 1.5.1 1.5.0 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 trunk 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6
hostinger-reach / src / Jobs / AbandonedCartsJob.php
hostinger-reach / src / Jobs Last commit date
AbandonedCartsJob.php 8 months ago AbstractBatchedJob.php 8 months ago AbstractJob.php 5 months ago ActionScheduler.php 8 months ago CleanupCartsJob.php 1 month ago ImportJob.php 8 months ago JobInterface.php 9 months ago RecurringJobInterface.php 9 months ago
AbandonedCartsJob.php
78 lines
1 <?php
2
3 namespace Hostinger\Reach\Jobs;
4
5 use Hostinger\Reach\Api\Handlers\ReachApiHandler;
6 use Hostinger\Reach\Api\Webhooks\Handlers\CartAbandoned;
7 use Hostinger\Reach\Models\Cart;
8 use Hostinger\Reach\Repositories\CartRepository;
9
10 class AbandonedCartsJob extends AbstractBatchedJob implements RecurringJobInterface {
11
12 public const JOB_NAME = 'abandoned_carts';
13 public const JOB_INTERVAL_SECONDS = MINUTE_IN_SECONDS * 15;
14
15 protected CartAbandoned $cart_abandoned_webhook;
16 protected CartRepository $cart_repository;
17
18 public function __construct( ActionScheduler $action_scheduler, ReachApiHandler $reach_api_handler, CartRepository $cart_repository, CartAbandoned $cart_abandoned_webhook ) {
19 parent::__construct( $action_scheduler, $reach_api_handler );
20 $this->cart_repository = $cart_repository;
21 $this->cart_abandoned_webhook = $cart_abandoned_webhook;
22 }
23
24 public function handle_create_batch_action( int $batch_number, array $args ): void {
25 if ( ! $this->cart_abandoned_webhook->is_enabled() ) {
26 $this->handle_complete( $batch_number, $args );
27
28 return;
29 }
30
31 parent::handle_create_batch_action( $batch_number, $args );
32 }
33
34 public function can_schedule_recurrent(): bool {
35 return $this->cart_abandoned_webhook->is_enabled() && count( $this->cart_repository->active_abandoned_carts( 1 ) ) && parent::can_schedule_recurrent();
36 }
37
38 protected function get_batch( int $batch_number, array $args ): array {
39 $limit = $this->get_batch_size();
40
41 return $this->cart_repository->active_abandoned_carts( $limit, array( 'hash' ) );
42 }
43
44 public function get_name(): string {
45 return self::JOB_NAME;
46 }
47
48 protected function process_items( array $args = array() ): void {
49 $items = $args['items'] ?? array();
50
51 if ( empty( $items ) ) {
52 return;
53 }
54
55 foreach ( $items as $item ) {
56 $this->cart_abandoned_webhook->send( $item['hash'] );
57 }
58 }
59
60 protected function set_items_as_processing( array $items ): void {
61 foreach ( $items as $cart ) {
62 $this->cart_repository->set_status( $cart['hash'], Cart::STATUS_PROCESSING );
63 }
64 }
65
66 public function schedule( array $args = array() ): void {
67 $this->schedule_create_batch_action( 1, $args );
68 }
69
70 public function can_schedule( array $args = array() ): bool {
71 return parent::can_schedule( $args ) && $this->cart_abandoned_webhook->is_enabled();
72 }
73
74 public function get_interval(): int {
75 return self::JOB_INTERVAL_SECONDS;
76 }
77 }
78