1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Category\Observers\ClearImageObserver |
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-category |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Category\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\StoreViewCodes; |
24
|
|
|
use TechDivision\Import\Category\Utils\ColumnKeys; |
25
|
|
|
use TechDivision\Import\Category\Utils\MemberNames; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Observer that extracts the category's image from a CSV file to be added to image specific 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-category |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
|
class ClearImageObserver extends AbstractCategoryImportObserver |
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
|
|
|
// initialize the store view code |
48
|
|
|
$this->getSubject()->prepareStoreViewCode(); |
49
|
|
|
|
50
|
|
|
// load the PK |
51
|
|
|
$pk = $this->getValue($this->getPrimaryKeyColumnName()); |
52
|
|
|
|
53
|
|
|
// load the store view - if no store view has been set, we assume the admin |
54
|
|
|
// store view, which will contain the default (fallback) attribute values |
55
|
|
|
$storeViewCode = $this->getSubject()->getStoreViewCode(StoreViewCodes::ADMIN); |
56
|
|
|
|
57
|
|
|
// query whether or not the row has already been processed |
58
|
|
|
if ($this->storeViewHasBeenProcessed($pk, $storeViewCode)) { |
|
|
|
|
59
|
|
|
// log a message |
60
|
|
|
$this->getSystemLogger()->warning( |
61
|
|
|
$this->getSubject()->appendExceptionSuffix( |
62
|
|
|
sprintf( |
63
|
|
|
'Attributes for %s "%s" + store view code "%s" has already been processed', |
64
|
|
|
$this->getPrimaryKeyColumnName(), |
65
|
|
|
$pk, |
66
|
|
|
$storeViewCode |
67
|
|
|
) |
68
|
|
|
) |
69
|
|
|
); |
70
|
|
|
|
71
|
|
|
// return immediately |
72
|
|
|
return; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// load the store ID, use the admin store if NO store view code has been set |
76
|
|
|
$storeId = $this->getSubject()->getRowStoreId(StoreViewCodes::ADMIN); |
|
|
|
|
77
|
|
|
|
78
|
|
|
// load the image attribute |
79
|
|
|
$attribute = $this->getEavAttributeByAttributeCode('image'); |
80
|
|
|
|
81
|
|
|
// remove the image if one exists |
82
|
|
|
if ($value = $this->loadVarcharAttribute($pk, $attribute[MemberNames::ATTRIBUTE_ID], $storeId)) { |
83
|
|
|
$this->deleteVarcharAttribute(array(MemberNames::VALUE_ID => $value[MemberNames::VALUE_ID])); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Delete's the varchar attribute with the passed value ID. |
89
|
|
|
* |
90
|
|
|
* @param array $row The attributes of the entity to delete |
91
|
|
|
* @param string|null $name The name of the prepared statement that has to be executed |
92
|
|
|
* |
93
|
|
|
* @return void |
94
|
|
|
*/ |
95
|
|
|
protected function deleteVarcharAttribute(array $row, $name = null) |
96
|
|
|
{ |
97
|
|
|
return $this->getCategoryBunchProcessor()->deleteCategoryVarcharAttribute($row, $name); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Load's and return's the varchar attribute with the passed entity/attribute/store ID. |
102
|
|
|
* |
103
|
|
|
* @param integer $entityId The entity ID of the attribute |
104
|
|
|
* @param integer $attributeId The attribute ID of the attribute |
105
|
|
|
* @param integer $storeId The store ID of the attribute |
106
|
|
|
* |
107
|
|
|
* @return array|null The varchar attribute |
108
|
|
|
*/ |
109
|
|
|
protected function loadVarcharAttribute($entityId, $attributeId, $storeId) |
110
|
|
|
{ |
111
|
|
|
return $this->getCategoryBunchProcessor()->loadCategoryVarcharAttribute($entityId, $attributeId, $storeId); |
|
|
|
|
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Return's the EAV attribute with the passed attribute code. |
116
|
|
|
* |
117
|
|
|
* @param string $attributeCode The attribute code |
118
|
|
|
* |
119
|
|
|
* @return array The array with the EAV attribute |
120
|
|
|
* @throws \Exception Is thrown if the attribute with the passed code is not available |
121
|
|
|
*/ |
122
|
|
|
protected function getEavAttributeByAttributeCode($attributeCode) |
123
|
|
|
{ |
124
|
|
|
return $this->getSubject()->getEavAttributeByAttributeCode($attributeCode); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Return's the category with the passed path. |
129
|
|
|
* |
130
|
|
|
* @param string $path The path of the category to return |
131
|
|
|
* |
132
|
|
|
* @return array The category |
133
|
|
|
*/ |
134
|
|
|
protected function getCategoryByPath($path) |
135
|
|
|
{ |
136
|
|
|
return $this->getSubject()->getCategoryByPath($path); |
|
|
|
|
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Return's the PK to create the product => attribute relation. |
141
|
|
|
* |
142
|
|
|
* @return integer The PK to create the relation with |
143
|
|
|
*/ |
144
|
|
|
protected function getPrimaryKey() |
145
|
|
|
{ |
146
|
|
|
return $this->getSubject()->getLastEntityId(); |
|
|
|
|
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
/** |
150
|
|
|
* Return's the PK column name to create the product => attribute relation. |
151
|
|
|
* |
152
|
|
|
* @return string The PK column name |
153
|
|
|
*/ |
154
|
|
|
protected function getPrimaryKeyMemberName() |
155
|
|
|
{ |
156
|
|
|
return MemberNames::ENTITY_ID; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Return's the column name that contains the primary key. |
161
|
|
|
* |
162
|
|
|
* @return string the column name that contains the primary key |
163
|
|
|
*/ |
164
|
|
|
protected function getPrimaryKeyColumnName() |
165
|
|
|
{ |
166
|
|
|
return ColumnKeys::PATH; |
167
|
|
|
} |
168
|
|
|
} |
169
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.