1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Model; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\CustomerRepositoryInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Api\Data; |
10
|
|
|
use CommerceLeague\ActiveCampaign\Model\ResourceModel\Customer as CustomerResource; |
11
|
|
|
use Magento\Customer\Model\Customer as MagentoCustomer; |
12
|
|
|
use Magento\Framework\Exception\CouldNotDeleteException; |
13
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
14
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
15
|
|
|
use Magento\Framework\Model\AbstractModel; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class CustomerRepository |
19
|
|
|
*/ |
20
|
|
|
class CustomerRepository implements CustomerRepositoryInterface |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var CustomerResource |
24
|
|
|
*/ |
25
|
|
|
private $customerResource; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var CustomerFactory |
|
|
|
|
29
|
|
|
*/ |
30
|
|
|
private $customerFactory; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param CustomerResource $customerResource |
34
|
|
|
* @param CustomerFactory $customerFactory |
35
|
|
|
*/ |
36
|
|
|
public function __construct( |
37
|
|
|
CustomerResource $customerResource, |
38
|
|
|
CustomerFactory $customerFactory |
39
|
|
|
) { |
40
|
|
|
$this->customerResource = $customerResource; |
41
|
|
|
$this->customerFactory = $customerFactory; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param Data\CustomerInterface|AbstractModel $customer |
46
|
|
|
* @return Data\CustomerInterface |
47
|
|
|
* @throws CouldNotSaveException |
48
|
|
|
*/ |
49
|
|
|
public function save(Data\CustomerInterface $customer): Data\CustomerInterface |
50
|
|
|
{ |
51
|
|
|
try { |
52
|
|
|
$this->customerResource->save($customer); |
53
|
|
|
} catch (\Exception $e) { |
54
|
|
|
throw new CouldNotSaveException(__($e->getMessage())); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $customer; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @inheritDoc |
62
|
|
|
*/ |
63
|
|
|
public function getById($entityId): Data\CustomerInterface |
64
|
|
|
{ |
65
|
|
|
/** @var Customer $customer */ |
66
|
|
|
$customer = $this->customerFactory->create(); |
67
|
|
|
$this->customerResource->load($customer, $entityId); |
68
|
|
|
|
69
|
|
|
return $customer; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
public function getByMagentoCustomerId($magentoCustomerId): Data\CustomerInterface |
73
|
|
|
{ |
74
|
|
|
$customer = $this->customerFactory->create(); |
75
|
|
|
$this->customerResource->load( |
76
|
|
|
$customer, |
77
|
|
|
$magentoCustomerId, |
78
|
|
|
Data\CustomerInterface::MAGENTO_CUSTOMER_ID |
79
|
|
|
); |
80
|
|
|
|
81
|
|
|
return $customer; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* @inheritDoc |
86
|
|
|
*/ |
87
|
|
|
public function getOrCreateByMagentoCustomerId($magentoCustomerId): Data\CustomerInterface |
88
|
|
|
{ |
89
|
|
|
$customer = $this->getByMagentoCustomerId($magentoCustomerId); |
90
|
|
|
|
91
|
|
|
if (!$customer->getId()) { |
|
|
|
|
92
|
|
|
$customer->setMagentoCustomerId($magentoCustomerId); |
93
|
|
|
$this->save($customer); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
return $customer; |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @param Data\CustomerInterface|AbstractModel $customer |
101
|
|
|
* @return bool |
102
|
|
|
* @throws CouldNotDeleteException |
103
|
|
|
*/ |
104
|
|
|
public function delete(Data\CustomerInterface $customer): bool |
105
|
|
|
{ |
106
|
|
|
try { |
107
|
|
|
$this->customerResource->delete($customer); |
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
|
|
|
$customer = $this->getById($entityId); |
121
|
|
|
|
122
|
|
|
if (!$customer->getId()) { |
123
|
|
|
throw new NoSuchEntityException( |
124
|
|
|
__('The Customer with the "%1" ID doesn\'t exist', $entityId) |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
return $this->delete($customer); |
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