|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Media\Subjects\MediaSubject |
|
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-product-media |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Media\Subjects; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\RegistryKeys; |
|
24
|
|
|
use TechDivision\Import\Subjects\FileUploadTrait; |
|
25
|
|
|
use TechDivision\Import\Subjects\FileUploadSubjectInterface; |
|
26
|
|
|
use TechDivision\Import\Product\Subjects\AbstractProductSubject; |
|
27
|
|
|
use TechDivision\Import\Product\Media\Utils\ConfigurationKeys; |
|
28
|
|
|
use TechDivision\Import\Product\Media\Exceptions\MapSkuToEntityIdException; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* The subject implementation for the product media handling. |
|
32
|
|
|
* |
|
33
|
|
|
* @author Tim Wagner <[email protected]> |
|
34
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
35
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
36
|
|
|
* @link https://github.com/techdivision/import-product-media |
|
37
|
|
|
* @link http://www.techdivision.com |
|
38
|
|
|
*/ |
|
39
|
|
|
class MediaSubject extends AbstractProductSubject implements FileUploadSubjectInterface |
|
40
|
|
|
{ |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* The trait that provides file upload functionality. |
|
44
|
|
|
* |
|
45
|
|
|
* @var \TechDivision\Import\Subjects\FileUploadTrait |
|
46
|
|
|
*/ |
|
47
|
|
|
use FileUploadTrait; |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* The ID of the parent product to relate the variant with. |
|
51
|
|
|
* |
|
52
|
|
|
* @var integer |
|
53
|
|
|
*/ |
|
54
|
|
|
protected $parentId; |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* The value ID of the created media gallery entry. |
|
58
|
|
|
* |
|
59
|
|
|
* @var integer |
|
60
|
|
|
*/ |
|
61
|
|
|
protected $parentValueId; |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* The Magento installation directory. |
|
65
|
|
|
* |
|
66
|
|
|
* @var string |
|
67
|
|
|
*/ |
|
68
|
|
|
protected $installationDir; |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* The position counter, if no position for the product media gallery value has been specified. |
|
72
|
|
|
* |
|
73
|
|
|
* @var integer |
|
74
|
|
|
*/ |
|
75
|
|
|
protected $positionCounter = 1; |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Intializes the previously loaded global data for exactly one variants. |
|
79
|
|
|
* |
|
80
|
|
|
* @param string $serial The serial of the actual import |
|
81
|
|
|
* |
|
82
|
|
|
* @return void |
|
83
|
|
|
*/ |
|
84
|
|
|
public function setUp($serial) |
|
85
|
|
|
{ |
|
86
|
|
|
|
|
87
|
|
|
// invoke parent method |
|
88
|
|
|
parent::setUp($serial); |
|
89
|
|
|
|
|
90
|
|
|
// load the entity manager and the registry processor |
|
91
|
|
|
$registryProcessor = $this->getRegistryProcessor(); |
|
92
|
|
|
|
|
93
|
|
|
// load the status of the actual import process |
|
94
|
|
|
$status = $registryProcessor->getAttribute(RegistryKeys::STATUS); |
|
95
|
|
|
|
|
96
|
|
|
// load the SKU => entity ID mapping |
|
97
|
|
|
$this->skuEntityIdMapping = $status[RegistryKeys::SKU_ENTITY_ID_MAPPING]; |
|
98
|
|
|
|
|
99
|
|
|
// initialize media directory => can be absolute or relative |
|
100
|
|
|
if ($this->getConfiguration()->hasParam(ConfigurationKeys::MEDIA_DIRECTORY)) { |
|
101
|
|
|
$this->setMediaDir( |
|
102
|
|
|
$this->resolvePath( |
|
103
|
|
|
$this->getConfiguration()->getParam(ConfigurationKeys::MEDIA_DIRECTORY) |
|
104
|
|
|
) |
|
105
|
|
|
); |
|
106
|
|
|
} |
|
107
|
|
|
|
|
108
|
|
|
// initialize images directory => can be absolute or relative |
|
109
|
|
|
if ($this->getConfiguration()->hasParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY)) { |
|
110
|
|
|
$this->setImagesFileDir( |
|
111
|
|
|
$this->resolvePath( |
|
112
|
|
|
$this->getConfiguration()->getParam(ConfigurationKeys::IMAGES_FILE_DIRECTORY) |
|
113
|
|
|
) |
|
114
|
|
|
); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
|
118
|
|
|
/** |
|
119
|
|
|
* Set's the ID of the parent product to relate the variant with. |
|
120
|
|
|
* |
|
121
|
|
|
* @param integer $parentId The ID of the parent product |
|
122
|
|
|
* |
|
123
|
|
|
* @return void |
|
124
|
|
|
*/ |
|
125
|
|
|
public function setParentId($parentId) |
|
126
|
|
|
{ |
|
127
|
|
|
$this->parentId = $parentId; |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
/** |
|
131
|
|
|
* Return's the ID of the parent product to relate the variant with. |
|
132
|
|
|
* |
|
133
|
|
|
* @return integer The ID of the parent product |
|
134
|
|
|
*/ |
|
135
|
|
|
public function getParentId() |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->parentId; |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
/** |
|
141
|
|
|
* Set's the value ID of the created media gallery entry. |
|
142
|
|
|
* |
|
143
|
|
|
* @param integer $parentValueId The ID of the created media gallery entry |
|
144
|
|
|
* |
|
145
|
|
|
* @return void |
|
146
|
|
|
*/ |
|
147
|
|
|
public function setParentValueId($parentValueId) |
|
148
|
|
|
{ |
|
149
|
|
|
$this->parentValueId = $parentValueId; |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Return's the value ID of the created media gallery entry. |
|
154
|
|
|
* |
|
155
|
|
|
* @return integer The ID of the created media gallery entry |
|
156
|
|
|
*/ |
|
157
|
|
|
public function getParentValueId() |
|
158
|
|
|
{ |
|
159
|
|
|
return $this->parentValueId; |
|
160
|
|
|
} |
|
161
|
|
|
|
|
162
|
|
|
/** |
|
163
|
|
|
* Reset the position counter to 1. |
|
164
|
|
|
* |
|
165
|
|
|
* @return void |
|
166
|
|
|
*/ |
|
167
|
|
|
public function resetPositionCounter() |
|
168
|
|
|
{ |
|
169
|
|
|
$this->positionCounter = 0; |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Returns the acutal value of the position counter and raise's it by one. |
|
174
|
|
|
* |
|
175
|
|
|
* @return integer The actual value of the position counter |
|
176
|
|
|
*/ |
|
177
|
|
|
public function raisePositionCounter() |
|
178
|
|
|
{ |
|
179
|
|
|
return $this->positionCounter++; |
|
180
|
|
|
} |
|
181
|
|
|
} |
|
182
|
|
|
|