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 | * Set's the prepared URL key. |
||
77 | * |
||
78 | * @param string $urlKey The prepared URL key |
||
79 | * |
||
80 | * @return void |
||
81 | */ |
||
82 | 3 | protected function setUrlKey($urlKey) |
|
86 | |||
87 | /** |
||
88 | * Return's the prepared URL key. |
||
89 | * |
||
90 | * @return string The prepared URL key |
||
91 | */ |
||
92 | 3 | protected function getUrlKey() |
|
96 | |||
97 | /** |
||
98 | * Set's the actual category ID to process. |
||
99 | * |
||
100 | * @param integer $categoryId The category ID |
||
101 | * |
||
102 | * @return void |
||
103 | */ |
||
104 | 3 | protected function setCategoryId($categoryId) |
|
108 | |||
109 | /** |
||
110 | * Return's the actual category ID to process. |
||
111 | * |
||
112 | * @return integer The category ID |
||
113 | */ |
||
114 | 3 | protected function getCategoryId() |
|
118 | |||
119 | /** |
||
120 | * Set's the actual entity ID to process. |
||
121 | * |
||
122 | * @param integer $entityId The entity ID |
||
123 | * |
||
124 | * @return void |
||
125 | */ |
||
126 | 3 | protected function setEntityId($entityId) |
|
130 | |||
131 | /** |
||
132 | * Return's the actual entity ID to process. |
||
133 | * |
||
134 | * @return integer The entity ID |
||
135 | */ |
||
136 | 3 | protected function getEntityId() |
|
140 | |||
141 | /** |
||
142 | * Process the observer's business logic. |
||
143 | * |
||
144 | * @return void |
||
145 | */ |
||
146 | 3 | protected function process() |
|
173 | |||
174 | /** |
||
175 | * Initialize the category product with the passed attributes and returns an instance. |
||
176 | * |
||
177 | * @param array $attr The category product attributes |
||
178 | * |
||
179 | * @return array The initialized category product |
||
180 | */ |
||
181 | 2 | protected function initializeUrlRewrite(array $attr) |
|
185 | |||
186 | /** |
||
187 | * Prepare's the URL rewrites that has to be created/updated. |
||
188 | * |
||
189 | * @return void |
||
190 | */ |
||
191 | 3 | protected function prepareUrlRewrites() |
|
214 | |||
215 | /** |
||
216 | * Prepare's and set's the URL key from the passed row of the CSV file. |
||
217 | * |
||
218 | * @return boolean TRUE, if the URL key has been prepared, else FALSE |
||
219 | */ |
||
220 | 3 | protected function prepareUrlKey() |
|
255 | |||
256 | /** |
||
257 | * Prepare the attributes of the entity that has to be persisted. |
||
258 | * |
||
259 | * @return array The prepared attributes |
||
260 | */ |
||
261 | 3 | protected function prepareAttributes() |
|
294 | |||
295 | /** |
||
296 | * Prepare's the target path for a URL rewrite. |
||
297 | * |
||
298 | * @param array $category The categroy with the URL path |
||
299 | * |
||
300 | * @return string The target path |
||
301 | */ |
||
302 | 3 | protected function prepareTargetPath(array $category) |
|
318 | |||
319 | /** |
||
320 | * Prepare's the request path for a URL rewrite or the target path for a 301 redirect. |
||
321 | * |
||
322 | * @param array $category The categroy with the URL path |
||
323 | * |
||
324 | * @return string The request path |
||
325 | */ |
||
326 | 3 | protected function prepareRequestPath(array $category) |
|
339 | |||
340 | /** |
||
341 | * Prepare's the URL rewrite's metadata with the passed category values. |
||
342 | * |
||
343 | * @param array $category The category used for preparation |
||
344 | * |
||
345 | * @return array The metadata |
||
346 | */ |
||
347 | 3 | protected function prepareMetadata(array $category) |
|
364 | |||
365 | /** |
||
366 | * Initialize's and return's the URL key filter. |
||
367 | * |
||
368 | * @return \TechDivision\Import\Product\Utils\ConvertLiteralUrl The URL key filter |
||
369 | */ |
||
370 | protected function getUrlKeyFilter() |
||
374 | |||
375 | /** |
||
376 | * Convert's the passed string into a valid URL key. |
||
377 | * |
||
378 | * @param string $string The string to be converted, e. g. the product name |
||
379 | * |
||
380 | * @return string The converted string as valid URL key |
||
381 | */ |
||
382 | protected function convertNameToUrlKey($string) |
||
386 | |||
387 | /** |
||
388 | * Return's the root category for the actual view store. |
||
389 | * |
||
390 | * @return array The store's root category |
||
391 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
392 | */ |
||
393 | 3 | protected function getRootCategory() |
|
397 | |||
398 | /** |
||
399 | * Return's TRUE if the passed category IS the root category, else FALSE. |
||
400 | * |
||
401 | * @param array $category The category to query |
||
402 | * |
||
403 | * @return boolean TRUE if the passed category IS the root category |
||
404 | */ |
||
405 | 3 | protected function isRootCategory(array $category) |
|
414 | |||
415 | /** |
||
416 | * Return's the store ID of the actual row, or of the default store |
||
417 | * if no store view code is set in the CSV file. |
||
418 | * |
||
419 | * @param string|null $default The default store view code to use, if no store view code is set in the CSV file |
||
420 | * |
||
421 | * @return integer The ID of the actual store |
||
422 | * @throws \Exception Is thrown, if the store with the actual code is not available |
||
423 | */ |
||
424 | 3 | protected function getRowStoreId($default = null) |
|
428 | |||
429 | /** |
||
430 | * Return's the list with category IDs the product is related with. |
||
431 | * |
||
432 | * @return array The product's category IDs |
||
433 | */ |
||
434 | 3 | protected function getProductCategoryIds() |
|
438 | |||
439 | /** |
||
440 | * Return's the category with the passed ID. |
||
441 | * |
||
442 | * @param integer $categoryId The ID of the category to return |
||
443 | * |
||
444 | * @return array The category data |
||
445 | */ |
||
446 | 3 | protected function getCategory($categoryId) |
|
450 | |||
451 | /** |
||
452 | * Persist's the URL write with the passed data. |
||
453 | * |
||
454 | * @param array $row The URL rewrite to persist |
||
455 | * |
||
456 | * @return void |
||
457 | */ |
||
458 | 3 | protected function persistUrlRewrite($row) |
|
462 | |||
463 | /** |
||
464 | * Return's the PK to create the product => attribute relation. |
||
465 | * |
||
466 | * @return integer The PK to create the relation with |
||
467 | */ |
||
468 | 3 | protected function getPrimaryKey() |
|
472 | } |
||
473 |