1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Customer\Address\Repositories\CustomerAddressRepository |
5
|
|
|
* |
6
|
|
|
* PHP version 7 |
7
|
|
|
* |
8
|
|
|
* @author Tim Wagner <[email protected]> |
9
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
10
|
|
|
* @license https://opensource.org/licenses/MIT |
11
|
|
|
* @link https://github.com/techdivision/import-customer-address |
12
|
|
|
* @link http://www.techdivision.com |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Customer\Address\Repositories; |
16
|
|
|
|
17
|
|
|
use TechDivision\Import\Customer\Address\Utils\MemberNames; |
18
|
|
|
use TechDivision\Import\Customer\Address\Utils\SqlStatementKeys; |
19
|
|
|
use TechDivision\Import\Dbal\Collection\Repositories\AbstractRepository; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Repository implementation to load customer address data. |
23
|
|
|
* |
24
|
|
|
* @author Tim Wagner <[email protected]> |
25
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
26
|
|
|
* @license https://opensource.org/licenses/MIT |
27
|
|
|
* @link https://github.com/techdivision/import-customer-address |
28
|
|
|
* @link http://www.techdivision.com |
29
|
|
|
*/ |
30
|
|
|
class CustomerAddressRepository extends AbstractRepository implements CustomerAddressRepositoryInterface |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The prepared statement to load a customer address with the passed entity ID. |
35
|
|
|
* |
36
|
|
|
* @var \PDOStatement |
37
|
|
|
*/ |
38
|
|
|
protected $customerAddressStmt; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* The prepared statement to load the existing customer addresses. |
42
|
|
|
* |
43
|
|
|
* @var \PDOStatement |
44
|
|
|
*/ |
45
|
|
|
protected $customerAddressesStmt; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* The prepared statement to load a customer address with the passed increment ID. |
49
|
|
|
* |
50
|
|
|
* @var \PDOStatement |
51
|
|
|
*/ |
52
|
|
|
protected $customerAddressIncrementIdStmt; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var PDOStatement |
|
|
|
|
56
|
|
|
*/ |
57
|
|
|
protected $directoryCountryRegionsStatement; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Initializes the repository's prepared statements. |
61
|
|
|
* |
62
|
|
|
* @return void |
63
|
|
|
*/ |
64
|
|
|
public function init() |
65
|
|
|
{ |
66
|
|
|
|
67
|
|
|
// initialize the prepared statements |
68
|
|
|
$this->customerAddressStmt = |
69
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESS)); |
70
|
|
|
$this->customerAddressesStmt = |
71
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESSES)); |
72
|
|
|
$this->customerAddressIncrementIdStmt = |
73
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::CUSTOMER_ADDRESS_INCREMENT_ID)); |
74
|
|
|
$this->directoryCountryRegionsStatement = |
75
|
|
|
$this->getConnection()->prepare($this->loadStatement(SqlStatementKeys::SELECT_DIRECTORY_COUNTRY_REGION)); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Return's the available customer addresses. |
80
|
|
|
* |
81
|
|
|
* @return array The available customer addresses |
82
|
|
|
*/ |
83
|
|
|
public function findAll() |
84
|
|
|
{ |
85
|
|
|
// load and return the available customers |
86
|
|
|
$this->customerAddressesStmt->execute(); |
87
|
|
|
return $this->customerAddressesStmt->fetchAll(\PDO::FETCH_ASSOC); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Return's the customer address with the passed entity ID. |
92
|
|
|
* |
93
|
|
|
* @param integer $id The entity ID of the customer address to return |
94
|
|
|
* |
95
|
|
|
* @return array|null The customer |
96
|
|
|
*/ |
97
|
|
|
public function load($id) |
98
|
|
|
{ |
99
|
|
|
|
100
|
|
|
// if not, try to load the customer with the passed entity ID |
101
|
|
|
$this->customerAddressStmt->execute(array(MemberNames::ENTITY_ID => $id)); |
102
|
|
|
return $this->customerAddressStmt->fetch(\PDO::FETCH_ASSOC); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Return's the customer address with the passed increment ID. |
107
|
|
|
* |
108
|
|
|
* @param string|integer $incrementId The increment ID of the customer address to return |
109
|
|
|
* @param string|integer $customerId The entity_id of the customer |
110
|
|
|
* |
111
|
|
|
* @return array|null The customer |
112
|
|
|
*/ |
113
|
|
|
public function loadByIncrementIdAndCustomerEntityId($incrementId, $customerId) |
114
|
|
|
{ |
115
|
|
|
// if not, try to load the customer with the passed Increment ID |
116
|
|
|
$this->customerAddressIncrementIdStmt->execute( |
117
|
|
|
array( |
118
|
|
|
MemberNames::INCREMENT_ID => $incrementId, |
119
|
|
|
MemberNames::PARENT_ID => $customerId |
120
|
|
|
) |
121
|
|
|
); |
122
|
|
|
return $this->customerAddressIncrementIdStmt->fetch(\PDO::FETCH_ASSOC); |
123
|
|
|
} |
124
|
|
|
/** |
125
|
|
|
* Return's all country regions from directory |
126
|
|
|
* |
127
|
|
|
* @return array |
128
|
|
|
*/ |
129
|
|
|
public function findDirectoryCountryRegions() |
130
|
|
|
{ |
131
|
|
|
$directoryCountryRegions = []; |
132
|
|
|
|
133
|
|
|
// execute the prepared statement |
134
|
|
|
$this->directoryCountryRegionsStatement->execute(); |
135
|
|
|
|
136
|
|
|
// load the available customer groups |
137
|
|
|
$avalaibleDirectoryCountryRegions = $this->directoryCountryRegionsStatement->fetchAll(); |
138
|
|
|
|
139
|
|
|
// fetch the directory regions and assemble them as array with the codes as key |
140
|
|
|
foreach ($avalaibleDirectoryCountryRegions as $countryRegion) { |
141
|
|
|
$directoryCountryRegions[$countryRegion[MemberNames::DIRECTORY_REGION_CODE]] = $countryRegion; |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
// return the customer groups |
145
|
|
|
return $directoryCountryRegions; |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
|