SqlStatementRepository   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 46
c 1
b 0
f 0
dl 0
loc 66
ccs 0
cts 3
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\TierPrice\Repositories\SqlStatementRepository
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Klaas-Tido Rühl <[email protected]>
9
 * @author    Tim Wagner <[email protected]>
10
 * @copyright 2019 REFUSiON GmbH <[email protected]>
11
 * @license   https://opensource.org/licenses/MIT
12
 * @link      https://github.com/techdivision/import-product-tier-price
13
 * @link      https://www.techdivision.com
14
 * @link      https://www.refusion.com
15
 */
16
17
namespace TechDivision\Import\Product\TierPrice\Repositories;
18
19
use TechDivision\Import\Product\TierPrice\Utils\SqlStatementKeys;
20
21
/**
22
 * Adds statements specifically required for tier price CRUD operations.
23
 *
24
 * @author    Klaas-Tido Rühl <[email protected]>
25
 * @author    Tim Wagner <[email protected]>
26
 * @copyright 2019 REFUSiON GmbH <[email protected]>
27
 * @license   https://opensource.org/licenses/MIT
28
 * @link      https://github.com/techdivision/import-product-tier-price
29
 * @link      https://www.techdivision.com
30
 * @link      https://www.refusion.com
31
 */
32
class SqlStatementRepository extends \TechDivision\Import\Repositories\SqlStatementRepository
33
{
34
35
    /**
36
     * The SQL statements.
37
     *
38
     * @var array
39
     */
40
    private $statements = array(
41
        SqlStatementKeys::TIER_PRICES =>
42
            'SELECT *
43
               FROM ${table:catalog_product_entity_tier_price}',
44
        SqlStatementKeys::TIER_PRICE_BY_PK_AND_ALL_GROUPS_AND_CUSTOMER_GROUP_ID_AND_QTY_AND_WEBSITE_ID =>
45
            'SELECT *
46
               FROM ${table:catalog_product_entity_tier_price}
47
              WHERE ${pk:entity_id} = :${pk:entity_id}
48
                AND all_groups = :all_groups
49
                AND customer_group_id = :customer_group_id
50
                AND qty = :qty
51
                AND website_id = :website_id',
52
        SqlStatementKeys::DELETE_TIER_PRICE =>
53
            'DELETE
54
               FROM ${table:catalog_product_entity_tier_price}
55
              WHERE value_id = :value_id',
56
        SqlStatementKeys::CREATE_TIER_PRICE =>
57
            'INSERT
58
               INTO ${table:catalog_product_entity_tier_price}
59
                    (all_groups,
60
                     customer_group_id,
61
                     qty,
62
                     value,
63
                     website_id,
64
                     percentage_value,
65
                     ${pk:entity_id})
66
             VALUES (:all_groups,
67
                     :customer_group_id,
68
                     :qty,
69
                     :value,
70
                     :website_id,
71
                     :percentage_value,
72
                     :${pk:entity_id})',
73
        SqlStatementKeys::UPDATE_TIER_PRICE =>
74
            'UPDATE ${table:catalog_product_entity_tier_price}
75
                SET all_groups = :all_groups,
76
                    customer_group_id = :customer_group_id,
77
                    qty = :qty,
78
                    value = :value,
79
                    website_id = :website_id,
80
                    percentage_value = :percentage_value,
81
                    ${pk:entity_id} = :${pk:entity_id}
82
              WHERE value_id = :value_id'
83
    );
84
85
    /**
86
     * Initializes the SQL statement repository with the primary key and table prefix utility.
87
     *
88
     * @param \IteratorAggregate<\TechDivision\Import\Dbal\Utils\SqlCompilerInterface> $compilers The array with the compiler instances
89
     */
90
    public function __construct(\IteratorAggregate $compilers)
91
    {
92
93
        // pass primary key + table prefix utility to parent instance
94
        parent::__construct($compilers);
95
96
        // compile the SQL statements
97
        $this->compile($this->statements);
98
    }
99
}
100