Completed
Pull Request — master (#99)
by Tim
02:25
created

SqlStatements::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 5
cts 5
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Utils\SqlStatements
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-product
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Utils;
22
23
/**
24
 * Utility class with the SQL statements to use.
25
 *
26
 * @author    Tim Wagner <[email protected]>
27
 * @copyright 2016 TechDivision GmbH <[email protected]>
28
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
29
 * @link      https://github.com/techdivision/import-product
30
 * @link      http://www.techdivision.com
31
 */
32
class SqlStatements extends \TechDivision\Import\Utils\SqlStatements
33
{
34
35
    /**
36
     * The SQL statement to load the product with the passed SKU.
37
     *
38
     * @var string
39
     */
40
    const PRODUCT = 'product';
41
42
    /**
43
     * The SQL statement to load the product website relations with the passed product/website ID.
44
     *
45
     * @var string
46
     */
47
    const PRODUCT_WEBSITE = 'product_website';
48
49
    /**
50
     * The SQL statement to load the product datetime attribute with the passed entity/attribute/store ID.
51
     *
52
     * @var string
53
     */
54
    const PRODUCT_DATETIME = 'product_datetime';
55
56
    /**
57
     * The SQL statement to load the product decimal attribute with the passed entity/attribute/store ID.
58
     *
59
     * @var string
60
     */
61
    const PRODUCT_DECIMAL = 'product_decimal';
62
63
    /**
64
     * The SQL statement to load the product integer attribute with the passed entity/attribute/store ID.
65
     *
66
     * @var string
67
     */
68
    const PRODUCT_INT = 'product_int';
69
70
    /**
71
     * The SQL statement to load the product text attribute with the passed entity/attribute/store ID.
72
     *
73
     * @var string
74
     */
75
    const PRODUCT_TEXT = 'product_text';
76
77
    /**
78
     * The SQL statement to load the product varchar attribute with the passed entity/attribute/store ID.
79
     *
80
     * @var string
81
     */
82
    const PRODUCT_VARCHAR = 'product_varchar';
83
84
    /**
85
     * The SQL statement to load a product varchar attribute by the passed attribute code,
86
     * entity typy and store ID as well as the passed value.
87
     *
88
     * @var string
89
     */
90
    const PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID_AND_VALUE = 'product_varchar.by.attribute_code.and.entity_type_id.and.store_id.and.value';
91
92
    /**
93
     * The SQL statement to load the category product relations with the passed product/website ID.
94
     *
95
     * @var string
96
     */
97
    const CATEGORY_PRODUCT = 'category_product';
98
99
    /**
100
     * The SQL statement to load the category product relations with the passed product SKU.
101
     *
102
     * @var string
103
     */
104
    const CATEGORY_PRODUCT_BY_SKU = 'category_product.by.sku';
105
106
    /**
107
     * The SQL statement to load the stock status with the passed product/website/stock ID.
108
     *
109
     * @var string
110
     */
111
    const STOCK_STATUS = 'stock_status';
112
113
    /**
114
     * The SQL statement to load the stock item with the passed product/website/stock ID.
115
     *
116
     * @var string
117
     */
118
    const STOCK_ITEM = 'stock_item';
119
120
    /**
121
     * The SQL statement to create new products.
122
     *
123
     * @var string
124
     */
125
    const CREATE_PRODUCT = 'create.product';
126
127
    /**
128
     * The SQL statement to update an existing product.
129
     *
130
     * @var string
131
     */
132
    const UPDATE_PRODUCT = 'update.product';
133
134
    /**
135
     * The SQL statement to create a new product website relation.
136
     *
137
     * @var string
138
     */
139
    const CREATE_PRODUCT_WEBSITE = 'create.product_website';
140
141
    /**
142
     * The SQL statement to create a new category product relation.
143
     *
144
     * @var string
145
     */
146
    const CREATE_CATEGORY_PRODUCT = 'create.category_product';
147
148
    /**
149
     * The SQL statement to update an existing category product relation.
150
     *
151
     * @var string
152
     */
153
    const UPDATE_CATEGORY_PRODUCT = 'update.category_product';
154
155
    /**
156
     * The SQL statement to create a new product datetime value.
157
     *
158
     * @var string
159
     */
160
    const CREATE_PRODUCT_DATETIME = 'create.product_datetime';
161
162
    /**
163
     * The SQL statement to update an existing product datetime value.
164
     *
165
     * @var string
166
     */
167
    const UPDATE_PRODUCT_DATETIME = 'update.product_datetime';
168
169
    /**
170
     * The SQL statement to delete an existing product datetime value.
171
     *
172
     * @var string
173
     */
174
    const DELETE_PRODUCT_DATETIME = 'delete.product_datetime';
175
176
    /**
177
     * The SQL statement to create a new product decimal value.
178
     *
179
     * @var string
180
     */
181
    const CREATE_PRODUCT_DECIMAL = 'create.product_decimal';
182
183
    /**
184
     * The SQL statement to update an existing product decimal value.
185
     *
186
     * @var string
187
     */
188
    const UPDATE_PRODUCT_DECIMAL = 'update.product_decimal';
189
190
    /**
191
     * The SQL statement to delete an existing product decimal value.
192
     *
193
     * @var string
194
     */
195
    const DELETE_PRODUCT_DECIMAL = 'delete.product_decimal';
196
197
    /**
198
     * The SQL statement to create a new product integer value.
199
     *
200
     * @var string
201
     */
202
    const CREATE_PRODUCT_INT = 'create.product.int';
203
204
    /**
205
     * The SQL statement to update an existing product integer value.
206
     *
207
     * @var string
208
     */
209
    const UPDATE_PRODUCT_INT = 'update.product_int';
210
211
    /**
212
     * The SQL statement to delete an existing product integer value.
213
     *
214
     * @var string
215
     */
216
    const DELETE_PRODUCT_INT = 'delete.product_int';
217
218
    /**
219
     * The SQL statement to create a new product varchar value.
220
     *
221
     * @var string
222
     */
223
    const CREATE_PRODUCT_VARCHAR = 'create.product_varchar';
224
225
    /**
226
     * The SQL statement to update an existing product varchar value.
227
     *
228
     * @var string
229
     */
230
    const UPDATE_PRODUCT_VARCHAR = 'update.product_varchar';
231
232
    /**
233
     * The SQL statement to delete an existing product varchar value.
234
     *
235
     * @var string
236
     */
237
    const DELETE_PRODUCT_VARCHAR = 'delete.product_varchar';
238
239
    /**
240
     * The SQL statement to create a new product text value.
241
     *
242
     * @var string
243
     */
244
    const CREATE_PRODUCT_TEXT = 'create.product_text';
245
246
    /**
247
     * The SQL statement to update an existing product text value.
248
     *
249
     * @var string
250
     */
251
    const UPDATE_PRODUCT_TEXT = 'update.product_text';
252
253
    /**
254
     * The SQL statement to delete an existing product text value.
255
     *
256
     * @var string
257
     */
258
    const DELETE_PRODUCT_TEXT = 'delete.product_text';
259
260
    /**
261
     * The SQL statement to create a product's stock status.
262
     *
263
     * @var string
264
     */
265
    const CREATE_STOCK_STATUS = 'create.stock_status';
266
267
    /**
268
     * The SQL statement to update an existing stock status.
269
     *
270
     * @var string
271
     */
272
    const UPDATE_STOCK_STATUS = 'update.stock_status';
273
274
    /**
275
     * The SQL statement to create a product's stock status.
276
     *
277
     * @var string
278
     */
279
    const CREATE_STOCK_ITEM = 'create.stock_item';
280
281
    /**
282
     * The SQL statement to create a product's stock status.
283
     *
284
     * @var string
285
     */
286
    const UPDATE_STOCK_ITEM = 'update.stock_item';
287
288
    /**
289
     * The SQL statement to remove a existing product.
290
     *
291
     * @var string
292
     */
293
    const DELETE_PRODUCT = 'delete.product';
294
295
    /**
296
     * The SQL statement to remove all existing stock status related with the SKU passed as parameter.
297
     *
298
     * @var string
299
     */
300
    const DELETE_STOCK_STATUS_BY_SKU = 'delete.stock_status.by.sku';
301
302
    /**
303
     * The SQL statement to remove all existing stock item related with the SKU passed as parameter.
304
     *
305
     * @var string
306
     */
307
    const DELETE_STOCK_ITEM_BY_SKU = 'delete.stock_item.by.sku';
308
309
    /**
310
     * The SQL statement to remove all product website relations for the product with the SKU passed as parameter.
311
     *
312
     * @var string
313
     */
314
    const DELETE_PRODUCT_WEBSITE_BY_SKU = 'delete.product_website.by.sku';
315
316
    /**
317
     * The SQL statement to remove all product category relations for the product.
318
     *
319
     * @var string
320
     */
321
    const DELETE_CATEGORY_PRODUCT = 'delete.category_product';
322
323
    /**
324
     * The SQL statement to remove all product category relations for the product with the SKU passed as parameter.
325
     *
326
     * @var string
327
     */
328
    const DELETE_CATEGORY_PRODUCT_BY_SKU = 'delete.category_product.by.sku';
329
330
    /**
331
     * The SQL statements.
332
     *
333
     * @var array
334
     */
335
    private $statements = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
336
        SqlStatements::PRODUCT =>
337
            'SELECT * FROM catalog_product_entity WHERE sku = :sku',
338
        SqlStatements::PRODUCT_WEBSITE =>
339
            'SELECT * FROM catalog_product_website WHERE product_id = :product_id AND website_id = :website_id',
340
        SqlStatements::PRODUCT_DATETIME =>
341
            'SELECT *
342
               FROM catalog_product_entity_datetime
343
              WHERE entity_id = :entity_id
344
                AND attribute_id = :attribute_id
345
                AND store_id = :store_id',
346
        SqlStatements::PRODUCT_DECIMAL =>
347
            'SELECT *
348
               FROM catalog_product_entity_decimal
349
              WHERE entity_id = :entity_id
350
                AND attribute_id = :attribute_id
351
                AND store_id = :store_id',
352
        SqlStatements::PRODUCT_INT =>
353
            'SELECT *
354
               FROM catalog_product_entity_int
355
              WHERE entity_id = :entity_id
356
                AND attribute_id = :attribute_id
357
                AND store_id = :store_id',
358
        SqlStatements::PRODUCT_TEXT =>
359
            'SELECT *
360
               FROM catalog_product_entity_text
361
              WHERE entity_id = :entity_id
362
                AND attribute_id = :attribute_id
363
                AND store_id = :store_id',
364
        SqlStatements::PRODUCT_VARCHAR =>
365
            'SELECT *
366
               FROM catalog_product_entity_varchar
367
              WHERE entity_id = :entity_id
368
                AND attribute_id = :attribute_id
369
                AND store_id = :store_id',
370
        SqlStatements::PRODUCT_VARCHAR_BY_ATTRIBUTE_CODE_AND_ENTITY_TYPE_ID_AND_STORE_ID_AND_VALUE =>
371
            'SELECT t1.*
372
               FROM catalog_product_entity_varchar t1,
373
                    eav_attribute t2
374
              WHERE t2.attribute_code = :attribute_code
375
                AND t2.entity_type_id = :entity_type_id
376
                AND t1.attribute_id = t2.attribute_id
377
                AND t1.store_id = :store_id
378
                AND t1.value = :value',
379
        SqlStatements::CATEGORY_PRODUCT =>
380
            'SELECT * FROM catalog_category_product WHERE category_id = :category_id AND product_id = :product_id',
381
        SqlStatements::CATEGORY_PRODUCT_BY_SKU =>
382
            'SELECT t1.*
383
               FROM catalog_category_product t1,
384
                    catalog_product_entity t2
385
              WHERE t2.sku = :sku
386
                AND t1.product_id = t2.entity_id',
387
        SqlStatements::STOCK_STATUS =>
388
            'SELECT * FROM cataloginventory_stock_status WHERE product_id = :product_id AND website_id = :website_id AND stock_id = :stock_id',
389
        SqlStatements::STOCK_ITEM =>
390
            'SELECT * FROM cataloginventory_stock_item WHERE product_id = :product_id AND website_id = :website_id AND stock_id = :stock_id',
391
        SqlStatements::CREATE_PRODUCT =>
392
            'INSERT
393
               INTO catalog_product_entity
394
                    (sku,
395
                     created_at,
396
                     updated_at,
397
                     has_options,
398
                     required_options,
399
                     type_id,
400
                     attribute_set_id)
401
             VALUES (:sku,
402
                     :created_at,
403
                     :updated_at,
404
                     :has_options,
405
                     :required_options,
406
                     :type_id,
407
                     :attribute_set_id)',
408
        SqlStatements::UPDATE_PRODUCT =>
409
            'UPDATE catalog_product_entity
410
                SET sku = :sku,
411
                   created_at = :created_at,
412
                    updated_at = :updated_at,
413
                    has_options = :has_options,
414
                    required_options = :required_options,
415
                    type_id = :type_id,
416
                    attribute_set_id = :attribute_set_id
417
              WHERE entity_id = :entity_id',
418
        SqlStatements::CREATE_PRODUCT_WEBSITE =>
419
            'INSERT
420
               INTO catalog_product_website
421
                    (product_id,
422
                     website_id)
423
             VALUES (:product_id,
424
                     :website_id)',
425
        SqlStatements::CREATE_CATEGORY_PRODUCT =>
426
            'INSERT
427
               INTO catalog_category_product
428
                    (category_id,
429
                     product_id,
430
                     position)
431
             VALUES (:category_id,
432
                     :product_id,
433
                     :position)',
434
        SqlStatements::UPDATE_CATEGORY_PRODUCT =>
435
            'UPDATE catalog_category_product
436
                SET category_id = :category_id,
437
                    product_id = :product_id,
438
                    position = :position
439
             WHERE  entity_id = :entity_id',
440
        SqlStatements::CREATE_PRODUCT_DATETIME =>
441
            'INSERT
442
               INTO catalog_product_entity_datetime
443
                    (entity_id,
444
                     attribute_id,
445
                     store_id,
446
                     value)
447
            VALUES (:entity_id,
448
                    :attribute_id,
449
                    :store_id,
450
                    :value)',
451
        SqlStatements::UPDATE_PRODUCT_DATETIME =>
452
            'UPDATE catalog_product_entity_datetime
453
                SET entity_id = :entity_id,
454
                    attribute_id = :attribute_id,
455
                    store_id = :store_id,
456
                    value = :value
457
              WHERE value_id = :value_id',
458
        SqlStatements::DELETE_PRODUCT_DATETIME =>
459
            'DELETE
460
               FROM catalog_product_entity_datetime
461
              WHERE value_id = :value_id',
462
        SqlStatements::CREATE_PRODUCT_DECIMAL =>
463
            'INSERT
464
               INTO catalog_product_entity_decimal
465
                    (entity_id,
466
                     attribute_id,
467
                     store_id,
468
                     value)
469
            VALUES (:entity_id,
470
                    :attribute_id,
471
                    :store_id,
472
                    :value)',
473
        SqlStatements::UPDATE_PRODUCT_DECIMAL =>
474
            'UPDATE catalog_product_entity_decimal
475
                SET entity_id = :entity_id,
476
                    attribute_id = :attribute_id,
477
                    store_id = :store_id,
478
                    value = :value
479
              WHERE value_id = :value_id',
480
        SqlStatements::DELETE_PRODUCT_DECIMAL =>
481
            'DELETE
482
               FROM catalog_product_entity_decimal
483
              WHERE value_id = :value_id',
484
        SqlStatements::CREATE_PRODUCT_INT =>
485
            'INSERT
486
               INTO catalog_product_entity_int
487
                    (entity_id,
488
                     attribute_id,
489
                     store_id,
490
                     value)
491
             VALUES (:entity_id,
492
                     :attribute_id,
493
                     :store_id,
494
                     :value)',
495
        SqlStatements::UPDATE_PRODUCT_INT =>
496
            'UPDATE catalog_product_entity_int
497
                SET entity_id = :entity_id,
498
                    attribute_id = :attribute_id,
499
                    store_id = :store_id,
500
                    value = :value
501
              WHERE value_id = :value_id',
502
        SqlStatements::DELETE_PRODUCT_INT =>
503
            'DELETE
504
               FROM catalog_product_entity_int
505
              WHERE value_id = :value_id',
506
        SqlStatements::CREATE_PRODUCT_VARCHAR =>
507
            'INSERT
508
               INTO catalog_product_entity_varchar
509
                    (entity_id,
510
                     attribute_id,
511
                     store_id,
512
                     value)
513
             VALUES (:entity_id,
514
                     :attribute_id,
515
                     :store_id,
516
                     :value)',
517
        SqlStatements::UPDATE_PRODUCT_VARCHAR =>
518
            'UPDATE catalog_product_entity_varchar
519
                SET entity_id = :entity_id,
520
                    attribute_id = :attribute_id,
521
                    store_id = :store_id,
522
                    value = :value
523
              WHERE value_id = :value_id',
524
        SqlStatements::DELETE_PRODUCT_VARCHAR =>
525
            'DELETE
526
               FROM catalog_product_entity_varchar
527
              WHERE value_id = :value_id',
528
        SqlStatements::CREATE_PRODUCT_TEXT =>
529
            'INSERT
530
               INTO catalog_product_entity_text
531
                    (entity_id,
532
                     attribute_id,
533
                     store_id,
534
                     value)
535
             VALUES (:entity_id,
536
                     :attribute_id,
537
                     :store_id,
538
                     :value)',
539
        SqlStatements::UPDATE_PRODUCT_TEXT =>
540
            'UPDATE catalog_product_entity_text
541
                SET entity_id = :entity_id,
542
                    attribute_id = :attribute_id,
543
                    store_id = :store_id,
544
                    value = :value
545
              WHERE value_id = :value_id',
546
        SqlStatements::DELETE_PRODUCT_TEXT =>
547
            'DELETE
548
               FROM catalog_product_entity_text
549
              WHERE value_id = :value_id',
550
        SqlStatements::CREATE_STOCK_STATUS =>
551
            'INSERT INTO cataloginventory_stock_status (%s) VALUES (:%s)',
552
        SqlStatements::UPDATE_STOCK_STATUS =>
553
            'UPDATE cataloginventory_stock_status SET %s WHERE %s',
554
        SqlStatements::CREATE_STOCK_ITEM =>
555
            'INSERT INTO cataloginventory_stock_item (%s) VALUES (:%s)',
556
        SqlStatements::UPDATE_STOCK_ITEM =>
557
            'UPDATE cataloginventory_stock_item SET %s WHERE %s',
558
        SqlStatements::DELETE_PRODUCT =>
559
            'DELETE
560
               FROM catalog_product_entity
561
              WHERE sku = :sku',
562
        SqlStatements::DELETE_STOCK_STATUS_BY_SKU =>
563
            'DELETE cataloginventory_stock_status
564
               FROM cataloginventory_stock_status
565
         INNER JOIN catalog_product_entity
566
              WHERE catalog_product_entity.sku = :sku
567
                AND cataloginventory_stock_status.product_id = catalog_product_entity.entity_id',
568
        SqlStatements::DELETE_STOCK_ITEM_BY_SKU =>
569
            'DELETE cataloginventory_stock_item
570
               FROM cataloginventory_stock_item
571
         INNER JOIN catalog_product_entity
572
              WHERE catalog_product_entity.sku = :sku
573
                AND cataloginventory_stock_item.product_id = catalog_product_entity.entity_id',
574
        SqlStatements::DELETE_PRODUCT_WEBSITE_BY_SKU =>
575
            'DELETE catalog_product_website
576
               FROM catalog_product_website
577
         INNER JOIN catalog_product_entity
578
              WHERE catalog_product_entity.sku = :sku
579
                AND catalog_product_website.product_id = catalog_product_entity.entity_id',
580
        SqlStatements::DELETE_CATEGORY_PRODUCT =>
581
            'DELETE
582
               FROM catalog_category_product
583
              WHERE entity_id = :entity_id',
584
        SqlStatements::DELETE_CATEGORY_PRODUCT_BY_SKU =>
585
            'DELETE catalog_category_product
586
               FROM catalog_category_product
587
         INNER JOIN catalog_product_entity
588
              WHERE catalog_product_entity.sku = :sku
589
                AND catalog_category_product.product_id = catalog_product_entity.entity_id'
590
    );
591
592
    /**
593
     * Initialize the the SQL statements.
594
     */
595 1
    public function __construct()
596
    {
597
598
        // call the parent constructor
599 1
        parent::__construct();
600
601
        // merge the class statements
602 1
        foreach ($this->statements as $key => $statement) {
603 1
            $this->preparedStatements[$key] = $statement;
604
        }
605 1
    }
606
}
607