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 option swatch values 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 AttributeOptionSwatchExportObserver extends AbstractAttributeExportObserver |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The artefact type. |
39
|
|
|
* |
40
|
|
|
* @var string |
41
|
|
|
*/ |
42
|
|
|
const ARTEFACT_TYPE = 'option-swatch-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
|
|
|
$attributeOptionSwatch = $this->explode($this->getValue(ColumnKeys::ATTRIBUTE_OPTION_SWATCH), $this->getMultipleValueDelimiter()); |
|
|
|
|
66
|
|
|
|
67
|
|
|
// load the option value keys |
68
|
|
|
$optionValueKeys = array_keys($attributeOptionValues); |
69
|
|
|
|
70
|
|
|
// iterate over the attribute option values and export them |
71
|
|
|
foreach ($optionValueKeys as $key) { |
72
|
|
|
// load the artefacts with the admin store values |
73
|
|
|
$adminValueArtefacts = $this->getArtefactsByTypeAndEntityId(AttributeOptionExportObserver::ARTEFACT_TYPE, $this->getLastEntityId()); |
|
|
|
|
74
|
|
|
|
75
|
|
|
// initialize the attribute option swatch data |
76
|
|
|
$optionSwatch = array(); |
77
|
|
|
if (isset($attributeOptionSwatch[$key])) { |
78
|
|
|
// prepare the EAV attribute option swatch values |
79
|
|
View Code Duplication |
foreach ($this->explode($attributeOptionSwatch[$key]) as $value) { |
|
|
|
|
80
|
|
|
$explodedSwatch = $this->explode($value, '='); |
|
|
|
|
81
|
|
|
if (isset($explodedSwatch[0]) && isset($explodedSwatch[1])) { |
82
|
|
|
$optionSwatch[$explodedSwatch[0]] = $explodedSwatch[1]; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
// initialize and add the new artefact |
87
|
|
|
$artefacts[] = $this->newArtefact( |
88
|
|
|
array( |
89
|
|
|
ColumnKeys::STORE_VIEW_CODE => $this->getValue(ColumnKeys::STORE_VIEW_CODE), |
90
|
|
|
ColumnKeys::ATTRIBUTE_CODE => $this->getValue(ColumnKeys::ATTRIBUTE_CODE), |
91
|
|
|
ColumnKeys::ADMIN_STORE_VALUE => $adminValueArtefacts[$key][ColumnKeys::VALUE], |
92
|
|
|
ColumnKeys::SWATCH_TYPE => isset($optionSwatch[ColumnKeys::TYPE]) ? $optionSwatch[ColumnKeys::TYPE] : null, |
93
|
|
|
ColumnKeys::SWATCH_VALUE => isset($optionSwatch[ColumnKeys::VALUE]) ? $optionSwatch[ColumnKeys::VALUE] : null |
94
|
|
|
), |
95
|
|
|
array( |
96
|
|
|
ColumnKeys::STORE_VIEW_CODE => ColumnKeys::STORE_VIEW_CODE, |
97
|
|
|
ColumnKeys::ATTRIBUTE_CODE => ColumnKeys::ATTRIBUTE_CODE, |
98
|
|
|
ColumnKeys::ADMIN_STORE_VALUE => $adminValueArtefacts[$key][ColumnKeys::VALUE], |
99
|
|
|
ColumnKeys::SWATCH_TYPE => ColumnKeys::ATTRIBUTE_OPTION_SWATCH, |
100
|
|
|
ColumnKeys::SWATCH_VALUE => ColumnKeys::ATTRIBUTE_OPTION_SWATCH |
101
|
|
|
) |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
// add the array with the artefacts |
107
|
|
|
$this->addArtefacts($artefacts); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return's the artefact type used for export. |
112
|
|
|
* |
113
|
|
|
* @return string The artefact type |
114
|
|
|
*/ |
115
|
|
|
protected function getArtefactType() |
116
|
|
|
{ |
117
|
|
|
return AttributeOptionSwatchExportObserver::ARTEFACT_TYPE; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.