1 | <?php |
||
36 | class MediaGalleryObserver extends AbstractProductImportObserver |
||
37 | { |
||
38 | |||
39 | /** |
||
40 | * The ID of the parent product the media is related to. |
||
41 | * |
||
42 | * @var integer |
||
43 | */ |
||
44 | protected $parentId; |
||
45 | |||
46 | /** |
||
47 | * The ID of the persisted media gallery entity. |
||
48 | * |
||
49 | * @var integer |
||
50 | */ |
||
51 | protected $valueId; |
||
52 | |||
53 | /** |
||
54 | * Process the observer's business logic. |
||
55 | * |
||
56 | * @return array The processed row |
||
57 | */ |
||
58 | protected function process() |
||
85 | |||
86 | /** |
||
87 | * Prepare the product media gallery that has to be persisted. |
||
88 | * |
||
89 | * @return array The prepared product media gallery attributes |
||
90 | */ |
||
91 | protected function prepareProductMediaGalleryAttributes() |
||
110 | |||
111 | /** |
||
112 | * Prepare the product media gallery value to entity that has to be persisted. |
||
113 | * |
||
114 | * @return array The prepared product media gallery value to entity attributes |
||
115 | */ |
||
116 | protected function prepareProductMediaGalleryValueToEntityAttributes() |
||
127 | |||
128 | /** |
||
129 | * Initialize the product media gallery with the passed attributes and returns an instance. |
||
130 | * |
||
131 | * @param array $attr The product media gallery attributes |
||
132 | * |
||
133 | * @return array The initialized product media gallery |
||
134 | */ |
||
135 | protected function initializeProductMediaGallery(array $attr) |
||
139 | |||
140 | /** |
||
141 | * Initialize the product media gallery value to entity with the passed attributes and returns an instance. |
||
142 | * |
||
143 | * @param array $attr The product media gallery value to entity attributes |
||
144 | * |
||
145 | * @return array|null The initialized product media gallery value to entity, or NULL if the product media gallery value to entity already exists |
||
146 | */ |
||
147 | protected function initializeProductMediaGalleryValueToEntity(array $attr) |
||
151 | |||
152 | /** |
||
153 | * Map's the passed SKU of the parent product to it's PK. |
||
154 | * |
||
155 | * @param string $parentSku The SKU of the parent product |
||
156 | * |
||
157 | * @return integer The primary key used to create relations |
||
158 | */ |
||
159 | protected function mapParentSku($parentSku) |
||
163 | |||
164 | /** |
||
165 | * Return's the name of the created image. |
||
166 | * |
||
167 | * @return string The name of the created image |
||
168 | */ |
||
169 | protected function getParentImage() |
||
173 | |||
174 | /** |
||
175 | * Return's TRUE if the passed image is the parent one. |
||
176 | * |
||
177 | * @param string $image The imageD to check |
||
178 | * |
||
179 | * @return boolean TRUE if the passed image is the parent one |
||
180 | */ |
||
181 | protected function isParentImage($image) |
||
185 | |||
186 | /** |
||
187 | * Set's the value ID of the created media gallery entry. |
||
188 | * |
||
189 | * @param integer $parentValueId The ID of the created media gallery entry |
||
190 | * |
||
191 | * @return void |
||
192 | */ |
||
193 | protected function setParentValueId($parentValueId) |
||
197 | |||
198 | /** |
||
199 | * Return the entity ID for the passed SKU. |
||
200 | * |
||
201 | * @param string $sku The SKU to return the entity ID for |
||
202 | * |
||
203 | * @return integer The mapped entity ID |
||
204 | * @throws \Exception Is thrown if the SKU is not mapped yet |
||
205 | */ |
||
206 | protected function mapSkuToEntityId($sku) |
||
210 | |||
211 | /** |
||
212 | * Set's the ID of the parent product to relate the variant with. |
||
213 | * |
||
214 | * @param integer $parentId The ID of the parent product |
||
215 | * |
||
216 | * @return void |
||
217 | */ |
||
218 | protected function setParentId($parentId) |
||
222 | |||
223 | /** |
||
224 | * Reset the position counter to 1. |
||
225 | * |
||
226 | * @return void |
||
227 | */ |
||
228 | protected function resetPositionCounter() |
||
232 | |||
233 | /** |
||
234 | * Persist's the passed product media gallery data and return's the ID. |
||
235 | * |
||
236 | * @param array $productMediaGallery The product media gallery data to persist |
||
237 | * |
||
238 | * @return string The ID of the persisted entity |
||
239 | */ |
||
240 | protected function persistProductMediaGallery($productMediaGallery) |
||
244 | |||
245 | /** |
||
246 | * Persist's the passed product media gallery value to entity data. |
||
247 | * |
||
248 | * @param array $productMediaGalleryValueToEntity The product media gallery value to entity data to persist |
||
249 | * |
||
250 | * @return void |
||
251 | */ |
||
252 | protected function persistProductMediaGalleryValueToEntity($productMediaGalleryValueToEntity) |
||
256 | } |
||
257 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.