Completed
Push — master ( fd6ade...042581 )
by Tim
12s
created

EeBunchSubject::nextIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Ee\Subjects\EeBunchSubject
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-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Ee\Subjects;
22
23
use TechDivision\Import\Utils\RegistryKeys;
24
use TechDivision\Import\Product\Ee\Utils\MemberNames;
25
use TechDivision\Import\Product\Subjects\BunchSubject;
26
27
/**
28
 * A SLSB that handles the process to import product bunches.
29
 *
30
 * @author    Tim Wagner <[email protected]>
31
 * @copyright 2016 TechDivision GmbH <[email protected]>
32
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
33
 * @link      https://github.com/techdivision/import-product-ee
34
 * @link      http://www.techdivision.com
35
 */
36
class EeBunchSubject extends BunchSubject
37
{
38
39
    /**
40
     * The row ID of the product that has been created recently.
41
     *
42
     * @var integer
43
     */
44
    protected $lastRowId;
45
46
    /**
47
     * The mapping for the SKUs to the created row IDs.
48
     *
49
     * @var array
50
     */
51
    protected $skuRowIdMapping = array();
52
53
    /**
54
     * The mapping for the supported backend types (for the product entity) => persist methods.
55
     *
56
     * @var array
57
     */
58
    protected $backendTypes = array(
59
        'datetime' => array('persistDatetimeAttribute', 'loadProductDatetimeAttributeByRowIdAndAttributeIdAndStoreId'),
60
        'decimal'  => array('persistDecimalAttribute', 'loadProductDecimalAttributeByRowIdAndAttributeIdAndStoreId'),
61
        'int'      => array('persistIntAttribute', 'loadProductIntAttributeByRowIdAndAttributeIdAndStoreId'),
62
        'text'     => array('persistTextAttribute', 'loadProductTextAttributeByRowIdAndAttributeIdAndStoreId'),
63
        'varchar'  => array('persistVarcharAttribute', 'loadProductVarcharAttributeByRowIdAndAttributeIdAndStoreId')
64
    );
65
66
    /**
67
     * Mappings for the table column => CSV column header.
68
     *
69
     * @var array
70
     */
71
    protected $headerStockMappings = array(
72
        'qty'                              => array('qty', 'float'),
73
        'min_qty'                          => array('out_of_stock_qty', 'float'),
74
        'use_config_min_qty'               => array('use_config_min_qty', 'int'),
75
        'is_qty_decimal'                   => array('is_qty_decimal', 'int'),
76
        'backorders'                       => array('allow_backorders', 'int'),
77
        'use_config_backorders'            => array('use_config_backorders', 'int'),
78
        'min_sale_qty'                     => array('min_cart_qty', 'float'),
79
        'use_config_min_sale_qty'          => array('use_config_min_sale_qty', 'int'),
80
        'max_sale_qty'                     => array('max_cart_qty', 'float'),
81
        'use_config_max_sale_qty'          => array('use_config_max_sale_qty', 'int'),
82
        'is_in_stock'                      => array('is_in_stock', 'int'),
83
        'notify_stock_qty'                 => array('notify_on_stock_below', 'float'),
84
        'use_config_notify_stock_qty'      => array('use_config_notify_stock_qty', 'int'),
85
        'manage_stock'                     => array('manage_stock', 'int'),
86
        'use_config_manage_stock'          => array('use_config_manage_stock', 'int'),
87
        'use_config_qty_increments'        => array('use_config_qty_increments', 'int'),
88
        'qty_increments'                   => array('qty_increments', 'float'),
89
        'use_config_enable_qty_inc'        => array('use_config_enable_qty_inc', 'int'),
90
        'enable_qty_increments'            => array('enable_qty_increments', 'int'),
91
        'is_decimal_divided'               => array('is_decimal_divided', 'int'),
92
        'deferred_stock_update'            => array('deferred_stock_update', 'int'),
93
        'use_config_deferred_stock_update' => array('use_config_deferred_stock_update', 'int'),
94
    );
95
96
    /**
97
     * Return's TRUE, if the passed URL key varchar value IS related with the actual PK.
98
     *
99
     * @param array $productVarcharAttribute The varchar value to check
100
     *
101
     * @return boolean TRUE if the URL key is related, else FALSE
102
     */
103
    public function isUrlKeyOf(array $productVarcharAttribute)
104
    {
105
        return $productVarcharAttribute[MemberNames::ROW_ID] === $this->getLastRowId();
106
    }
107
108
    /**
109
     * Clean up the global data after importing the bunch.
110
     *
111
     * @param string $serial The serial of the actual import
112
     *
113
     * @return void
114
     */
115
    public function tearDown($serial)
116
    {
117
118
        // call parent method
119
        parent::tearDown($serial);
120
121
        // load the registry processor
122
        $registryProcessor = $this->getRegistryProcessor();
123
124
        // update the status up the actual import with SKU => row ID mapping
125
        $registryProcessor->mergeAttributesRecursive($this->serial, array(RegistryKeys::SKU_ROW_ID_MAPPING => $this->skuRowIdMapping));
126
    }
127
128
    /**
129
     * Set's the row ID of the product that has been created recently.
130
     *
131
     * @param string $lastRowId The row ID
132
     *
133
     * @return void
134
     */
135
    public function setLastRowId($lastRowId)
136
    {
137
        $this->lastRowId = $lastRowId;
0 ignored issues
show
Documentation Bug introduced by
The property $lastRowId was declared of type integer, but $lastRowId is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
138
    }
139
140
    /**
141
     * Return's the row ID of the product that has been created recently.
142
     *
143
     * @return string The row Id
144
     */
145
    public function getLastRowId()
146
    {
147
        return $this->lastRowId;
148
    }
149
150
    /**
151
     * Add the passed SKU => row ID mapping.
152
     *
153
     * @param string $sku The SKU
154
     *
155
     * @return void
156
     */
157
    public function addSkuRowIdMapping($sku)
158
    {
159
        $this->skuRowIdMapping[$sku] = $this->getLastRowId();
160
    }
161
}
162