Completed
Push — master ( 2727c0...993f12 )
by Tim
03:10
created

PreLoadEntityIdObserver::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 7
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Observers\PreLoadEntityIdObserver
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\Observers;
22
23
use TechDivision\Import\Product\Utils\ColumnKeys;
24
use TechDivision\Import\Product\Utils\SqlStatements;
25
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
26
27
/**
28
 * Observer that pre-loads the entity ID of the product with the SKU found in the CSV file.
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
34
 * @link      http://www.techdivision.com
35
 */
36
class PreLoadEntityIdObserver extends AbstractProductImportObserver
37
{
38
39
    /**
40
     * Process the observer's business logic.
41
     *
42
     * @return array The processed row
43
     */
44
    protected function process()
45
    {
46
47
        // query whether or not, we've found a new SKU => means we've found a new product
48
        if ($this->isLastSku($sku = $this->getValue(ColumnKeys::SKU))) {
49
            return;
50
        }
51
52
        // preserve the entity ID for the product with the passed SKU
53
        $this->preLoadEntityId($sku);
54
    }
55
56
    /**
57
     * Pre-load the entity ID for the product with the passed SKU.
58
     *
59
     * @param string $sku The SKU of the product to pre-load
60
     *
61
     * @return void
62
     */
63
    protected function preLoadEntityId($sku)
64
    {
65
        return $this->getSubject()->preLoadEntityId($sku);
66
    }
67
}
68