1 | <?php |
||
37 | class UrlRewriteObserver extends AbstractProductImportObserver |
||
38 | { |
||
39 | |||
40 | /** |
||
41 | * The entity type to load the URL rewrites for. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | const ENTITY_TYPE = 'product'; |
||
46 | |||
47 | /** |
||
48 | * The URL key from the CSV file column that has to be processed by the observer. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | protected $urlKey; |
||
53 | |||
54 | /** |
||
55 | * The actual category ID to process. |
||
56 | * |
||
57 | * @var integer |
||
58 | */ |
||
59 | protected $categoryId; |
||
60 | |||
61 | /** |
||
62 | * The actual entity ID to process. |
||
63 | * |
||
64 | * @var integer |
||
65 | */ |
||
66 | protected $entityId; |
||
67 | |||
68 | /** |
||
69 | * The array with the URL rewrites that has to be created. |
||
70 | * |
||
71 | * @var array |
||
72 | */ |
||
73 | protected $urlRewrites = array(); |
||
74 | |||
75 | /** |
||
76 | * Process the observer's business logic. |
||
77 | * |
||
78 | * @return void |
||
79 | */ |
||
80 | 3 | protected function process() |
|
114 | |||
115 | /** |
||
116 | * Initialize the category product with the passed attributes and returns an instance. |
||
117 | * |
||
118 | * @param array $attr The category product attributes |
||
119 | * |
||
120 | * @return array The initialized category product |
||
121 | */ |
||
122 | 2 | protected function initializeUrlRewrite(array $attr) |
|
126 | |||
127 | /** |
||
128 | * Initialize the URL rewrite product => category relation with the passed attributes |
||
129 | * and returns an instance. |
||
130 | * |
||
131 | * @param array $attr The URL rewrite product => category relation attributes |
||
132 | * |
||
133 | * @return array The initialized URL rewrite product => category relation |
||
134 | */ |
||
135 | 3 | protected function initializeUrlRewriteProductCategory($attr) |
|
139 | |||
140 | /** |
||
141 | * Prepare's the URL rewrites that has to be created/updated. |
||
142 | * |
||
143 | * @return void |
||
144 | */ |
||
145 | 3 | protected function prepareUrlRewrites() |
|
168 | |||
169 | /** |
||
170 | * Prepare's and set's the URL key from the passed row of the CSV file. |
||
171 | * |
||
172 | * @return boolean TRUE, if the URL key has been prepared, else FALSE |
||
173 | */ |
||
174 | 3 | protected function prepareUrlKey() |
|
209 | |||
210 | /** |
||
211 | * Prepare the attributes of the entity that has to be persisted. |
||
212 | * |
||
213 | * @return array The prepared attributes |
||
214 | */ |
||
215 | 3 | protected function prepareAttributes() |
|
244 | |||
245 | /** |
||
246 | * Prepare's the URL rewrite product => category relation attributes. |
||
247 | * |
||
248 | * @return arry The prepared attributes |
||
249 | */ |
||
250 | 3 | protected function prepareUrlRewriteProductCategoryAttributes() |
|
262 | |||
263 | /** |
||
264 | * Prepare's the target path for a URL rewrite. |
||
265 | * |
||
266 | * @param array $category The categroy with the URL path |
||
267 | * |
||
268 | * @return string The target path |
||
269 | */ |
||
270 | 3 | protected function prepareTargetPath(array $category) |
|
286 | |||
287 | /** |
||
288 | * Prepare's the request path for a URL rewrite or the target path for a 301 redirect. |
||
289 | * |
||
290 | * @param array $category The categroy with the URL path |
||
291 | * |
||
292 | * @return string The request path |
||
293 | */ |
||
294 | 3 | protected function prepareRequestPath(array $category) |
|
307 | |||
308 | /** |
||
309 | * Prepare's the URL rewrite's metadata with the passed category values. |
||
310 | * |
||
311 | * @param array $category The category used for preparation |
||
312 | * |
||
313 | * @return array The metadata |
||
314 | */ |
||
315 | 3 | protected function prepareMetadata(array $category) |
|
332 | |||
333 | /** |
||
334 | * Initialize's and return's the URL key filter. |
||
335 | * |
||
336 | * @return \TechDivision\Import\Product\Utils\ConvertLiteralUrl The URL key filter |
||
337 | */ |
||
338 | protected function getUrlKeyFilter() |
||
342 | |||
343 | /** |
||
344 | * Convert's the passed string into a valid URL key. |
||
345 | * |
||
346 | * @param string $string The string to be converted, e. g. the product name |
||
347 | * |
||
348 | * @return string The converted string as valid URL key |
||
349 | */ |
||
350 | protected function convertNameToUrlKey($string) |
||
354 | |||
355 | /** |
||
356 | * Return's the root category for the actual view store. |
||
357 | * |
||
358 | * @return array The store's root category |
||
359 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
360 | */ |
||
361 | 3 | protected function getRootCategory() |
|
365 | |||
366 | /** |
||
367 | * Return's TRUE if the passed category IS the root category, else FALSE. |
||
368 | * |
||
369 | * @param array $category The category to query |
||
370 | * |
||
371 | * @return boolean TRUE if the passed category IS the root category |
||
372 | */ |
||
373 | 3 | protected function isRootCategory(array $category) |
|
382 | |||
383 | /** |
||
384 | * Return's the store ID of the actual row, or of the default store |
||
385 | * if no store view code is set in the CSV file. |
||
386 | * |
||
387 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
388 | * |
||
389 | * @return integer The ID of the actual store |
||
390 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
391 | */ |
||
392 | 3 | protected function getRowStoreId($default = null) |
|
396 | |||
397 | /** |
||
398 | * Return's the list with category IDs the product is related with. |
||
399 | * |
||
400 | * @return array The product's category IDs |
||
401 | */ |
||
402 | 3 | protected function getProductCategoryIds() |
|
406 | |||
407 | /** |
||
408 | * Return's the category with the passed ID. |
||
409 | * |
||
410 | * @param integer $categoryId The ID of the category to return |
||
411 | * |
||
412 | * @return array The category data |
||
413 | */ |
||
414 | 3 | protected function getCategory($categoryId) |
|
418 | |||
419 | /** |
||
420 | * Persist's the URL rewrite with the passed data. |
||
421 | * |
||
422 | * @param array $row The URL rewrite to persist |
||
423 | * |
||
424 | * @return string The ID of the persisted entity |
||
425 | */ |
||
426 | 3 | protected function persistUrlRewrite($row) |
|
430 | |||
431 | /** |
||
432 | * Persist's the URL rewrite product => category relation with the passed data. |
||
433 | * |
||
434 | * @param array $row The URL rewrite product => category relation to persist |
||
435 | * |
||
436 | * @return void |
||
437 | */ |
||
438 | 3 | protected function persistUrlRewriteProductCategory($row) |
|
442 | |||
443 | /** |
||
444 | * Return's the PK to create the product => attribute relation. |
||
445 | * |
||
446 | * @return integer The PK to create the relation with |
||
447 | */ |
||
448 | 3 | protected function getPrimaryKey() |
|
452 | } |
||
453 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.