|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Category\Ee\Subjects\EeBunchSubject |
|
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 2019 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-ee |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Category\Ee\Subjects; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\StoreViewCodes; |
|
24
|
|
|
use TechDivision\Import\Category\Utils\RegistryKeys; |
|
25
|
|
|
use TechDivision\Import\Category\Subjects\BunchSubject; |
|
26
|
|
|
use TechDivision\Import\Category\Ee\Utils\MemberNames; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* A SLSB that handles the process to import category bunches. |
|
30
|
|
|
* |
|
31
|
|
|
* @author Tim Wagner <[email protected]> |
|
32
|
|
|
* @copyright 2019 TechDivision GmbH <[email protected]> |
|
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
34
|
|
|
* @link https://github.com/techdivision/import-category-ee |
|
35
|
|
|
* @link http://www.techdivision.com |
|
36
|
|
|
*/ |
|
37
|
|
|
class EeBunchSubject extends BunchSubject |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The row ID of the product that has been created recently. |
|
42
|
|
|
* |
|
43
|
|
|
* @var integer |
|
44
|
|
|
*/ |
|
45
|
|
|
protected $lastRowId; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* The mapping for the paths to the created row IDs. |
|
49
|
|
|
* |
|
50
|
|
|
* @var array |
|
51
|
|
|
*/ |
|
52
|
|
|
protected $pathRowIdMapping = array(); |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Intializes the previously loaded global data for exactly one bunch. |
|
56
|
|
|
* |
|
57
|
|
|
* @param string $serial The serial of the actual import |
|
58
|
|
|
* |
|
59
|
|
|
* @return void |
|
60
|
|
|
*/ |
|
61
|
|
|
public function setUp($serial) |
|
62
|
|
|
{ |
|
63
|
|
|
|
|
64
|
|
|
// prepare the callbacks |
|
65
|
|
|
parent::setUp($serial); |
|
66
|
|
|
|
|
67
|
|
|
// load the status of the actual import |
|
68
|
|
|
$status = $this->getRegistryProcessor()->getAttribute(RegistryKeys::STATUS); |
|
69
|
|
|
|
|
70
|
|
|
// load the available category path => row ID mappings |
|
71
|
|
|
foreach ($this->categories as $resolvedPath => $category) { |
|
72
|
|
|
$this->pathRowIdMapping[$this->unifyPath($resolvedPath)] = $category[MemberNames::ROW_ID]; |
|
|
|
|
|
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
// load the category path => row ID mappings from the previous subject |
|
76
|
|
|
if (isset($status[RegistryKeys::PATH_ROW_ID_MAPPING])) { |
|
77
|
|
|
$this->pathRowIdMapping = array_merge($this->pathRowIdMapping, $status[RegistryKeys::PATH_ROW_ID_MAPPING]); |
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Clean up the global data after importing the variants. |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $serial The serial of the actual import |
|
85
|
|
|
* |
|
86
|
|
|
* @return void |
|
87
|
|
|
*/ |
|
88
|
|
|
public function tearDown($serial) |
|
89
|
|
|
{ |
|
90
|
|
|
|
|
91
|
|
|
// load the registry processor |
|
92
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
|
93
|
|
|
|
|
94
|
|
|
// update the status with the actual path => row ID mappings |
|
95
|
|
|
$registryProcessor->mergeAttributesRecursive( |
|
96
|
|
|
RegistryKeys::STATUS, |
|
97
|
|
|
array( |
|
98
|
|
|
RegistryKeys::PATH_ROW_ID_MAPPING => $this->pathRowIdMapping |
|
99
|
|
|
) |
|
100
|
|
|
); |
|
101
|
|
|
|
|
102
|
|
|
// invoke the parent method |
|
103
|
|
|
parent::tearDown($serial); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* Set's the row ID of the product that has been created recently. |
|
108
|
|
|
* |
|
109
|
|
|
* @param string $lastRowId The row ID |
|
110
|
|
|
* |
|
111
|
|
|
* @return void |
|
112
|
|
|
*/ |
|
113
|
1 |
|
public function setLastRowId($lastRowId) |
|
114
|
|
|
{ |
|
115
|
1 |
|
$this->lastRowId = $lastRowId; |
|
|
|
|
|
|
116
|
1 |
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Return's the row ID of the product that has been created recently. |
|
120
|
|
|
* |
|
121
|
|
|
* @return string The row Id |
|
122
|
|
|
*/ |
|
123
|
1 |
|
public function getLastRowId() |
|
124
|
|
|
{ |
|
125
|
1 |
|
return $this->lastRowId; |
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Add the passed path => row ID mapping. |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $path The path |
|
132
|
|
|
* |
|
133
|
|
|
* @return void |
|
134
|
|
|
*/ |
|
135
|
|
|
public function addPathRowIdMapping($path) |
|
136
|
|
|
{ |
|
137
|
|
|
$this->pathRowIdMapping[$this->unifyPath($path)] = $this->getLastRowId(); |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Removes the mapping, e. g. when a category has been deleted. |
|
142
|
|
|
* |
|
143
|
|
|
* @param string $path The path to delete the mapping for |
|
144
|
|
|
* |
|
145
|
|
|
* @return void |
|
146
|
|
|
*/ |
|
147
|
|
|
public function removePathRowIdMapping($path) |
|
148
|
|
|
{ |
|
149
|
|
|
unset($this->pathRowIdMapping[$this->unifyPath($path)]); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Return's the entity ID for the passed path. |
|
154
|
|
|
* |
|
155
|
|
|
* @param string $path The path to return the entity ID for |
|
156
|
|
|
* |
|
157
|
|
|
* @return integer The mapped entity ID |
|
158
|
|
|
* @throws \Exception Is thrown, if the path can not be mapped |
|
159
|
|
|
*/ |
|
160
|
|
|
public function mapPathRowId($path) |
|
161
|
|
|
{ |
|
162
|
|
|
|
|
163
|
|
|
// query whether or not a entity ID for the passed path has been mapped |
|
164
|
|
|
if (isset($this->pathRowIdMapping[$unifiedPath = $this->unifyPath($path)])) { |
|
|
|
|
|
|
165
|
|
|
return $this->pathRowIdMapping[$unifiedPath]; |
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
// throw an exception if not |
|
169
|
|
|
throw new \Exception( |
|
170
|
|
|
$this->appendExceptionSuffix( |
|
171
|
|
|
sprintf('Can\'t map path %s to any row ID', $path) |
|
172
|
|
|
) |
|
173
|
|
|
); |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
/** |
|
177
|
|
|
* Return's the PK column name to create the product => attribute relation. |
|
178
|
|
|
* |
|
179
|
|
|
* @return string The PK column name |
|
180
|
|
|
*/ |
|
181
|
|
|
protected function getPrimaryKeyMemberName() |
|
182
|
|
|
{ |
|
183
|
|
|
return MemberNames::ROW_ID; |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Return's TRUE, if the passed URL key varchar value IS related with the actual PK. |
|
188
|
|
|
* |
|
189
|
|
|
* @param array $categoryVarcharAttribute The varchar value to check |
|
190
|
|
|
* |
|
191
|
|
|
* @return boolean TRUE if the URL key is related, else FALSE |
|
192
|
|
|
*/ |
|
193
|
|
|
public function isUrlKeyOf(array $categoryVarcharAttribute) |
|
194
|
|
|
{ |
|
195
|
|
|
return ((integer) $categoryVarcharAttribute[MemberNames::ROW_ID] === (integer) $this->getLastRowId()) && |
|
196
|
|
|
((integer) $categoryVarcharAttribute[MemberNames::STORE_ID] === (integer) $this->getRowStoreId(StoreViewCodes::ADMIN)); |
|
197
|
|
|
} |
|
198
|
|
|
} |
|
199
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.