Completed
Push — master ( 75c1b1...70c9d5 )
by Tim
14:06 queued 12:57
created

EeBunchSubject::isUrlKeyOf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
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\Subjects\BunchSubject;
25
use TechDivision\Import\Product\Ee\Exceptions\MapSkuToRowIdException;
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
     * Mappings for the table column => CSV column header.
55
     *
56
     * @var array
57
     */
58
    protected $headerStockMappings = array(
59
        'qty'                              => array('qty', 'float'),
60
        'min_qty'                          => array('out_of_stock_qty', 'float'),
61
        'use_config_min_qty'               => array('use_config_min_qty', 'int'),
62
        'is_qty_decimal'                   => array('is_qty_decimal', 'int'),
63
        'backorders'                       => array('allow_backorders', 'int'),
64
        'use_config_backorders'            => array('use_config_backorders', 'int'),
65
        'min_sale_qty'                     => array('min_cart_qty', 'float'),
66
        'use_config_min_sale_qty'          => array('use_config_min_sale_qty', 'int'),
67
        'max_sale_qty'                     => array('max_cart_qty', 'float'),
68
        'use_config_max_sale_qty'          => array('use_config_max_sale_qty', 'int'),
69
        'is_in_stock'                      => array('is_in_stock', 'int'),
70
        'notify_stock_qty'                 => array('notify_on_stock_below', 'float'),
71
        'use_config_notify_stock_qty'      => array('use_config_notify_stock_qty', 'int'),
72
        'manage_stock'                     => array('manage_stock', 'int'),
73
        'use_config_manage_stock'          => array('use_config_manage_stock', 'int'),
74
        'use_config_qty_increments'        => array('use_config_qty_increments', 'int'),
75
        'qty_increments'                   => array('qty_increments', 'float'),
76
        'use_config_enable_qty_inc'        => array('use_config_enable_qty_inc', 'int'),
77
        'enable_qty_increments'            => array('enable_qty_increments', 'int'),
78
        'is_decimal_divided'               => array('is_decimal_divided', 'int'),
79
        'deferred_stock_update'            => array('deferred_stock_update', 'int'),
80
        'use_config_deferred_stock_update' => array('use_config_deferred_stock_update', 'int'),
81
    );
82
83
    /**
84
     * The default callback mappings for the Magento EE standard product attributes.
85
     *
86
     * @var array
87
     */
88
    protected $defaultEeCallbackMappings = array(
89
        'is_returnable' => array('import_product_ee.callback.rma')
90
    );
91
92
    /**
93
     * Return's the default callback mappings.
94
     *
95
     * @return array The default callback mappings
96
     */
97
    public function getDefaultCallbackMappings()
98
    {
99
        return array_merge(parent::getDefaultCallbackMappings(), $this->defaultEeCallbackMappings);
100
    }
101
102
    /**
103
     * Clean up the global data after importing the bunch.
104
     *
105
     * @param string $serial The serial of the actual import
106
     *
107
     * @return void
108
     */
109
    public function tearDown($serial)
110
    {
111
112
        // load the registry processor
113
        $registryProcessor = $this->getRegistryProcessor();
114
115
        // update the status up the actual import with SKU => row ID mapping
116
        $registryProcessor->mergeAttributesRecursive(RegistryKeys::STATUS, array(RegistryKeys::SKU_ROW_ID_MAPPING => $this->skuRowIdMapping));
117
118
        // call parent method
119
        parent::tearDown($serial);
120
    }
121
122
    /**
123
     * Set's the row ID of the product that has been created recently.
124
     *
125
     * @param string $lastRowId The row ID
126
     *
127
     * @return void
128
     */
129
    public function setLastRowId($lastRowId)
130
    {
131
        $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...
132
    }
133
134
    /**
135
     * Return's the row ID of the product that has been created recently.
136
     *
137
     * @return string The row Id
138
     */
139
    public function getLastRowId()
140
    {
141
        return $this->lastRowId;
142
    }
143
144
    /**
145
     * Add the passed SKU => row ID mapping.
146
     *
147
     * @param string       $sku   The SKU
148
     * @param integer|null $rowId The optional entity ID, the last processed entity ID is used, if not set
149
     *
150
     * @return void
151
     */
152
    public function addSkuRowIdMapping($sku, $rowId = null)
153
    {
154
        $this->skuRowIdMapping[$sku] = $rowId == null ? $this->getLastRowId() : $rowId;
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $rowId of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
155
    }
156
157
    /**
158
     * Return the row ID for the passed SKU.
159
     *
160
     * @param string $sku The SKU to return the row ID for
161
     *
162
     * @return integer The mapped row ID
163
     * @throws \TechDivision\Import\Product\Ee\Exceptions\MapSkuToRowIdException Is thrown if the SKU is not mapped yet
164
     */
165
    public function mapSkuToRowId($sku)
166
    {
167
168
        // query weather or not the SKU has been mapped
169
        if (isset($this->skuRowIdMapping[$sku])) {
170
            return $this->skuRowIdMapping[$sku];
171
        }
172
173
        // throw an exception if the SKU has not been mapped yet
174
        throw new MapSkuToRowIdException(
175
            $this->appendExceptionSuffix(
176
                sprintf('Found not mapped entity ID for SKU %s', $sku)
177
            )
178
        );
179
    }
180
}
181