@@ -186,7 +186,7 @@ class Configurable extends AbstractType
186
186
private $ salableProcessor ;
187
187
188
188
/**
189
- * Cache attributes of products without and ID here.
189
+ * Cache attributes of products without IDs here.
190
190
*
191
191
* @var ProductTypeConfigurable\Attribute\Collection[] Where keys are
192
192
* objects' hashes and value are attributes.
@@ -480,42 +480,44 @@ private function generateConfigurableAttributesCacheId(
480
480
private function findCachedConfigurableAttributes (
481
481
Product $ product
482
482
) {
483
+ //Trying to load attributes from cache.
483
484
try {
484
- //Trying to load attributes from cache.
485
485
$ cacheId = $ this ->generateConfigurableAttributesCacheId ($ product );
486
+ } catch (\Exception $ exception ) {
487
+ $ cacheId = null ;
488
+ }
489
+ if ($ cacheId ) {
486
490
$ configurableAttributes = $ this ->getCache ()->load ($ cacheId );
487
491
$ configurableAttributes
488
492
= $ this ->hasCacheData ($ configurableAttributes );
489
- if (! $ configurableAttributes ) {
490
- throw new \ RuntimeException () ;
493
+ if ($ configurableAttributes ) {
494
+ return $ configurableAttributes ;
491
495
}
496
+ }
492
497
493
- return $ configurableAttributes ;
494
- } catch (\Exception $ exception ) {
495
- //Failed, trying local cache.
496
- $ productHashId = spl_object_hash ($ product );
497
- if (
498
+ //Failed, trying local cache.
499
+ $ productHashId = spl_object_hash ($ product );
500
+ if (
498
501
array_key_exists (
499
502
$ productHashId ,
500
503
$ this ->configurableAttributesLocalCache
501
504
)
502
- ) {
503
- $ configurableAttributes
504
- = $ this ->configurableAttributesLocalCache [$ productHashId ];
505
- //If product has ID then caching attributes for further use.
506
- $ metadata = $ this ->getMetadataPool ()
507
- ->getMetadata (ProductInterface::class);
508
- /** @var string|null $productId */
509
- $ productId = $ product ->getData ($ metadata ->getLinkField ());
510
- if ($ productId ) {
511
- $ this ->cacheConfigurableAttributes (
512
- $ product ,
513
- $ configurableAttributes
514
- );
515
- }
516
-
517
- return $ configurableAttributes ;
505
+ ) {
506
+ $ configurableAttributes
507
+ = $ this ->configurableAttributesLocalCache [$ productHashId ];
508
+ //If product has ID then caching attributes for further use.
509
+ $ metadata = $ this ->getMetadataPool ()
510
+ ->getMetadata (ProductInterface::class);
511
+ /** @var string|null $productId */
512
+ $ productId = $ product ->getData ($ metadata ->getLinkField ());
513
+ if ($ productId ) {
514
+ $ this ->cacheConfigurableAttributes (
515
+ $ product ,
516
+ $ configurableAttributes
517
+ );
518
518
}
519
+
520
+ return $ configurableAttributes ;
519
521
}
520
522
521
523
throw new \RuntimeException (
0 commit comments