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
OrderPayload.php
61 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 | use WC_Order_Item_Product; |
| 10 | use WC_Product; |
| 11 | |
| 12 | class OrderPayload implements Payload { |
| 13 | |
| 14 | /** @var \WC_Order */ |
| 15 | private $order; |
| 16 | |
| 17 | public function __construct( |
| 18 | \WC_Order $order |
| 19 | ) { |
| 20 | $this->order = $order; |
| 21 | } |
| 22 | |
| 23 | public function getOrder(): \WC_Order { |
| 24 | return $this->order; |
| 25 | } |
| 26 | |
| 27 | public function getEmail(): string { |
| 28 | return $this->order->get_billing_email(); |
| 29 | } |
| 30 | |
| 31 | public function getId(): int { |
| 32 | return $this->order->get_id(); |
| 33 | } |
| 34 | |
| 35 | public function getProductIds(): array { |
| 36 | $productIds = []; |
| 37 | foreach ($this->order->get_items() as $item) { |
| 38 | if (!$item instanceof WC_Order_Item_Product) { |
| 39 | continue; |
| 40 | } |
| 41 | $productIds[] = $item->get_product_id(); |
| 42 | } |
| 43 | return array_unique($productIds); |
| 44 | } |
| 45 | |
| 46 | public function getCrossSellIds(): array { |
| 47 | $crossSellIds = []; |
| 48 | foreach ($this->order->get_items() as $item) { |
| 49 | if (!$item instanceof WC_Order_Item_Product) { |
| 50 | continue; |
| 51 | } |
| 52 | $product = $item->get_product(); |
| 53 | if (!$product instanceof WC_Product) { |
| 54 | continue; |
| 55 | } |
| 56 | $crossSellIds = array_merge($crossSellIds, $product->get_cross_sell_ids()); |
| 57 | } |
| 58 | return array_unique($crossSellIds); |
| 59 | } |
| 60 | } |
| 61 |