PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Events / Order / OrderStatusUpdated.php

OrderStatusUpdated.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Events/Order/OrderStatusUpdated.php

96 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Events\Order;
4
5 use FluentCart\App\Events\EventDispatcher;
6 use FluentCart\App\Listeners;
7 use FluentCart\App\Models\Order;
8 use FluentCart\Framework\Support\Arr;
9
10 class OrderStatusUpdated extends EventDispatcher
11 {
12 public string $hook = 'fluent_cart/order_status_updated';
13 public bool $autoFireHook = false;
14
15 protected array $listeners = [
16 // Listeners\UpdateStock::class,
17 ];
18
19 /**
20 * @var Order $order
21 */
22 public Order $order;
23 public ?string $oldStatus;
24 public ?string $newStatus;
25 public ?bool $manageStock;
26 public array $activity = [];
27
28 public string $type;
29
30 protected $willDispatch = true;
31
32 public function __construct(Order $order, $oldStatus = null, $newStatus = null, $manageStock = true, $activity = [], $type = 'payment_status')
33 {
34 $this->order = $order;
35
36 if ($oldStatus === $newStatus) {
37 $this->willDispatch = false;
38 $this->listeners = [];
39 return;
40 }
41
42 $this->order->load('customer', 'shipping_address', 'billing_address');
43 $this->oldStatus = $oldStatus;
44 $this->newStatus = $newStatus;
45 $this->manageStock = $manageStock;
46 $this->activity = $activity;
47 $this->type = $type;
48 }
49
50 public function toArray(): array
51 {
52 return [
53 'order' => $this->order,
54 'old_status' => $this->oldStatus,
55 'new_status' => $this->newStatus,
56 'manageStock' => $this->manageStock,
57 'activity' => $this->activity,
58 ];
59 }
60
61 public function getActivityEventModel()
62 {
63 return $this->order;
64 }
65
66 public function getEventInfoForActivity(): array
67 {
68 return [
69 'title' => Arr::get($this->activity, 'title', ''),
70 'content' => Arr::get($this->activity, 'content', '')
71 ];
72 }
73
74 public function afterDispatch()
75 {
76 if (!$this->willDispatch) {
77 return;
78 }
79
80 if ($this->type === 'payment_status') {
81 do_action('fluent_cart/payment_status_changed_to_'.$this->newStatus, $this->toArray());
82 do_action('fluent_cart/payment_status_changed', $this->toArray());
83 }
84
85 if ($this->type === 'shipping_status') {
86 do_action('fluent_cart/shipping_status_changed_to_' . $this->newStatus, $this->toArray());
87 do_action('fluent_cart/shipping_status_changed', $this->toArray());
88 }
89
90 if ($this->type === 'order_status') {
91 do_action('fluent_cart/order_status_changed_to_' . $this->newStatus, $this->toArray());
92 do_action('fluent_cart/order_status_changed', $this->toArray());
93 }
94 }
95 }
96