1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Magic360\Subjects\Magic360Subject |
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
|
|
|
* @author Bernhard Wick <[email protected]> |
16
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
17
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
18
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
19
|
|
|
* @link http://www.techdivision.com |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace TechDivision\Import\Product\Magic360\Subjects; |
23
|
|
|
|
24
|
|
|
use League\Flysystem\Adapter\Local; |
25
|
|
|
use League\Flysystem\Filesystem; |
26
|
|
|
use TechDivision\Import\Subjects\FileUploadTrait; |
27
|
|
|
use TechDivision\Import\Utils\ConfigurationKeys; |
28
|
|
|
use TechDivision\Import\Utils\FileUploadConfigurationKeys; |
29
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
30
|
|
|
use TechDivision\Import\Product\Utils\RegistryKeys as ProductRegistryKeys; |
31
|
|
|
use TechDivision\Import\Product\Subjects\AbstractProductSubject; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The main Magic360 subject |
35
|
|
|
* |
36
|
|
|
* @author Tim Wagner <[email protected]> |
37
|
|
|
* @author Bernhard Wick <[email protected]> |
38
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
39
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
40
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
41
|
|
|
* @link http://www.techdivision.com |
42
|
|
|
* |
43
|
|
|
* @method \TechDivision\Import\Product\Magic360\Services\ProductMagic360ProcessorInterface getProductProcessor() |
44
|
|
|
*/ |
45
|
|
|
class Magic360Subject extends AbstractProductSubject |
46
|
|
|
{ |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* The trait that provides file upload functionality. |
50
|
|
|
* |
51
|
|
|
* @var \TechDivision\Import\Subjects\FileUploadTrait |
52
|
|
|
*/ |
53
|
|
|
use FileUploadTrait; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* The mapping for the SKUs to the created entity IDs. |
57
|
|
|
* |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
protected $skuEntityIdMapping = array(); |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* The entity IDs which were initially within the data storage, before other observers influenced them |
64
|
|
|
* |
65
|
|
|
* @var array |
66
|
|
|
*/ |
67
|
|
|
protected $preloadEntityIds = array(); |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Initializes the subject data |
71
|
|
|
* |
72
|
|
|
* @return void |
73
|
|
|
* @see \Importer\Csv\Actions\ProductImportAction::prepare() |
74
|
|
|
*/ |
75
|
|
|
public function setUp() |
76
|
|
|
{ |
77
|
|
|
|
78
|
|
|
// invoke the parent method |
79
|
|
|
parent::setUp(); |
80
|
|
|
|
81
|
|
|
// load the entity manager and the registry processor |
82
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
83
|
|
|
|
84
|
|
|
// load the status of the actual import process |
85
|
|
|
$status = $registryProcessor->getAttribute($this->serial); |
86
|
|
|
|
87
|
|
|
// load the attribute set we've prepared initially |
88
|
|
|
$this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING]; |
89
|
|
|
$this->preloadEntityIds = $status[ProductRegistryKeys::PRE_LOADED_ENTITY_IDS]; |
90
|
|
|
|
91
|
|
|
// initialize the flag to decide copy images or not |
92
|
|
|
$this->setCopyImages($this->getConfiguration()->getParam(FileUploadConfigurationKeys::COPY_IMAGES)); |
|
|
|
|
93
|
|
|
|
94
|
|
|
// initialize the filesystems root directory |
95
|
|
|
$this->setRootDir($this->getConfiguration()->getParam(ConfigurationKeys::ROOT_DIRECTORY, getcwd())); |
96
|
|
|
|
97
|
|
|
// initialize the filesystem |
98
|
|
|
$this->setFilesystem(new Filesystem(new Local($this->getRootDir()))); |
99
|
|
|
|
100
|
|
|
// initialize media directory => can be absolute or relative |
101
|
|
|
if ($this->getConfiguration()->hasParam(FileUploadConfigurationKeys::MEDIA_DIRECTORY)) { |
102
|
|
|
$this->setMediaDir( |
103
|
|
|
$this->resolvePath( |
104
|
|
|
$this->getConfiguration()->getParam(FileUploadConfigurationKeys::MEDIA_DIRECTORY) |
105
|
|
|
) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// initialize images directory => can be absolute or relative |
110
|
|
|
if ($this->getConfiguration()->hasParam(FileUploadConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
111
|
|
|
$this->setImagesFileDir( |
112
|
|
|
$this->resolvePath( |
113
|
|
|
$this->getConfiguration()->getParam(FileUploadConfigurationKeys::IMAGES_FILE_DIRECTORY) |
114
|
|
|
) |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Return the entity ID for the passed SKU. |
121
|
|
|
* |
122
|
|
|
* @param string $sku The SKU to return the entity ID for |
123
|
|
|
* |
124
|
|
|
* @return integer The mapped entity ID |
125
|
|
|
* @throws \Exception Is thrown if the SKU is not mapped yet |
126
|
|
|
*/ |
127
|
|
|
public function mapSkuToEntityId($sku) |
128
|
|
|
{ |
129
|
|
|
|
130
|
|
|
// query weather or not the SKU has been mapped |
131
|
|
|
if (isset($this->skuEntityIdMapping[$sku])) { |
132
|
|
|
return $this->skuEntityIdMapping[$sku]; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
// throw an exception if the SKU has not been mapped yet |
136
|
|
|
throw new \Exception(sprintf('Found not mapped SKU %s', $sku)); |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Return the entity ID for the passed SKU based on the preload entity IDs. |
141
|
|
|
* |
142
|
|
|
* @param string $sku The SKU to return the entity ID for |
143
|
|
|
* |
144
|
|
|
* @return integer The mapped entity ID |
145
|
|
|
* @throws \Exception Is thrown if the SKU is not mapped yet |
146
|
|
|
*/ |
147
|
|
|
public function mapSkuToPreloadEntityId($sku) |
148
|
|
|
{ |
149
|
|
|
|
150
|
|
|
// query weather or not the SKU has been mapped |
151
|
|
|
if (isset($this->preloadEntityIds[$sku])) { |
152
|
|
|
return $this->preloadEntityIds[$sku]; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// throw an exception if the SKU has not been mapped yet |
156
|
|
|
throw new \Exception(sprintf('Found not mapped SKU %s within preload entities', $sku)); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Loads the mag360 gallery with the passed product ID. |
161
|
|
|
* |
162
|
|
|
* @param integer $productId The product ID of the gallery |
163
|
|
|
* |
164
|
|
|
* @return array The bundle option |
165
|
|
|
*/ |
166
|
|
|
public function loadMagic360Gallery($productId, $position) |
167
|
|
|
{ |
168
|
|
|
return $this->getProductProcessor()->loadMagic360Gallery($productId, $position); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Loads the mag360 gallery with the passed name, store + parent ID. |
173
|
|
|
* |
174
|
|
|
* @param string $productId The product ID of the mag360 column to be returned |
175
|
|
|
* |
176
|
|
|
* @return array The bundle option |
177
|
|
|
*/ |
178
|
|
|
public function loadMagic360Columns($productId) |
179
|
|
|
{ |
180
|
|
|
return $this->getProductProcessor()->loadMagic360Columns($productId); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Persists the passed mag360 gallery and returns the ID. |
185
|
|
|
* |
186
|
|
|
* @param array $galleryEntity The mag360 gallery to persist |
187
|
|
|
* |
188
|
|
|
* @return string The ID of the persisted entity |
189
|
|
|
*/ |
190
|
|
|
public function persistMagic360Gallery($galleryEntity) |
191
|
|
|
{ |
192
|
|
|
return $this->getProductProcessor()->persistMagic360Gallery($galleryEntity); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Persists the passed mag360 gallery and returns the ID. |
197
|
|
|
* |
198
|
|
|
* @param array $productBundleOption The mag360 gallery to persist |
|
|
|
|
199
|
|
|
* |
200
|
|
|
* @return string The ID of the persisted entity |
201
|
|
|
*/ |
202
|
|
|
public function persistMagic360Columns($columnsEntry) |
203
|
|
|
{ |
204
|
|
|
return $this->getProductProcessor()->persistMagic360Columns($columnsEntry); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Persists the passed mag360 gallery and returns the ID. |
209
|
|
|
* |
210
|
|
|
* @param array $galleryEntity The mag360 gallery to persist |
|
|
|
|
211
|
|
|
* |
212
|
|
|
* @return string The ID of the persisted entity |
213
|
|
|
*/ |
214
|
|
|
public function deleteMagic360Gallery($row, $name = null) |
215
|
|
|
{ |
216
|
|
|
return $this->getProductProcessor()->deleteMagic360Gallery($row, $name); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* Persists the passed mag360 gallery and returns the ID. |
221
|
|
|
* |
222
|
|
|
* @param array $productBundleOption The mag360 gallery to persist |
|
|
|
|
223
|
|
|
* |
224
|
|
|
* @return string The ID of the persisted entity |
225
|
|
|
*/ |
226
|
|
|
public function deleteMagic360Columns($row, $name = null) |
227
|
|
|
{ |
228
|
|
|
return $this->getProductProcessor()->deleteMagic360Columns($row, $name); |
229
|
|
|
} |
230
|
|
|
} |
231
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: