@@ -449,9 +449,8 @@ public function getUsedProductAttributes($product)
449
449
/**
450
450
* @param Product $product
451
451
*
452
- * @return string
453
- * @throws \InvalidArgumentException When it's impossible to generate cache
454
- * ID for the product.
452
+ * @return string|null Null is returned when it's impossible to generate
453
+ * cache ID for the product.
455
454
*/
456
455
private function generateConfigurableAttributesCacheId (
457
456
Product $ product
@@ -461,9 +460,7 @@ private function generateConfigurableAttributesCacheId(
461
460
/** @var string|null $productId */
462
461
$ productId = $ product ->getData ($ metadata ->getLinkField ());
463
462
if (!$ productId ) {
464
- throw new \InvalidArgumentException (
465
- 'Impossible to generate cache ID for the product '
466
- );
463
+ return null ;
467
464
}
468
465
469
466
return __CLASS__ . $ productId . '_ ' . $ product ->getStoreId ();
@@ -474,18 +471,14 @@ private function generateConfigurableAttributesCacheId(
474
471
*
475
472
* @param Product $product
476
473
*
477
- * @return ProductTypeConfigurable\Attribute\Collection
478
- * @throws \RuntimeException When can't find the cached attributes .
474
+ * @return ProductTypeConfigurable\Attribute\Collection|null Null when
475
+ * attributes for given product cannot be found in cache .
479
476
*/
480
477
private function findCachedConfigurableAttributes (
481
478
Product $ product
482
479
) {
483
480
//Trying to load attributes from cache.
484
- try {
485
- $ cacheId = $ this ->generateConfigurableAttributesCacheId ($ product );
486
- } catch (\Exception $ exception ) {
487
- $ cacheId = null ;
488
- }
481
+ $ cacheId = $ this ->generateConfigurableAttributesCacheId ($ product );
489
482
if ($ cacheId ) {
490
483
$ configurableAttributes = $ this ->getCache ()->load ($ cacheId );
491
484
$ configurableAttributes
@@ -520,9 +513,7 @@ private function findCachedConfigurableAttributes(
520
513
return $ configurableAttributes ;
521
514
}
522
515
523
- throw new \RuntimeException (
524
- 'Couldn \'t find attributes for configurable product. '
525
- );
516
+ return null ;
526
517
}
527
518
528
519
/**
@@ -544,11 +535,12 @@ private function cacheConfigurableAttributes(
544
535
/** @var string $productHashId */
545
536
$ productHashId = spl_object_hash ($ product );
546
537
547
- if ($ productId ) {
538
+ $ cacheId = $ this ->generateConfigurableAttributesCacheId ($ product );
539
+ if ($ productId && $ cacheId ) {
548
540
$ this ->getCache ()
549
541
->save (
550
542
serialize ($ collection ),
551
- $ this -> generateConfigurableAttributesCacheId ( $ product ) ,
543
+ $ cacheId ,
552
544
array_merge (
553
545
$ product ->getIdentities (),
554
546
[self ::TYPE_CODE . '_ ' . $ productId ]
@@ -574,10 +566,10 @@ public function getConfigurableAttributes($product)
574
566
['group ' => 'CONFIGURABLE ' , 'method ' => __METHOD__ ]
575
567
);
576
568
if (!$ product ->hasData ($ this ->_configurableAttributes )) {
577
- try {
578
- $ configurableAttributes
569
+ $ configurableAttributes
579
570
= $ this ->findCachedConfigurableAttributes ($ product );
580
- } catch (\RuntimeException $ exception ) {
571
+
572
+ if (!$ configurableAttributes ) {
581
573
//Couldn't find attributes in cache, loading.
582
574
$ configurableAttributes
583
575
= $ this ->getConfigurableAttributeCollection ($ product );
0 commit comments