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 TechDivision\Import\Utils\RegistryKeys; |
25
|
|
|
use TechDivision\Import\Utils\FileUploadConfigurationKeys; |
26
|
|
|
use TechDivision\Import\Subjects\FileUploadTrait; |
27
|
|
|
use TechDivision\Import\Product\Utils\RegistryKeys as ProductRegistryKeys; |
28
|
|
|
use TechDivision\Import\Product\Subjects\AbstractProductSubject; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* The main Magic360 subject |
32
|
|
|
* |
33
|
|
|
* @author Tim Wagner <[email protected]> |
34
|
|
|
* @author Bernhard Wick <[email protected]> |
35
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
36
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
37
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
38
|
|
|
* @link http://www.techdivision.com |
39
|
|
|
* |
40
|
|
|
* @method \TechDivision\Import\Product\Magic360\Services\ProductMagic360ProcessorInterface getProductProcessor() |
41
|
|
|
*/ |
42
|
|
|
class Magic360Subject extends AbstractProductSubject |
43
|
|
|
{ |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* The trait that provides file upload functionality. |
47
|
|
|
* |
48
|
|
|
* @var \TechDivision\Import\Subjects\FileUploadTrait |
49
|
|
|
*/ |
50
|
|
|
use FileUploadTrait; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* The mapping for the SKUs to the created entity IDs. |
54
|
|
|
* |
55
|
|
|
* @var array $skuEntityIdMapping |
56
|
|
|
*/ |
57
|
|
|
protected $skuEntityIdMapping = array(); |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* The entity IDs which were initially within the data storage, before other observers influenced them |
61
|
|
|
* |
62
|
|
|
* @var array $preloadEntityIds |
63
|
|
|
*/ |
64
|
|
|
protected $preloadEntityIds = array(); |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* The name of the craeted image. |
68
|
|
|
* |
69
|
|
|
* @var integer |
70
|
|
|
*/ |
71
|
|
|
protected $parentImage; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Initializes the subject data |
75
|
|
|
* |
76
|
|
|
* @param string $serial The serial of the actual import |
77
|
|
|
* |
78
|
|
|
* @return void |
79
|
|
|
*/ |
80
|
|
|
public function setUp($serial) |
81
|
|
|
{ |
82
|
|
|
|
83
|
|
|
// invoke the parent method |
84
|
|
|
parent::setUp($serial); |
85
|
|
|
|
86
|
|
|
// load the entity manager and the registry processor |
87
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
88
|
|
|
|
89
|
|
|
// load the status of the actual import process |
90
|
|
|
$status = $registryProcessor->getAttribute($serial); |
91
|
|
|
|
92
|
|
|
// load the attribute set we've prepared initially |
93
|
|
|
$this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING]; |
94
|
|
|
$this->preloadEntityIds = $status[ProductRegistryKeys::PRE_LOADED_ENTITY_IDS]; |
95
|
|
|
|
96
|
|
|
// initialize the flag to decide copy images or not |
97
|
|
|
$this->setCopyImages($this->getConfiguration()->getParam(FileUploadConfigurationKeys::COPY_IMAGES)); |
|
|
|
|
98
|
|
|
|
99
|
|
|
// initialize media directory => can be absolute or relative |
100
|
|
|
if ($this->getConfiguration()->hasParam(FileUploadConfigurationKeys::MEDIA_DIRECTORY)) { |
101
|
|
|
$this->setMediaDir( |
102
|
|
|
$this->resolvePath( |
103
|
|
|
$this->getConfiguration()->getParam(FileUploadConfigurationKeys::MEDIA_DIRECTORY) |
104
|
|
|
) |
105
|
|
|
); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
// initialize images directory => can be absolute or relative |
109
|
|
|
if ($this->getConfiguration()->hasParam(FileUploadConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
110
|
|
|
$this->setImagesFileDir( |
111
|
|
|
$this->resolvePath( |
112
|
|
|
$this->getConfiguration()->getParam(FileUploadConfigurationKeys::IMAGES_FILE_DIRECTORY) |
113
|
|
|
) |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Return the entity ID for the passed SKU. |
120
|
|
|
* |
121
|
|
|
* @param string $sku The SKU to return the entity ID for |
122
|
|
|
* |
123
|
|
|
* @return integer The mapped entity ID |
124
|
|
|
* @throws \Exception Is thrown if the SKU is not mapped yet |
125
|
|
|
*/ |
126
|
|
|
public function mapSkuToEntityId($sku) |
127
|
|
|
{ |
128
|
|
|
|
129
|
|
|
// query weather or not the SKU has been mapped |
130
|
|
|
if (isset($this->skuEntityIdMapping[$sku])) { |
131
|
|
|
return $this->skuEntityIdMapping[$sku]; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// throw an exception if the SKU has not been mapped yet |
135
|
|
|
throw new \Exception(sprintf('Found not mapped SKU %s', $sku)); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
/** |
139
|
|
|
* Return the entity ID for the passed SKU based on the preload entity IDs. |
140
|
|
|
* |
141
|
|
|
* @param string $sku The SKU to return the entity ID for |
142
|
|
|
* |
143
|
|
|
* @return integer The mapped entity ID |
144
|
|
|
* @throws \Exception Is thrown if the SKU is not mapped yet |
145
|
|
|
*/ |
146
|
|
|
public function mapSkuToPreloadEntityId($sku) |
147
|
|
|
{ |
148
|
|
|
|
149
|
|
|
// query weather or not the SKU has been mapped |
150
|
|
|
if (isset($this->preloadEntityIds[$sku])) { |
151
|
|
|
return $this->preloadEntityIds[$sku]; |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
// throw an exception if the SKU has not been mapped yet |
155
|
|
|
throw new \Exception(sprintf('Found not mapped SKU %s within preload entities', $sku)); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Set's the name of the created image. |
160
|
|
|
* |
161
|
|
|
* @param string $parentImage The name of the created image |
162
|
|
|
* |
163
|
|
|
* @return void |
164
|
|
|
*/ |
165
|
|
|
public function setParentImage($parentImage) |
166
|
|
|
{ |
167
|
|
|
$this->parentImage = $parentImage; |
|
|
|
|
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Return's the name of the created image. |
172
|
|
|
* |
173
|
|
|
* @return string The name of the created image |
174
|
|
|
*/ |
175
|
|
|
public function getParentImage() |
176
|
|
|
{ |
177
|
|
|
return $this->parentImage; |
178
|
|
|
} |
179
|
|
|
} |
180
|
|
|
|
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: