| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Events; |
| 4 |
|
| 5 |
use FluentCart\App\Events\EventDispatcher; |
| 6 |
use FluentCart\App\Listeners; |
| 7 |
use FluentCart\App\Models\Order; |
| 8 |
use FluentCart\App\Models\ProductVariation; |
| 9 |
|
| 10 |
class PlanChanged extends EventDispatcher |
| 11 |
{ |
| 12 |
|
| 13 |
public string $hook = 'fluent_cart/plan_changed'; |
| 14 |
protected array $listeners = []; |
| 15 |
|
| 16 |
public Order $order; |
| 17 |
public ProductVariation $newVariation; |
| 18 |
public ProductVariation $oldVariation; |
| 19 |
public array $otherInfo = []; |
| 20 |
|
| 21 |
|
| 22 |
public function __construct(Order $order, ProductVariation $newVariation, ProductVariation $oldVariation, $otherInfo = null) |
| 23 |
{ |
| 24 |
$this->order = $order; |
| 25 |
$this->newVariation = $newVariation; |
| 26 |
$this->oldVariation = $oldVariation; |
| 27 |
$this->otherInfo = is_array($otherInfo) ? $otherInfo : []; |
| 28 |
|
| 29 |
// Load necessary relationships |
| 30 |
$this->order->load('customer', 'shipping_address', 'billing_address'); |
| 31 |
} |
| 32 |
|
| 33 |
public function toArray(): array |
| 34 |
{ |
| 35 |
return [ |
| 36 |
'order' => $this->order->toArray(), |
| 37 |
'customer' => $this->order->customer ? $this->order->customer->toArray() : [], |
| 38 |
'new_variation' => $this->newVariation->toArray(), |
| 39 |
'old_variation' => $this->oldVariation->toArray(), |
| 40 |
'other_info' => $this->otherInfo |
| 41 |
]; |
| 42 |
} |
| 43 |
|
| 44 |
public function getActivityEventModel() |
| 45 |
{ |
| 46 |
return null; |
| 47 |
} |
| 48 |
|
| 49 |
public function shouldCreateActivity(): bool |
| 50 |
{ |
| 51 |
return false; |
| 52 |
} |
| 53 |
} |