Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like UrlRewriteObserver often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use UrlRewriteObserver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 42 | class UrlRewriteObserver extends AbstractProductImportObserver implements ObserverFactoryInterface |
||
| 43 | { |
||
| 44 | |||
| 45 | /** |
||
| 46 | * The entity type to load the URL rewrites for. |
||
| 47 | * |
||
| 48 | * @var string |
||
| 49 | */ |
||
| 50 | const ENTITY_TYPE = 'product'; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * The key for the category in the metadata. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | const CATEGORY_ID = 'category_id'; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * The URL key from the CSV file column that has to be processed by the observer. |
||
| 61 | * |
||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | protected $urlKey; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * The actual category ID to process. |
||
| 68 | * |
||
| 69 | * @var integer |
||
| 70 | */ |
||
| 71 | protected $categoryId; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * The actual entity ID to process. |
||
| 75 | * |
||
| 76 | * @var integer |
||
| 77 | */ |
||
| 78 | protected $entityId; |
||
| 79 | |||
| 80 | /** |
||
| 81 | * The ID of the recently created URL rewrite. |
||
| 82 | * |
||
| 83 | * @var integer |
||
| 84 | */ |
||
| 85 | protected $urlRewriteId; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * The array with the URL rewrites that has to be created. |
||
| 89 | * |
||
| 90 | * @var array |
||
| 91 | */ |
||
| 92 | protected $urlRewrites = array(); |
||
| 93 | |||
| 94 | /** |
||
| 95 | * The array with the category IDs related with the product. |
||
| 96 | * |
||
| 97 | * @var array |
||
| 98 | */ |
||
| 99 | protected $productCategoryIds = array(); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * The array with the root categories. |
||
| 103 | * |
||
| 104 | * @var array |
||
| 105 | */ |
||
| 106 | protected $rootCategories = array(); |
||
| 107 | |||
| 108 | /** |
||
| 109 | * The product bunch processor instance. |
||
| 110 | * |
||
| 111 | * @var \TechDivision\Import\Product\UrlRewrite\Services\ProductUrlRewriteProcessorInterface |
||
| 112 | */ |
||
| 113 | protected $productUrlRewriteProcessor; |
||
| 114 | |||
| 115 | /** |
||
| 116 | * Initialize the observer with the passed product URL rewrite processor instance. |
||
| 117 | * |
||
| 118 | * @param \TechDivision\Import\Product\UrlRewrite\Services\ProductUrlRewriteProcessorInterface $productUrlRewriteProcessor The product URL rewrite processor instance |
||
| 119 | */ |
||
| 120 | 5 | public function __construct(ProductUrlRewriteProcessorInterface $productUrlRewriteProcessor) |
|
| 121 | { |
||
| 122 | 5 | $this->productUrlRewriteProcessor = $productUrlRewriteProcessor; |
|
| 123 | 5 | } |
|
| 124 | |||
| 125 | /** |
||
| 126 | * Will be invoked by the observer visitor when a factory has been defined to create the observer instance. |
||
| 127 | * |
||
| 128 | * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance |
||
| 129 | * |
||
| 130 | * @return \TechDivision\Import\Observers\ObserverInterface The observer instance |
||
| 131 | */ |
||
| 132 | 5 | public function createObserver(SubjectInterface $subject) |
|
| 147 | |||
| 148 | /** |
||
| 149 | * Return's the product bunch processor instance. |
||
| 150 | * |
||
| 151 | * @return \TechDivision\Import\Product\Services\ProductBunchProcessorInterface The product bunch processor instance |
||
| 152 | */ |
||
| 153 | 3 | protected function getProductUrlRewriteProcessor() |
|
| 154 | { |
||
| 155 | 3 | return $this->productUrlRewriteProcessor; |
|
| 156 | } |
||
| 157 | |||
| 158 | /** |
||
| 159 | * Will be invoked by the action on the events the listener has been registered for. |
||
| 160 | * |
||
| 161 | * @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance |
||
| 162 | * |
||
| 163 | * @return array The modified row |
||
| 164 | * @throws \Exception Is thrown, if the product is not available or no URL key has been specified |
||
| 165 | * @see \TechDivision\Import\Observers\ObserverInterface::handle() |
||
| 166 | */ |
||
| 167 | 3 | public function handle(SubjectInterface $subject) |
|
| 168 | { |
||
| 169 | |||
| 170 | // initialize the row |
||
| 171 | 3 | $this->setSubject($subject); |
|
| 172 | 3 | $this->setRow($subject->getRow()); |
|
| 173 | |||
| 174 | // try to load the entity ID for the product with the passed SKU |
||
| 175 | 3 | if ($product = $this->loadProduct($sku = $this->getValue(ColumnKeys::SKU))) { |
|
| 176 | 3 | $this->setLastEntityId($this->entityId = $product[MemberNames::ENTITY_ID]); |
|
| 177 | View Code Duplication | } else { |
|
| 178 | // prepare a log message |
||
| 179 | $message = sprintf('Product with SKU "%s" can\'t be loaded to create URL rewrites', $sku); |
||
| 180 | // query whether or not we're in debug mode |
||
| 181 | if ($this->getSubject()->isDebugMode()) { |
||
| 182 | $this->getSubject()->getSystemLogger()->warning($message); |
||
| 183 | return $this->getRow(); |
||
| 184 | } else { |
||
| 185 | throw new \Exception($this->appendExceptionSuffix($message)); |
||
| 186 | } |
||
| 187 | } |
||
| 188 | |||
| 189 | // try to load the URL key |
||
| 190 | 3 | if ($this->hasValue(ColumnKeys::URL_KEY)) { |
|
| 191 | 3 | $this->urlKey = $this->getValue(ColumnKeys::URL_KEY); |
|
| 192 | View Code Duplication | } else { |
|
| 193 | // prepare a log message |
||
| 194 | $message = sprintf('Can\'t find a value in column "url_key" for product with SKU "%s"', $sku); |
||
| 195 | // query whether or not we're in debug mode |
||
| 196 | if ($this->getSubject()->isDebugMode()) { |
||
| 197 | $this->getSubject()->getSystemLogger()->warning($message); |
||
| 198 | return $this->getRow(); |
||
| 199 | } else { |
||
| 200 | throw new \Exception($this->appendExceptionSuffix($message)); |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | // initialize the store view code |
||
| 205 | 3 | $this->getSubject()->prepareStoreViewCode(); |
|
| 206 | |||
| 207 | // load the store view - if no store view has been set we use the admin store view as default |
||
| 208 | 3 | $storeViewCode = $this->getSubject()->getStoreViewCode(StoreViewCodes::ADMIN); |
|
| 209 | |||
| 210 | // query whether or not the row has already been processed |
||
| 211 | 3 | View Code Duplication | if ($this->storeViewHasBeenProcessed($sku, $storeViewCode)) { |
| 212 | // log a message |
||
| 213 | $this->getSubject() |
||
| 214 | ->getSystemLogger() |
||
| 215 | ->debug( |
||
| 216 | sprintf( |
||
| 217 | 'URL rewrites for SKU "%s" + store view code "%s" has already been processed', |
||
| 218 | $sku, |
||
| 219 | $storeViewCode |
||
| 220 | ) |
||
| 221 | ); |
||
| 222 | |||
| 223 | // return without creating any rewrites |
||
| 224 | return $this->getRow(); |
||
| 225 | }; |
||
| 226 | |||
| 227 | // stop processing as we don't want to create URL rewrites for the admin store view |
||
| 228 | 3 | View Code Duplication | if ($storeViewCode === StoreViewCodes::ADMIN) { |
| 229 | // log a message and return |
||
| 230 | $this->getSubject() |
||
| 231 | ->getSystemLogger() |
||
| 232 | ->debug( |
||
| 233 | sprintf( |
||
| 234 | 'Store with code "%s" is not active, no URL rewrites will be created for product with SKU "%s"', |
||
| 235 | $storeViewCode, |
||
| 236 | $sku |
||
| 237 | ) |
||
| 238 | ); |
||
| 239 | |||
| 240 | // return without creating any rewrites |
||
| 241 | return $this->getRow(); |
||
| 242 | } |
||
| 243 | |||
| 244 | // stop processing if the store is NOT active |
||
| 245 | 3 | View Code Duplication | if (!$this->getSubject()->storeIsActive($storeViewCode)) { |
| 246 | // log a message and return |
||
| 247 | $this->getSubject() |
||
| 248 | ->getSystemLogger() |
||
| 249 | ->debug( |
||
| 250 | sprintf( |
||
| 251 | 'Store with code "%s" is not active, no URL rewrites will be created for product with SKU "%s"', |
||
| 252 | $storeViewCode, |
||
| 253 | $sku |
||
| 254 | ) |
||
| 255 | ); |
||
| 256 | |||
| 257 | // return without creating any rewrites |
||
| 258 | return $this->getRow(); |
||
| 259 | } |
||
| 260 | |||
| 261 | // only map the visibility for the product row related to the default store view |
||
| 262 | 3 | if (!$this->hasBeenProcessed($sku)) { |
|
| 263 | 3 | $this->addEntityIdVisibilityIdMapping($this->getValue(ColumnKeys::VISIBILITY)); |
|
| 264 | } |
||
| 265 | |||
| 266 | // process the functionality and return the row |
||
| 267 | 3 | $this->process(); |
|
| 268 | |||
| 269 | // return the processed row |
||
| 270 | 3 | return $this->getRow(); |
|
| 271 | } |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Process the observer's business logic. |
||
| 275 | * |
||
| 276 | * @return void |
||
| 277 | */ |
||
| 278 | 3 | protected function process() |
|
| 279 | { |
||
| 280 | |||
| 281 | // prepare the URL rewrites |
||
| 282 | 3 | $this->prepareUrlRewrites(); |
|
| 283 | |||
| 284 | // iterate over the categories and create the URL rewrites |
||
| 285 | 3 | foreach ($this->urlRewrites as $categoryId => $urlRewrite) { |
|
| 286 | // initialize and persist the URL rewrite |
||
| 287 | 3 | if ($urlRewrite = $this->initializeUrlRewrite($urlRewrite)) { |
|
| 288 | // initialize URL rewrite and catagory ID |
||
| 289 | 3 | $this->categoryId = $categoryId; |
|
| 290 | |||
| 291 | try { |
||
| 292 | // persist the URL rewrite |
||
| 293 | 3 | $this->urlRewriteId = $this->persistUrlRewrite($urlRewrite); |
|
| 294 | |||
| 295 | /* |
||
| 296 | * Attention! Stop processing, if this is a root category, because Magento needs explicitly |
||
| 297 | * NO URL rewrite product category relation to render canonical and meta og:url tag! |
||
| 298 | */ |
||
| 299 | 3 | if ($this->isRootCategory($this->getCategory($categoryId))) { |
|
| 300 | 3 | continue; |
|
| 301 | } |
||
| 302 | |||
| 303 | // initialize and persist the URL rewrite product => category relation |
||
| 304 | 2 | $urlRewriteProductCategory = $this->initializeUrlRewriteProductCategory( |
|
| 305 | 2 | $this->prepareUrlRewriteProductCategoryAttributes() |
|
| 306 | ); |
||
| 307 | |||
| 308 | // persist the URL rewrite product category relation |
||
| 309 | 2 | $this->persistUrlRewriteProductCategory($urlRewriteProductCategory); |
|
| 310 | } catch (\Exception $e) { |
||
| 311 | // query whether or not debug mode has been enabled |
||
| 312 | View Code Duplication | if ($this->getSubject()->isDebugMode()) { |
|
| 313 | $this->getSubject() |
||
| 314 | ->getSystemLogger() |
||
| 315 | ->warning($this->getSubject()->appendExceptionSuffix($e->getMessage())); |
||
| 316 | } else { |
||
| 317 | 2 | throw $e; |
|
| 318 | } |
||
| 319 | } |
||
| 320 | } |
||
| 321 | } |
||
| 322 | 3 | } |
|
| 323 | |||
| 324 | /** |
||
| 325 | * Initialize the category product with the passed attributes and returns an instance. |
||
| 326 | * |
||
| 327 | * @param array $attr The category product attributes |
||
| 328 | * |
||
| 329 | * @return array The initialized category product |
||
| 330 | */ |
||
| 331 | 2 | protected function initializeUrlRewrite(array $attr) |
|
| 332 | { |
||
| 333 | 2 | return $attr; |
|
| 334 | } |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Initialize the URL rewrite product => category relation with the passed attributes |
||
| 338 | * and returns an instance. |
||
| 339 | * |
||
| 340 | * @param array $attr The URL rewrite product => category relation attributes |
||
| 341 | * |
||
| 342 | * @return array The initialized URL rewrite product => category relation |
||
| 343 | */ |
||
| 344 | 1 | protected function initializeUrlRewriteProductCategory($attr) |
|
| 345 | { |
||
| 346 | 1 | return $attr; |
|
| 347 | } |
||
| 348 | |||
| 349 | /** |
||
| 350 | * Prepare's the URL rewrites that has to be created/updated. |
||
| 351 | * |
||
| 352 | * @return void |
||
| 353 | */ |
||
| 354 | 3 | protected function prepareUrlRewrites() |
|
| 355 | { |
||
| 356 | |||
| 357 | // (re-)initialize the array for the URL rewrites and the product category IDs |
||
| 358 | 3 | $this->urlRewrites = array(); |
|
| 359 | 3 | $this->productCategoryIds = array(); |
|
| 360 | |||
| 361 | // do NOT create new URL rewrites, if the product is NOT visible (any more), BUT |
||
| 362 | // handle existing URL rewrites, e. g. to remove and clean up the URL rewrites |
||
| 363 | 3 | if (!$this->isVisible()) { |
|
| 364 | // log a message |
||
| 365 | $this->getSubject() |
||
| 366 | ->getSystemLogger() |
||
| 367 | ->debug( |
||
| 368 | sprintf( |
||
| 369 | 'Product with SKU "%s" is not visible, so no URL rewrites will be created', |
||
| 370 | $this->getValue(ColumnKeys::SKU) |
||
| 371 | ) |
||
| 372 | ); |
||
| 373 | |||
| 374 | // return without creating any rewrites |
||
| 375 | return; |
||
| 376 | } |
||
| 377 | |||
| 378 | // load the root category of the default store view (as we're in the |
||
| 379 | // default row and does not have a store view code), because we need |
||
| 380 | // that to create the default product URL rewrite |
||
| 381 | 3 | $rootCategory = $this->getRootCategory(); |
|
| 382 | |||
| 383 | // at least, add the root category ID to the category => product relations |
||
| 384 | 3 | $this->productCategoryIds[] = $rootCategory[MemberNames::ENTITY_ID]; |
|
| 385 | |||
| 386 | // load the store view code from the appropriate column |
||
| 387 | 3 | $storeViewCode = $this->getValue(ColumnKeys::STORE_VIEW_CODE); |
|
| 388 | |||
| 389 | // load the category paths from the import file |
||
| 390 | 3 | $paths = $this->getValue(ColumnKeys::CATEGORIES, array(), array($this, 'explode')); |
|
| 391 | |||
| 392 | // append the category => product relations found |
||
| 393 | 3 | foreach ($paths as $path) { |
|
| 394 | try { |
||
| 395 | // try to load the category for the given path |
||
| 396 | 2 | $category = $this->getCategoryByPath($path, $storeViewCode); |
|
| 397 | // resolve the product's categories recursively |
||
| 398 | 2 | $this->resolveCategoryIds($category[MemberNames::ENTITY_ID], true, $storeViewCode); |
|
| 399 | } catch (\Exception $e) { |
||
| 400 | // query whether or not debug mode has been enabled |
||
| 401 | View Code Duplication | if ($this->getSubject()->isDebugMode()) { |
|
| 402 | $this->getSubject() |
||
| 403 | ->getSystemLogger() |
||
| 404 | ->warning($this->getSubject()->appendExceptionSuffix($e->getMessage())); |
||
| 405 | } else { |
||
| 406 | 2 | throw $e; |
|
| 407 | } |
||
| 408 | } |
||
| 409 | } |
||
| 410 | |||
| 411 | // initialize the member varialbe with the category ID |
||
| 412 | // and prepare the attributes for each URL rewrite |
||
| 413 | 3 | foreach ($this->productCategoryIds as $this->categoryId) { |
|
| 414 | 3 | $this->urlRewrites[$this->categoryId] = $this->prepareAttributes($storeViewCode); |
|
| 415 | } |
||
| 416 | 3 | } |
|
| 417 | |||
| 418 | /** |
||
| 419 | * Resolve's the parent categories of the category with the passed ID and relate's |
||
| 420 | * it with the product with the passed ID, if the category is top level OR has the |
||
| 421 | * anchor flag set. |
||
| 422 | * |
||
| 423 | * @param integer $categoryId The ID of the category to resolve the parents |
||
| 424 | * @param boolean $topLevel TRUE if the passed category has top level, else FALSE |
||
| 425 | * @param string $storeViewCode The store view code to resolve the category IDs for |
||
| 426 | * |
||
| 427 | * @return void |
||
| 428 | */ |
||
| 429 | 2 | protected function resolveCategoryIds($categoryId, $topLevel = false, $storeViewCode = StoreViewCodes::ADMIN) |
|
| 430 | { |
||
| 431 | |||
| 432 | // load the data of the category with the passed ID |
||
| 433 | 2 | $category = $this->getCategory($categoryId, $storeViewCode); |
|
| 434 | |||
| 435 | // return immediately if this is a root category |
||
| 436 | 2 | if ($this->isRootCategory($category)) { |
|
| 437 | 2 | return; |
|
| 438 | } |
||
| 439 | |||
| 440 | // create the product category relation for the current category |
||
| 441 | 2 | $this->createProductCategoryRelation($category, $topLevel); |
|
| 442 | |||
| 443 | // try to resolve the parent category IDs |
||
| 444 | 2 | $this->resolveCategoryIds($category[MemberNames::PARENT_ID], false, $storeViewCode); |
|
| 445 | 2 | } |
|
| 446 | |||
| 447 | /** |
||
| 448 | * Adds the entity product relation if necessary. |
||
| 449 | * |
||
| 450 | * @param array $category The category to create the relation for |
||
| 451 | * @param boolean $topLevel Whether or not the category has top level |
||
| 452 | * |
||
| 453 | * @return void |
||
| 454 | */ |
||
| 455 | 4 | protected function createProductCategoryRelation($category, $topLevel) |
|
| 456 | { |
||
| 457 | |||
| 458 | // query whether or not the product has already been related |
||
| 459 | 4 | if (in_array($category[MemberNames::ENTITY_ID], $this->productCategoryIds)) { |
|
| 460 | return; |
||
| 461 | } |
||
| 462 | |||
| 463 | // load the backend configuration value for whether or not the catalog product rewrites should be generated |
||
| 464 | 4 | $generateCategoryRewrites = $this->getGenerateCategoryProductRewritesOptionValue(); |
|
| 465 | |||
| 466 | // abort if generating product categories is disabled and category is not root |
||
| 467 | 4 | if ($generateCategoryRewrites === false && $this->isRootCategory($category) === false) { |
|
| 468 | 1 | return; |
|
| 469 | } |
||
| 470 | |||
| 471 | // create relation if the category is top level or has the anchor flag set |
||
| 472 | 3 | if ($topLevel || (integer) $category[MemberNames::IS_ANCHOR] === 1) { |
|
| 473 | 3 | $this->productCategoryIds[] = $category[MemberNames::ENTITY_ID]; |
|
| 474 | 3 | return; |
|
| 475 | } |
||
| 476 | |||
| 477 | 2 | $this->getSubject() |
|
| 478 | 2 | ->getSystemLogger() |
|
| 479 | 2 | ->debug( |
|
| 480 | 2 | sprintf( |
|
| 481 | 2 | 'Don\'t create URL rewrite for category "%s" because of missing anchor flag', |
|
| 482 | 2 | $category[MemberNames::PATH] |
|
| 483 | ) |
||
| 484 | ); |
||
| 485 | 2 | } |
|
| 486 | |||
| 487 | /** |
||
| 488 | * Returns the option value for whether or not to generate product catalog rewrites as well. |
||
| 489 | * |
||
| 490 | * @return bool |
||
| 491 | */ |
||
| 492 | 4 | protected function getGenerateCategoryProductRewritesOptionValue() |
|
| 499 | |||
| 500 | /** |
||
| 501 | * Prepare the attributes of the entity that has to be persisted. |
||
| 502 | * |
||
| 503 | * @param string $storeViewCode The store view code to prepare the attributes for |
||
| 504 | * |
||
| 505 | * @return array The prepared attributes |
||
| 506 | */ |
||
| 507 | 3 | protected function prepareAttributes($storeViewCode) |
|
| 508 | { |
||
| 509 | |||
| 510 | // load the store ID to use |
||
| 511 | 3 | $storeId = $this->getSubject()->getRowStoreId(); |
|
| 512 | |||
| 513 | // load the category to create the URL rewrite for |
||
| 514 | 3 | $category = $this->getCategory($this->categoryId, $storeViewCode); |
|
| 515 | |||
| 516 | // initialize the values |
||
| 517 | 3 | $metadata = $this->prepareMetadata($category); |
|
| 518 | 3 | $targetPath = $this->prepareTargetPath($category); |
|
| 519 | 3 | $requestPath = $this->prepareRequestPath($category); |
|
| 520 | |||
| 521 | // return the prepared URL rewrite |
||
| 522 | 3 | return $this->initializeEntity( |
|
| 523 | array( |
||
| 524 | 3 | MemberNames::ENTITY_TYPE => UrlRewriteObserver::ENTITY_TYPE, |
|
| 525 | 3 | MemberNames::ENTITY_ID => $this->entityId, |
|
| 526 | 3 | MemberNames::REQUEST_PATH => $requestPath, |
|
| 527 | 3 | MemberNames::TARGET_PATH => $targetPath, |
|
| 528 | 3 | MemberNames::REDIRECT_TYPE => 0, |
|
| 529 | 3 | MemberNames::STORE_ID => $storeId, |
|
| 530 | MemberNames::DESCRIPTION => null, |
||
| 531 | 3 | MemberNames::IS_AUTOGENERATED => 1, |
|
| 532 | 3 | MemberNames::METADATA => $metadata ? json_encode($metadata) : null |
|
| 533 | ) |
||
| 534 | ); |
||
| 535 | } |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Prepare's the URL rewrite product => category relation attributes. |
||
| 539 | * |
||
| 540 | * @return array The prepared attributes |
||
| 541 | */ |
||
| 542 | 2 | protected function prepareUrlRewriteProductCategoryAttributes() |
|
| 543 | { |
||
| 544 | |||
| 545 | // return the prepared product |
||
| 546 | 2 | return $this->initializeEntity( |
|
| 547 | array( |
||
| 548 | 2 | MemberNames::PRODUCT_ID => $this->entityId, |
|
| 549 | 2 | MemberNames::CATEGORY_ID => $this->categoryId, |
|
| 550 | 2 | MemberNames::URL_REWRITE_ID => $this->urlRewriteId |
|
| 551 | ) |
||
| 552 | ); |
||
| 553 | } |
||
| 554 | |||
| 555 | /** |
||
| 556 | * Prepare's the target path for a URL rewrite. |
||
| 557 | * |
||
| 558 | * @param array $category The categroy with the URL path |
||
| 559 | * |
||
| 560 | * @return string The target path |
||
| 561 | */ |
||
| 562 | 3 | protected function prepareTargetPath(array $category) |
|
| 575 | |||
| 576 | /** |
||
| 577 | * Prepare's the request path for a URL rewrite or the target path for a 301 redirect. |
||
| 578 | * |
||
| 579 | * @param array $category The categroy with the URL path |
||
| 580 | * |
||
| 581 | * @return string The request path |
||
| 582 | * @throws \RuntimeException Is thrown, if the passed category has no or an empty value for attribute "url_path" |
||
| 583 | */ |
||
| 584 | 3 | protected function prepareRequestPath(array $category) |
|
| 585 | { |
||
| 586 | |||
| 611 | |||
| 612 | /** |
||
| 613 | * Prepare's the URL rewrite's metadata with the passed category values. |
||
| 614 | * |
||
| 615 | * @param array $category The category used for preparation |
||
| 616 | * |
||
| 617 | * @return array|null The metadata |
||
| 618 | */ |
||
| 619 | 3 | protected function prepareMetadata(array $category) |
|
| 636 | |||
| 637 | /** |
||
| 638 | * Query whether or not the actual entity is visible. |
||
| 639 | * |
||
| 640 | * @return boolean TRUE if the entity is visible, else FALSE |
||
| 641 | */ |
||
| 642 | 3 | protected function isVisible() |
|
| 646 | |||
| 647 | /** |
||
| 648 | * Return's the visibility for the passed entity ID, if it already has been mapped. The mapping will be created |
||
| 649 | * by calling <code>\TechDivision\Import\Product\Subjects\BunchSubject::getVisibilityIdByValue</code> which will |
||
| 650 | * be done by the <code>\TechDivision\Import\Product\Callbacks\VisibilityCallback</code>. |
||
| 651 | * |
||
| 652 | * @return integer The visibility ID |
||
| 653 | * @throws \Exception Is thrown, if the entity ID has not been mapped |
||
| 654 | * @see \TechDivision\Import\Product\Subjects\BunchSubject::getVisibilityIdByValue() |
||
| 655 | */ |
||
| 656 | 3 | protected function getEntityIdVisibilityIdMapping() |
|
| 660 | |||
| 661 | /** |
||
| 662 | * Return's the root category for the actual view store. |
||
| 663 | * |
||
| 664 | * @return array The store's root category |
||
| 665 | * @throws \Exception Is thrown if the root category for the passed store code is NOT available |
||
| 666 | */ |
||
| 667 | 3 | protected function getRootCategory() |
|
| 671 | |||
| 672 | /** |
||
| 673 | * Return's TRUE if the passed category IS the root category, else FALSE. |
||
| 674 | * |
||
| 675 | * @param array $category The category to query |
||
| 676 | * |
||
| 677 | * @return boolean TRUE if the passed category IS the root category |
||
| 678 | */ |
||
| 679 | 3 | protected function isRootCategory(array $category) |
|
| 683 | |||
| 684 | /** |
||
| 685 | * Return's the category with the passed path. |
||
| 686 | * |
||
| 687 | * @param string $path The path of the category to return |
||
| 688 | * @param string $storeViewCode The store view code of the category to return |
||
| 689 | * |
||
| 690 | * @return array The category |
||
| 691 | */ |
||
| 692 | 2 | protected function getCategoryByPath($path, $storeViewCode = StoreViewCodes::ADMIN) |
|
| 696 | |||
| 697 | /** |
||
| 698 | * Return's the category with the passed ID. |
||
| 699 | * |
||
| 700 | * @param integer $categoryId The ID of the category to return |
||
| 701 | * @param string $storeViewCode The store view code of category to return |
||
| 702 | * |
||
| 703 | * @return array The category data |
||
| 704 | */ |
||
| 705 | 2 | protected function getCategory($categoryId, $storeViewCode = StoreViewCodes::ADMIN) |
|
| 709 | |||
| 710 | /** |
||
| 711 | * Persist's the URL rewrite with the passed data. |
||
| 712 | * |
||
| 713 | * @param array $row The URL rewrite to persist |
||
| 714 | * |
||
| 715 | * @return string The ID of the persisted entity |
||
| 716 | */ |
||
| 717 | 3 | protected function persistUrlRewrite($row) |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Persist's the URL rewrite product => category relation with the passed data. |
||
| 724 | * |
||
| 725 | * @param array $row The URL rewrite product => category relation to persist |
||
| 726 | * |
||
| 727 | * @return void |
||
| 728 | */ |
||
| 729 | 2 | protected function persistUrlRewriteProductCategory($row) |
|
| 733 | |||
| 734 | /** |
||
| 735 | * Queries whether or not the passed SKU and store view code has already been processed. |
||
| 736 | * |
||
| 737 | * @param string $sku The SKU to check been processed |
||
| 738 | * @param string $storeViewCode The store view code to check been processed |
||
| 739 | * |
||
| 740 | * @return boolean TRUE if the SKU and store view code has been processed, else FALSE |
||
| 741 | */ |
||
| 742 | 3 | protected function storeViewHasBeenProcessed($sku, $storeViewCode) |
|
| 746 | |||
| 747 | /** |
||
| 748 | * Add the entity ID => visibility mapping for the actual entity ID. |
||
| 749 | * |
||
| 750 | * @param string $visibility The visibility of the actual entity to map |
||
| 751 | * |
||
| 752 | * @return void |
||
| 753 | */ |
||
| 754 | 3 | protected function addEntityIdVisibilityIdMapping($visibility) |
|
| 758 | |||
| 759 | /** |
||
| 760 | * Set's the ID of the product that has been created recently. |
||
| 761 | * |
||
| 762 | * @param string $lastEntityId The entity ID |
||
| 763 | * |
||
| 764 | * @return void |
||
| 765 | */ |
||
| 766 | 3 | protected function setLastEntityId($lastEntityId) |
|
| 770 | |||
| 771 | /** |
||
| 772 | * Load's and return's the product with the passed SKU. |
||
| 773 | * |
||
| 774 | * @param string $sku The SKU of the product to load |
||
| 775 | * |
||
| 776 | * @return array The product |
||
| 777 | */ |
||
| 778 | 3 | protected function loadProduct($sku) |
|
| 782 | } |
||
| 783 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.