|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Model\ActiveCampaign; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data; |
|
9
|
|
|
use CommerceLeague\ActiveCampaign\Api\OrderRepositoryInterface; |
|
10
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\ActiveCampaign\Order as OrderResource; |
|
11
|
|
|
use Magento\Framework\Exception\CouldNotDeleteException; |
|
12
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
|
13
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
|
14
|
|
|
use Magento\Framework\Model\AbstractModel; |
|
15
|
|
|
|
|
16
|
|
|
class OrderRepository implements OrderRepositoryInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var OrderResource |
|
20
|
|
|
*/ |
|
21
|
|
|
private $orderResource; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var OrderFactory |
|
|
|
|
|
|
25
|
|
|
*/ |
|
26
|
|
|
private $orderFactory; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param OrderResource $orderResource |
|
30
|
|
|
* @param OrderFactory $orderFactory |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct( |
|
33
|
|
|
OrderResource $orderResource, |
|
34
|
|
|
OrderFactory $orderFactory |
|
35
|
|
|
) { |
|
36
|
|
|
$this->orderResource = $orderResource; |
|
37
|
|
|
$this->orderFactory = $orderFactory; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param Data\OrderInterface|AbstractModel $order |
|
42
|
|
|
* @return Data\OrderInterface |
|
43
|
|
|
* @throws CouldNotSaveException |
|
44
|
|
|
*/ |
|
45
|
|
|
public function save(Data\OrderInterface $order): Data\OrderInterface |
|
46
|
|
|
{ |
|
47
|
|
|
try { |
|
48
|
|
|
$this->orderResource->save($order); |
|
49
|
|
|
} catch (\Exception $e) { |
|
50
|
|
|
throw new CouldNotSaveException(__($e->getMessage())); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
return $order; |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @inheritDoc |
|
58
|
|
|
*/ |
|
59
|
|
|
public function getById($entityId): Data\OrderInterface |
|
60
|
|
|
{ |
|
61
|
|
|
/** @var Order $order */ |
|
62
|
|
|
$order = $this->orderFactory->create(); |
|
63
|
|
|
$this->orderResource->load($order, $entityId); |
|
64
|
|
|
|
|
65
|
|
|
return $order; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @inheritDoc |
|
70
|
|
|
*/ |
|
71
|
|
|
public function getByMagentoOrderId($magentoOrderId): Data\OrderInterface |
|
72
|
|
|
{ |
|
73
|
|
|
/** @var Order $order */ |
|
74
|
|
|
$order = $this->orderFactory->create(); |
|
75
|
|
|
$this->orderResource->load( |
|
76
|
|
|
$order, |
|
77
|
|
|
$magentoOrderId, |
|
78
|
|
|
Data\OrderInterface::MAGENTO_ORDER_ID |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
return $order; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* @inheritDoc |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getOrCreateByMagentoOrderId($magentoOrderId): Data\OrderInterface |
|
88
|
|
|
{ |
|
89
|
|
|
$order = $this->getByMagentoOrderId($magentoOrderId); |
|
90
|
|
|
|
|
91
|
|
|
if (!$order->getId()) { |
|
92
|
|
|
$order->setMagentoOrderId($magentoOrderId); |
|
93
|
|
|
$this->save($order); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
return $order; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @param Data\OrderInterface|AbstractModel $order |
|
101
|
|
|
* @return bool |
|
102
|
|
|
* @throws CouldNotDeleteException |
|
103
|
|
|
*/ |
|
104
|
|
|
public function delete(Data\OrderInterface $order): bool |
|
105
|
|
|
{ |
|
106
|
|
|
try { |
|
107
|
|
|
$this->orderResource->delete($order); |
|
108
|
|
|
} catch (\Exception $e) { |
|
109
|
|
|
throw new CouldNotDeleteException(__($e->getMessage())); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
return true; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* @inheritDoc |
|
117
|
|
|
*/ |
|
118
|
|
|
public function deleteById($entityId): bool |
|
119
|
|
|
{ |
|
120
|
|
|
$order = $this->getById($entityId); |
|
121
|
|
|
|
|
122
|
|
|
if (!$order->getId()) { |
|
123
|
|
|
throw new NoSuchEntityException( |
|
124
|
|
|
__('The Order with the "%1" ID doesn\'t exist', $entityId) |
|
125
|
|
|
); |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
return $this->delete($order); |
|
129
|
|
|
} |
|
130
|
|
|
} |
|
131
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths