|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Attribute\Repositories\SqlStatementKeys |
|
5
|
|
|
* |
|
6
|
|
|
* NOTICE OF LICENSE |
|
7
|
|
|
* |
|
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
|
9
|
|
|
* that is available through the world-wide-web at this URL: |
|
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
|
11
|
|
|
* |
|
12
|
|
|
* PHP version 5 |
|
13
|
|
|
* |
|
14
|
|
|
* @author Tim Wagner <[email protected]> |
|
15
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
17
|
|
|
* @link https://github.com/techdivision/import-attribute |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Attribute\Repositories; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Attribute\Utils\SqlStatementKeys; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Repository class with the SQL statements to use. |
|
27
|
|
|
* |
|
28
|
|
|
* @author Tim Wagner <[email protected]> |
|
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
31
|
|
|
* @link https://github.com/techdivision/import-attribute |
|
32
|
|
|
* @link http://www.techdivision.com |
|
33
|
|
|
*/ |
|
34
|
|
|
class SqlStatementRepository extends \TechDivision\Import\Repositories\SqlStatementRepository |
|
35
|
|
|
{ |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* The SQL statements. |
|
39
|
|
|
* |
|
40
|
|
|
* @var array |
|
41
|
|
|
*/ |
|
42
|
|
|
private $statements = array( |
|
|
|
|
|
|
43
|
|
|
SqlStatementKeys::ATTRIBUTE => |
|
44
|
|
|
'SELECT * FROM eav_attribute WHERE attribute_id = :attribute_id', |
|
45
|
|
|
SqlStatementKeys::CATALOG_ATTRIBUTE => |
|
46
|
|
|
'SELECT attribute_id, |
|
47
|
|
|
frontend_input_renderer, |
|
48
|
|
|
is_global, |
|
49
|
|
|
is_visible, |
|
50
|
|
|
is_searchable, |
|
51
|
|
|
is_filterable, |
|
52
|
|
|
is_comparable, |
|
53
|
|
|
is_visible_on_front, |
|
54
|
|
|
is_html_allowed_on_front, |
|
55
|
|
|
is_used_for_price_rules, |
|
56
|
|
|
is_filterable_in_search, |
|
57
|
|
|
used_in_product_listing, |
|
58
|
|
|
used_for_sort_by, |
|
59
|
|
|
apply_to, |
|
60
|
|
|
is_visible_in_advanced_search, |
|
61
|
|
|
position, |
|
62
|
|
|
is_wysiwyg_enabled, |
|
63
|
|
|
is_used_for_promo_rules, |
|
64
|
|
|
is_required_in_admin_store, |
|
65
|
|
|
is_used_in_grid, |
|
66
|
|
|
is_visible_in_grid, |
|
67
|
|
|
is_filterable_in_grid, |
|
68
|
|
|
search_weight, |
|
69
|
|
|
additional_data |
|
70
|
|
|
FROM catalog_eav_attribute |
|
71
|
|
|
WHERE attribute_id = :attribute_id', |
|
72
|
|
|
SqlStatementKeys::ATTRIBUTE_BY_ATTRIBUTE_CODE => |
|
73
|
|
|
'SELECT * FROM eav_attribute WHERE attribute_code = :attribute_code', |
|
74
|
|
|
SqlStatementKeys::ATTRIBUTE_LABEL_BY_ATTRIBUTE_CODE_AND_STORE_ID => |
|
75
|
|
|
'SELECT t1.* |
|
76
|
|
|
FROM eav_attribute_label t1, |
|
77
|
|
|
eav_attribute t2 |
|
78
|
|
|
WHERE t2.attribute_code = :attribute_code |
|
79
|
|
|
AND t1.attribute_id = t2.attribute_id |
|
80
|
|
|
AND t1.store_id = :store_id', |
|
81
|
|
|
SqlStatementKeys::ATTRIBUTE_OPTION_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE => |
|
82
|
|
|
'SELECT t2.* |
|
83
|
|
|
FROM eav_attribute t1, |
|
84
|
|
|
eav_attribute_option t2, |
|
85
|
|
|
eav_attribute_option_value t3 |
|
86
|
|
|
WHERE t1.attribute_code = :attribute_code |
|
87
|
|
|
AND t3.store_id = :store_id |
|
88
|
|
|
AND t3.value = :value |
|
89
|
|
|
AND t2.attribute_id = t1.attribute_id |
|
90
|
|
|
AND t2.option_id = t3.option_id', |
|
91
|
|
|
SqlStatementKeys::ATTRIBUTE_OPTION_SWATCH_BY_ATTRIBUTE_CODE_AND_STORE_ID_AND_VALUE_AND_TYPE => |
|
92
|
|
|
'SELECT t3.* |
|
93
|
|
|
FROM eav_attribute t1, |
|
94
|
|
|
eav_attribute_option t2, |
|
95
|
|
|
eav_attribute_option_swatch t3 |
|
96
|
|
|
WHERE t1.attribute_code = :attribute_code |
|
97
|
|
|
AND t3.store_id = :store_id |
|
98
|
|
|
AND t3.value = :value |
|
99
|
|
|
AND t3.type = :type |
|
100
|
|
|
AND t2.attribute_id = t1.attribute_id |
|
101
|
|
|
AND t2.option_id = t3.option_id', |
|
102
|
|
|
SqlStatementKeys::ATTRIBUTE_OPTION_SWATCH_BY_OPTION_ID_AND_STORE_ID => |
|
103
|
|
|
'SELECT t1.* |
|
104
|
|
|
FROM eav_attribute_option_swatch t1 |
|
105
|
|
|
WHERE t1.store_id = :store_id |
|
106
|
|
|
AND t1.option_id = :option_id', |
|
107
|
|
|
SqlStatementKeys::CATALOG_ATTRIBUTE_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID => |
|
108
|
|
|
'SELECT t2.* |
|
109
|
|
|
FROM eav_attribute t1 |
|
110
|
|
|
INNER JOIN catalog_eav_attribute t2 |
|
111
|
|
|
WHERE t1.attribute_code = :attribute_code |
|
112
|
|
|
AND t1.entity_type_id = :entity_type_id |
|
113
|
|
|
AND t2.attribute_id = t1.attribute_id', |
|
114
|
|
|
SqlStatementKeys::ENTITY_ATTRIBUTE_BY_ATTRIBUTE_ID_AND_ATTRIBUTE_SET_ID_AND_ATTRIBUTE_GROUP_ID => |
|
115
|
|
|
'SELECT * |
|
116
|
|
|
FROM eav_entity_attribute |
|
117
|
|
|
WHERE entity_type_id = :entity_type_id |
|
118
|
|
|
AND attribute_id = :attribute_id |
|
119
|
|
|
AND attribute_set_id = :attribute_set_id |
|
120
|
|
|
AND attribute_group_id = :attribute_group_id', |
|
121
|
|
|
SqlStatementKeys::CREATE_ATTRIBUTE => |
|
122
|
|
|
'INSERT |
|
123
|
|
|
INTO eav_attribute |
|
124
|
|
|
(entity_type_id, |
|
125
|
|
|
attribute_code, |
|
126
|
|
|
attribute_model, |
|
127
|
|
|
backend_model, |
|
128
|
|
|
backend_type, |
|
129
|
|
|
backend_table, |
|
130
|
|
|
frontend_model, |
|
131
|
|
|
frontend_input, |
|
132
|
|
|
frontend_label, |
|
133
|
|
|
frontend_class, |
|
134
|
|
|
source_model, |
|
135
|
|
|
is_required, |
|
136
|
|
|
is_user_defined, |
|
137
|
|
|
default_value, |
|
138
|
|
|
is_unique, |
|
139
|
|
|
note) |
|
140
|
|
|
VALUES (:entity_type_id, |
|
141
|
|
|
:attribute_code, |
|
142
|
|
|
:attribute_model, |
|
143
|
|
|
:backend_model, |
|
144
|
|
|
:backend_type, |
|
145
|
|
|
:backend_table, |
|
146
|
|
|
:frontend_model, |
|
147
|
|
|
:frontend_input, |
|
148
|
|
|
:frontend_label, |
|
149
|
|
|
:frontend_class, |
|
150
|
|
|
:source_model, |
|
151
|
|
|
:is_required, |
|
152
|
|
|
:is_user_defined, |
|
153
|
|
|
:default_value, |
|
154
|
|
|
:is_unique, |
|
155
|
|
|
:note)', |
|
156
|
|
|
SqlStatementKeys::CREATE_ENTITY_ATTRIBUTE => |
|
157
|
|
|
'INSERT |
|
158
|
|
|
INTO eav_entity_attribute |
|
159
|
|
|
(entity_type_id, |
|
160
|
|
|
attribute_id, |
|
161
|
|
|
attribute_set_id, |
|
162
|
|
|
attribute_group_id, |
|
163
|
|
|
sort_order) |
|
164
|
|
|
VALUES (:entity_type_id, |
|
165
|
|
|
:attribute_id, |
|
166
|
|
|
:attribute_set_id, |
|
167
|
|
|
:attribute_group_id, |
|
168
|
|
|
:sort_order)', |
|
169
|
|
|
SqlStatementKeys::CREATE_ATTRIBUTE_LABEL => |
|
170
|
|
|
'INSERT |
|
171
|
|
|
INTO eav_attribute_label |
|
172
|
|
|
(attribute_id, |
|
173
|
|
|
store_id, |
|
174
|
|
|
value) |
|
175
|
|
|
VALUES (:attribute_id, |
|
176
|
|
|
:store_id, |
|
177
|
|
|
:value)', |
|
178
|
|
|
SqlStatementKeys::CREATE_ATTRIBUTE_OPTION => |
|
179
|
|
|
'INSERT |
|
180
|
|
|
INTO eav_attribute_option |
|
181
|
|
|
(attribute_id, |
|
182
|
|
|
sort_order) |
|
183
|
|
|
VALUES (:attribute_id, |
|
184
|
|
|
:sort_order)', |
|
185
|
|
|
SqlStatementKeys::CREATE_ATTRIBUTE_OPTION_VALUE => |
|
186
|
|
|
'INSERT |
|
187
|
|
|
INTO eav_attribute_option_value |
|
188
|
|
|
(option_id, |
|
189
|
|
|
store_id, |
|
190
|
|
|
value) |
|
191
|
|
|
VALUES (:option_id, |
|
192
|
|
|
:store_id, |
|
193
|
|
|
:value)', |
|
194
|
|
|
SqlStatementKeys::CREATE_ATTRIBUTE_OPTION_SWATCH => |
|
195
|
|
|
'INSERT |
|
196
|
|
|
INTO eav_attribute_option_swatch |
|
197
|
|
|
(option_id, |
|
198
|
|
|
store_id, |
|
199
|
|
|
value, |
|
200
|
|
|
type) |
|
201
|
|
|
VALUES (:option_id, |
|
202
|
|
|
:store_id, |
|
203
|
|
|
:value, |
|
204
|
|
|
:type)', |
|
205
|
|
|
SqlStatementKeys::CREATE_CATALOG_ATTRIBUTE => |
|
206
|
|
|
'INSERT INTO catalog_eav_attribute (%s) VALUES (:%s)', |
|
207
|
|
|
SqlStatementKeys::UPDATE_ATTRIBUTE => |
|
208
|
|
|
'UPDATE eav_attribute |
|
209
|
|
|
SET entity_type_id = :entity_type_id, |
|
210
|
|
|
attribute_code = :attribute_code, |
|
211
|
|
|
attribute_model = :attribute_model, |
|
212
|
|
|
backend_model = :backend_model, |
|
213
|
|
|
backend_type = :backend_type, |
|
214
|
|
|
backend_table = :backend_table, |
|
215
|
|
|
frontend_model = :frontend_model, |
|
216
|
|
|
frontend_input = :frontend_input, |
|
217
|
|
|
frontend_label = :frontend_label, |
|
218
|
|
|
frontend_class = :frontend_class, |
|
219
|
|
|
source_model = :source_model, |
|
220
|
|
|
is_required = :is_required, |
|
221
|
|
|
is_user_defined = :is_user_defined, |
|
222
|
|
|
default_value = :default_value, |
|
223
|
|
|
is_unique = :is_unique, |
|
224
|
|
|
note = :note |
|
225
|
|
|
WHERE attribute_id = :attribute_id', |
|
226
|
|
|
SqlStatementKeys::UPDATE_CATALOG_ATTRIBUTE => |
|
227
|
|
|
'UPDATE catalog_eav_attribute SET %s WHERE attribute_id = :%s', |
|
228
|
|
|
SqlStatementKeys::UPDATE_ENTITY_ATTRIBUTE => |
|
229
|
|
|
'UPDATE eav_entity_attribute |
|
230
|
|
|
SET entity_type_id = :entity_type_id, |
|
231
|
|
|
attribute_id = :attribute_id, |
|
232
|
|
|
attribute_set_id = :attribute_set_id, |
|
233
|
|
|
attribute_group_id = :attribute_group_id, |
|
234
|
|
|
sort_order = :sort_order |
|
235
|
|
|
WHERE entity_attribute_id = :entity_attribute_id', |
|
236
|
|
|
SqlStatementKeys::UPDATE_ATTRIBUTE_LABEL => |
|
237
|
|
|
'UPDATE eav_attribute_label |
|
238
|
|
|
SET attribute_id = :attribute_id, |
|
239
|
|
|
store_id = :store_id, |
|
240
|
|
|
value = :value |
|
241
|
|
|
WHERE attribute_label_id = :attribute_label_id', |
|
242
|
|
|
SqlStatementKeys::UPDATE_ATTRIBUTE_OPTION => |
|
243
|
|
|
'UPDATE eav_attribute_option |
|
244
|
|
|
SET attribute_id = :attribute_id, |
|
245
|
|
|
sort_order = :sort_order |
|
246
|
|
|
WHERE option_id = :option_id', |
|
247
|
|
|
SqlStatementKeys::UPDATE_ATTRIBUTE_OPTION_VALUE => |
|
248
|
|
|
'UPDATE eav_attribute_option_value |
|
249
|
|
|
SET option_id = :option_id, |
|
250
|
|
|
store_id = :store_id, |
|
251
|
|
|
value = :value |
|
252
|
|
|
WHERE value_id = :value_id', |
|
253
|
|
|
SqlStatementKeys::UPDATE_ATTRIBUTE_OPTION_SWATCH => |
|
254
|
|
|
'UPDATE eav_attribute_option_swatch |
|
255
|
|
|
SET option_id = :option_id, |
|
256
|
|
|
store_id = :store_id, |
|
257
|
|
|
value = :value, |
|
258
|
|
|
type = :type |
|
259
|
|
|
WHERE swatch_id = :swatch_id', |
|
260
|
|
|
SqlStatementKeys::DELETE_ATTRIBUTE => |
|
261
|
|
|
'DELETE FROM eav_attribute WHERE attribute_id = :attribute_id', |
|
262
|
|
|
SqlStatementKeys::DELETE_ENTITY_ATTRIBUTE => |
|
263
|
|
|
'DELETE FROM eav_entity_attribute WHERE entity_attribute_id = :entity_attribute_id', |
|
264
|
|
|
SqlStatementKeys::DELETE_ATTRIBUTE_LABEL => |
|
265
|
|
|
'DELETE FROM eav_attribute_label WHERE attribute_label_id = :attribute_label_id', |
|
266
|
|
|
SqlStatementKeys::DELETE_ATTRIBUTE_OPTION => |
|
267
|
|
|
'DELETE FROM eav_attribute_option WHERE option_id = :option_id', |
|
268
|
|
|
SqlStatementKeys::DELETE_ATTRIBUTE_OPTION_VALUE => |
|
269
|
|
|
'DELETE FROM eav_attribute_option_value WHERE value_id = :value_id', |
|
270
|
|
|
SqlStatementKeys::DELETE_ATTRIBUTE_OPTION_SWATCH => |
|
271
|
|
|
'DELETE FROM eav_attribute_option_swatch WHERE swatch_id = :swatch_id', |
|
272
|
|
|
SqlStatementKeys::DELETE_CATALOG_ATTRIBUTE => |
|
273
|
|
|
'DELETE FROM catalog_eav_attribute WHERE attribute_id = :attribute_id', |
|
274
|
|
|
SqlStatementKeys::DELETE_ATTRIBUTE_BY_ATTRIBUTE_CODE => |
|
275
|
|
|
'DELETE FROM eav_attribute WHERE attribute_code = :attribute_code' |
|
276
|
|
|
); |
|
277
|
|
|
|
|
278
|
|
|
/** |
|
279
|
|
|
* Initialize the the SQL statements. |
|
280
|
|
|
*/ |
|
281
|
|
|
public function __construct() |
|
282
|
|
|
{ |
|
283
|
|
|
|
|
284
|
|
|
// call the parent constructor |
|
285
|
|
|
parent::__construct(); |
|
286
|
|
|
|
|
287
|
|
|
// merge the class statements |
|
288
|
|
|
foreach ($this->statements as $key => $statement) { |
|
289
|
|
|
$this->preparedStatements[$key] = $statement; |
|
290
|
|
|
} |
|
291
|
|
|
} |
|
292
|
|
|
} |
|
293
|
|
|
|