Completed
Pull Request — master (#5)
by Tim
02:21
created

AttributeOptionValueExportObserver::process()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 42
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
c 0
b 0
f 0
rs 8.8571
cc 3
eloc 20
nc 3
nop 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Observers\AttributeOptionValueExportObserver
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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Observers;
22
23
use TechDivision\Import\Attribute\Utils\ColumnKeys;
24
25
/**
26
 * Observer that exports the attribute options to an additional CSV file for further processing.
27
 *
28
 * @author    Tim Wagner <[email protected]>
29
 * @copyright 2016 TechDivision GmbH <[email protected]>
30
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
31
 * @link      https://github.com/techdivision/import-attribute
32
 * @link      http://www.techdivision.com
33
 */
34
class AttributeOptionValueExportObserver extends AbstractAttributeExportObserver
35
{
36
37
    /**
38
     * The artefact type.
39
     *
40
     * @var string
41
     */
42
    const ARTEFACT_TYPE = 'option-value-import';
43
44
    /**
45
     * Process the observer's business logic.
46
     *
47
     * @return void
48
     */
49
    protected function process()
50
    {
51
52
        // do NOT export the value if we're NOT in the admin store view
53
        if ($this->isAdminStore()) {
54
            return;
55
        }
56
57
        // prepare the store view code
58
        $this->prepareStoreViewCode();
59
60
        // initialize the array with the artefacts
61
        $artefacts = array();
62
63
        // load the attribute option values for the custom store views
64
        $attributeOptionValues = $this->getValue(ColumnKeys::ATTRIBUTE_OPTION_VALUES, array(), array($this, 'explode'));
65
66
        // iterate over the attribute option values and export them
67
        foreach ($attributeOptionValues as $key => $attributeOptionValue) {
68
            // load the artefacts with the admin store values
69
            $adminValueArtefacts = reset($this->getArtefactsByTypeAndEntityId(AttributeOptionExportObserver::ARTEFACT_TYPE, $this->getLastEntityId()));
0 ignored issues
show
Bug introduced by
$this->getArtefactsByTyp...his->getLastEntityId()) cannot be passed to reset() as the parameter $array expects a reference.
Loading history...
70
71
            // initialize and add the new artefact
72
            $artefacts[] = $this->newArtefact(
73
                array(
74
                    ColumnKeys::STORE_VIEW_CODE   => $this->getValue(ColumnKeys::STORE_VIEW_CODE),
75
                    ColumnKeys::ATTRIBUTE_CODE    => $this->getValue(ColumnKeys::ATTRIBUTE_CODE),
76
                    ColumnKeys::ADMIN_STORE_VALUE => $adminValueArtefacts[$key][ColumnKeys::VALUE],
77
                    ColumnKeys::VALUE             => $attributeOptionValue
78
                ),
79
                array(
80
                    ColumnKeys::STORE_VIEW_CODE   => ColumnKeys::STORE_VIEW_CODE,
81
                    ColumnKeys::ATTRIBUTE_CODE    => ColumnKeys::ATTRIBUTE_CODE,
82
                    ColumnKeys::ADMIN_STORE_VALUE => ColumnKeys::ADMIN_STORE_VALUE,
83
                    ColumnKeys::VALUE             => ColumnKeys::VALUE
84
                )
85
            );
86
        }
87
88
        // add the array with the artefacts
89
        $this->addArtefacts($artefacts);
90
    }
91
92
    /**
93
     * Return's the artefact type used for export.
94
     *
95
     * @return string The artefact type
96
     */
97
    protected function getArtefactType()
98
    {
99
        return AttributeOptionValueExportObserver::ARTEFACT_TYPE;
100
    }
101
}
102