AbandonedCartPayload.php
2 years ago
CustomerPayload.php
1 year ago
OrderPayload.php
1 year ago
OrderStatusChangePayload.php
3 years ago
index.php
3 years ago
AbandonedCartPayload.php
63 lines
| 1 | <?php declare(strict_types = 1); |
| 2 | |
| 3 | namespace MailPoet\Automation\Integrations\WooCommerce\Payloads; |
| 4 | |
| 5 | if (!defined('ABSPATH')) exit; |
| 6 | |
| 7 | |
| 8 | use MailPoet\Automation\Engine\Integration\Payload; |
| 9 | |
| 10 | class AbandonedCartPayload implements Payload { |
| 11 | |
| 12 | /** @var \WC_Customer */ |
| 13 | private $customer; |
| 14 | |
| 15 | /** @var \DateTimeImmutable */ |
| 16 | private $lastActivityAt; |
| 17 | |
| 18 | /** @var int[] */ |
| 19 | private $productIds; |
| 20 | |
| 21 | /** |
| 22 | * @param \WC_Customer $customer |
| 23 | * @param \DateTimeImmutable $lastActivityAt |
| 24 | * @param int[] $productIds |
| 25 | */ |
| 26 | public function __construct( |
| 27 | \WC_Customer $customer, |
| 28 | \DateTimeImmutable $lastActivityAt, |
| 29 | array $productIds |
| 30 | ) { |
| 31 | |
| 32 | $this->customer = $customer; |
| 33 | $this->lastActivityAt = $lastActivityAt; |
| 34 | $this->productIds = $productIds; |
| 35 | } |
| 36 | |
| 37 | public function getLastActivityAt(): \DateTimeImmutable { |
| 38 | return $this->lastActivityAt; |
| 39 | } |
| 40 | |
| 41 | public function getCustomer(): \WC_Customer { |
| 42 | return $this->customer; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @return int[] |
| 47 | */ |
| 48 | public function getProductIds(): array { |
| 49 | return $this->productIds; |
| 50 | } |
| 51 | |
| 52 | public function getTotal(): float { |
| 53 | $total = 0.0; |
| 54 | foreach ($this->productIds as $productId) { |
| 55 | $product = wc_get_product($productId); |
| 56 | if ($product) { |
| 57 | $total += (float)$product->get_price(); |
| 58 | } |
| 59 | } |
| 60 | return $total; |
| 61 | } |
| 62 | } |
| 63 |