|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Customer\Utils\SqlStatements |
|
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 |
|
12
|
|
|
* @link http://www.techdivision.com |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace TechDivision\Import\Customer\Repositories; |
|
16
|
|
|
|
|
17
|
|
|
use TechDivision\Import\Customer\Utils\SqlStatementKeys; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Repository class with the SQL statements to use. |
|
21
|
|
|
* |
|
22
|
|
|
* @author Tim Wagner <[email protected]> |
|
23
|
|
|
* @copyright 2018 TechDivision GmbH <[email protected]> |
|
24
|
|
|
* @license https://opensource.org/licenses/MIT |
|
25
|
|
|
* @link https://github.com/techdivision/import-customer |
|
26
|
|
|
* @link http://www.techdivision.com |
|
27
|
|
|
*/ |
|
28
|
|
|
class SqlStatementRepository extends \TechDivision\Import\Repositories\SqlStatementRepository |
|
29
|
|
|
{ |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The SQL statements. |
|
33
|
|
|
* |
|
34
|
|
|
* @var array |
|
35
|
|
|
*/ |
|
36
|
|
|
private $statements = array( |
|
37
|
|
|
SqlStatementKeys::CUSTOMER => |
|
38
|
|
|
'SELECT * |
|
39
|
|
|
FROM ${table:customer_entity} |
|
40
|
|
|
WHERE entity_id = :entity_id', |
|
41
|
|
|
SqlStatementKeys::CUSTOMER_BY_EMAIL_AND_WEBSITE_ID => |
|
42
|
|
|
'SELECT * |
|
43
|
|
|
FROM ${table:customer_entity} |
|
44
|
|
|
WHERE email = :email |
|
45
|
|
|
AND website_id = :website_id', |
|
46
|
|
|
SqlStatementKeys::CUSTOMER_BY_WEBSITE_ID_AND_INCREMET_ID => |
|
47
|
|
|
'SELECT * |
|
48
|
|
|
FROM ${table:customer_entity} |
|
49
|
|
|
WHERE website_id = :website_id |
|
50
|
|
|
AND increment_id = :increment_id', |
|
51
|
|
|
SqlStatementKeys::CUSTOMERS => |
|
52
|
|
|
'SELECT * |
|
53
|
|
|
FROM ${table:customer_entity}', |
|
54
|
|
|
SqlStatementKeys::CUSTOMER_DATETIMES => |
|
55
|
|
|
'SELECT * |
|
56
|
|
|
FROM ${table:customer_entity_datetime} |
|
57
|
|
|
WHERE entity_id = :entity_id', |
|
58
|
|
|
SqlStatementKeys::CUSTOMER_DECIMALS => |
|
59
|
|
|
'SELECT * |
|
60
|
|
|
FROM ${table:customer_entity_decimal} |
|
61
|
|
|
WHERE entity_id = :entity_id', |
|
62
|
|
|
SqlStatementKeys::CUSTOMER_INTS => |
|
63
|
|
|
'SELECT * |
|
64
|
|
|
FROM ${table:customer_entity_int} |
|
65
|
|
|
WHERE entity_id = :entity_id', |
|
66
|
|
|
SqlStatementKeys::CUSTOMER_TEXTS => |
|
67
|
|
|
'SELECT * |
|
68
|
|
|
FROM ${table:customer_entity_text} |
|
69
|
|
|
WHERE entity_id = :entity_id', |
|
70
|
|
|
SqlStatementKeys::CUSTOMER_VARCHARS => |
|
71
|
|
|
'SELECT * |
|
72
|
|
|
FROM ${table:customer_entity_varchar} |
|
73
|
|
|
WHERE entity_id = :entity_id', |
|
74
|
|
|
SqlStatementKeys::CUSTOMER_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_VALUE => |
|
75
|
|
|
'SELECT t1.* |
|
76
|
|
|
FROM ${table:customer_entity_varchar} t1, |
|
77
|
|
|
${table:eav_attribute} t2 |
|
78
|
|
|
WHERE t2.attribute_code = :attribute_code |
|
79
|
|
|
AND t2.entity_type_id = :entity_type_id |
|
80
|
|
|
AND t1.attribute_id = t2.attribute_id |
|
81
|
|
|
AND t1.value = :value', |
|
82
|
|
|
SqlStatementKeys::CREATE_CUSTOMER => |
|
83
|
|
|
'INSERT |
|
84
|
|
|
INTO ${table:customer_entity} |
|
85
|
|
|
(${column-names:customer_entity}) |
|
86
|
|
|
VALUES (${column-placeholders:customer_entity})', |
|
87
|
|
|
SqlStatementKeys::UPDATE_CUSTOMER => |
|
88
|
|
|
'UPDATE ${table:customer_entity} |
|
89
|
|
|
SET ${column-values:customer_entity} |
|
90
|
|
|
WHERE entity_id = :entity_id', |
|
91
|
|
|
SqlStatementKeys::DELETE_CUSTOMER => |
|
92
|
|
|
'DELETE |
|
93
|
|
|
FROM ${table:customer_entity} |
|
94
|
|
|
WHERE website_id = :website_id |
|
95
|
|
|
AND email = :email', |
|
96
|
|
|
SqlStatementKeys::CREATE_CUSTOMER_DATETIME => |
|
97
|
|
|
'INSERT |
|
98
|
|
|
INTO ${table:customer_entity_datetime} |
|
99
|
|
|
(entity_id, |
|
100
|
|
|
attribute_id, |
|
101
|
|
|
value) |
|
102
|
|
|
VALUES (:entity_id, |
|
103
|
|
|
:attribute_id, |
|
104
|
|
|
:value)', |
|
105
|
|
|
SqlStatementKeys::UPDATE_CUSTOMER_DATETIME => |
|
106
|
|
|
'UPDATE ${table:customer_entity_datetime} |
|
107
|
|
|
SET entity_id = :entity_id, |
|
108
|
|
|
attribute_id = :attribute_id, |
|
109
|
|
|
value = :value |
|
110
|
|
|
WHERE value_id = :value_id', |
|
111
|
|
|
SqlStatementKeys::DELETE_CUSTOMER_DATETIME => |
|
112
|
|
|
'DELETE |
|
113
|
|
|
FROM ${table:customer_entity_datetime} |
|
114
|
|
|
WHERE value_id = :value_id', |
|
115
|
|
|
SqlStatementKeys::CREATE_CUSTOMER_DECIMAL => |
|
116
|
|
|
'INSERT |
|
117
|
|
|
INTO ${table:customer_entity_decimal} |
|
118
|
|
|
(entity_id, |
|
119
|
|
|
attribute_id, |
|
120
|
|
|
value) |
|
121
|
|
|
VALUES (:entity_id, |
|
122
|
|
|
:attribute_id, |
|
123
|
|
|
:value)', |
|
124
|
|
|
SqlStatementKeys::UPDATE_CUSTOMER_DECIMAL => |
|
125
|
|
|
'UPDATE ${table:customer_entity_decimal} |
|
126
|
|
|
SET entity_id = :entity_id, |
|
127
|
|
|
attribute_id = :attribute_id, |
|
128
|
|
|
value = :value |
|
129
|
|
|
WHERE value_id = :value_id', |
|
130
|
|
|
SqlStatementKeys::DELETE_CUSTOMER_DECIMAL => |
|
131
|
|
|
'DELETE |
|
132
|
|
|
FROM ${table:customer_entity_decimal} |
|
133
|
|
|
WHERE value_id = :value_id', |
|
134
|
|
|
SqlStatementKeys::CREATE_CUSTOMER_INT => |
|
135
|
|
|
'INSERT |
|
136
|
|
|
INTO ${table:customer_entity_int} |
|
137
|
|
|
(entity_id, |
|
138
|
|
|
attribute_id, |
|
139
|
|
|
value) |
|
140
|
|
|
VALUES (:entity_id, |
|
141
|
|
|
:attribute_id, |
|
142
|
|
|
:value)', |
|
143
|
|
|
SqlStatementKeys::UPDATE_CUSTOMER_INT => |
|
144
|
|
|
'UPDATE ${table:customer_entity_int} |
|
145
|
|
|
SET entity_id = :entity_id, |
|
146
|
|
|
attribute_id = :attribute_id, |
|
147
|
|
|
value = :value |
|
148
|
|
|
WHERE value_id = :value_id', |
|
149
|
|
|
SqlStatementKeys::DELETE_CUSTOMER_INT => |
|
150
|
|
|
'DELETE |
|
151
|
|
|
FROM ${table:customer_entity_int} |
|
152
|
|
|
WHERE value_id = :value_id', |
|
153
|
|
|
SqlStatementKeys::CREATE_CUSTOMER_VARCHAR => |
|
154
|
|
|
'INSERT |
|
155
|
|
|
INTO ${table:customer_entity_varchar} |
|
156
|
|
|
(entity_id, |
|
157
|
|
|
attribute_id, |
|
158
|
|
|
value) |
|
159
|
|
|
VALUES (:entity_id, |
|
160
|
|
|
:attribute_id, |
|
161
|
|
|
:value)', |
|
162
|
|
|
SqlStatementKeys::UPDATE_CUSTOMER_VARCHAR => |
|
163
|
|
|
'UPDATE ${table:customer_entity_varchar} |
|
164
|
|
|
SET entity_id = :entity_id, |
|
165
|
|
|
attribute_id = :attribute_id, |
|
166
|
|
|
value = :value |
|
167
|
|
|
WHERE value_id = :value_id', |
|
168
|
|
|
SqlStatementKeys::DELETE_CUSTOMER_VARCHAR => |
|
169
|
|
|
'DELETE |
|
170
|
|
|
FROM ${table:customer_entity_varchar} |
|
171
|
|
|
WHERE value_id = :value_id', |
|
172
|
|
|
SqlStatementKeys::CREATE_CUSTOMER_TEXT => |
|
173
|
|
|
'INSERT |
|
174
|
|
|
INTO ${table:customer_entity_text} |
|
175
|
|
|
(entity_id, |
|
176
|
|
|
attribute_id, |
|
177
|
|
|
value) |
|
178
|
|
|
VALUES (:entity_id, |
|
179
|
|
|
:attribute_id, |
|
180
|
|
|
:value)', |
|
181
|
|
|
SqlStatementKeys::UPDATE_CUSTOMER_TEXT => |
|
182
|
|
|
'UPDATE ${table:customer_entity_text} |
|
183
|
|
|
SET entity_id = :entity_id, |
|
184
|
|
|
attribute_id = :attribute_id, |
|
185
|
|
|
value = :value |
|
186
|
|
|
WHERE value_id = :value_id', |
|
187
|
|
|
SqlStatementKeys::DELETE_CUSTOMER_TEXT => |
|
188
|
|
|
'DELETE |
|
189
|
|
|
FROM ${table:customer_entity_text} |
|
190
|
|
|
WHERE value_id = :value_id', |
|
191
|
|
|
SqlStatementKeys::SELECT_DIRECTORY_COUNTRY_REGIONS => |
|
192
|
|
|
'SELECT * |
|
193
|
|
|
FROM ${table:directory_country_region}', |
|
194
|
|
|
); |
|
195
|
|
|
|
|
196
|
|
|
/** |
|
197
|
|
|
* Initializes the SQL statement repository with the primary key and table prefix utility. |
|
198
|
|
|
* |
|
199
|
|
|
* @param \IteratorAggregate<\TechDivision\Import\Dbal\Utils\SqlCompilerInterface> $compilers The array with the compiler instances |
|
200
|
|
|
*/ |
|
201
|
|
|
public function __construct(\IteratorAggregate $compilers) |
|
202
|
|
|
{ |
|
203
|
|
|
|
|
204
|
|
|
// pass primary key + table prefix utility to parent instance |
|
205
|
|
|
parent::__construct($compilers); |
|
206
|
|
|
|
|
207
|
|
|
// compile the SQL statements |
|
208
|
|
|
$this->compile($this->statements); |
|
209
|
|
|
} |
|
210
|
|
|
} |
|
211
|
|
|
|