ProductSourceItemDefaultObserver   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 73
ccs 0
cts 25
cp 0
rs 10
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addArtefacts() 0 3 1
A process() 0 31 2
A newArtefact() 0 3 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Msi\Observers\ProductSourceItemDefaultObserver
5
 *
6
 * PHP version 7
7
 *
8
 * @author    Tim Wagner <[email protected]>
9
 * @copyright 2019 TechDivision GmbH <[email protected]>
10
 * @license   https://opensource.org/licenses/MIT
11
 * @link      https://github.com/techdivision/import-product-msi
12
 * @link      http://www.techdivision.com
13
 */
14
15
namespace TechDivision\Import\Product\Msi\Observers;
16
17
use TechDivision\Import\Product\Msi\Utils\ColumnKeys;
18
use TechDivision\Import\Product\Observers\AbstractProductImportObserver;
19
20
/**
21
 * Observer that extracts the MSI source item data to a specific CSV file.
22
 *
23
 * @author     Tim Wagner <[email protected]>
24
 * @copyright  2019 TechDivision GmbH <[email protected]>
25
 * @license   https://opensource.org/licenses/MIT
26
 * @link       https://github.com/techdivision/import-product-msi
27
 * @link       http://www.techdivision.com
28
 * @deprecated Since version 13.0.1
29
 * @see        \TechDivision\Import\Product\Msi\Observers\ProductSourceItemObserver
30
 */
31
class ProductSourceItemDefaultObserver extends AbstractProductImportObserver
32
{
33
34
    /**
35
     * The artefact type.
36
     *
37
     * @var string
38
     */
39
    const ARTEFACT_TYPE = 'inventory-msi';
40
41
    /**
42
     * Process the observer's business logic.
43
     *
44
     * @return array The processed row
45
     */
46
    protected function process()
47
    {
48
49
        // query whether or not, we've found a new SKU => means we've found a new product
50
        if ($this->hasBeenProcessed($this->getValue(ColumnKeys::SKU))) {
51
            return;
52
        }
53
54
        // initialize the array for the artefacts and the store view codes
55
        $artefacts = array();
56
57
        // create a new artefact with the column information
58
        $artefacts[] = $this->newArtefact(
59
            array(
60
                ColumnKeys::SKU         => $this->getValue(ColumnKeys::SKU),
61
                ColumnKeys::SOURCE_CODE => 'default',
62
                ColumnKeys::STATUS      => 1,
63
                ColumnKeys::QUANTITY    => $this->getValue(ColumnKeys::QTY, 0),
64
                ColumnKeys::RELATIVE    => $this->getValue(ColumnKeys::QTY_RELATIVE),
0 ignored issues
show
Bug introduced by
The constant TechDivision\Import\Prod...olumnKeys::QTY_RELATIVE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
65
            ),
66
            array(
67
                ColumnKeys::SKU         => ColumnKeys::SKU,
68
                ColumnKeys::SOURCE_CODE => null,
69
                ColumnKeys::STATUS      => null,
70
                ColumnKeys::QUANTITY    => ColumnKeys::QTY,
71
                ColumnKeys::RELATIVE    => null,
72
            )
73
        );
74
75
        // append the artefacts that has to be exported to the subject
76
        $this->addArtefacts($artefacts);
77
    }
78
79
    /**
80
     * Create's and return's a new empty artefact entity.
81
     *
82
     * @param array $columns             The array with the column data
83
     * @param array $originalColumnNames The array with a mapping from the old to the new column names
84
     *
85
     * @return array The new artefact entity
86
     */
87
    protected function newArtefact(array $columns, array $originalColumnNames)
88
    {
89
        return $this->getSubject()->newArtefact($columns, $originalColumnNames);
90
    }
91
92
    /**
93
     * Add the passed product type artefacts to the product with the
94
     * last entity ID.
95
     *
96
     * @param array $artefacts The product type artefacts
97
     *
98
     * @return void
99
     * @uses \TechDivision\Import\Product\Media\Subjects\MediaSubject::getLastEntityId()
100
     */
101
    protected function addArtefacts(array $artefacts)
102
    {
103
        $this->getSubject()->addArtefacts(ProductSourceItemObserver::ARTEFACT_TYPE, $artefacts, false);
104
    }
105
}
106