Skip to content

Commit aae290b

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-71576-2' into 2.1-develop-PR
2 parents 621c283 + 0316caf commit aae290b

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,8 @@ public function getUsedProductAttributes($product)
449449
/**
450450
* @param Product $product
451451
*
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.
455454
*/
456455
private function generateConfigurableAttributesCacheId(
457456
Product $product
@@ -461,9 +460,7 @@ private function generateConfigurableAttributesCacheId(
461460
/** @var string|null $productId */
462461
$productId = $product->getData($metadata->getLinkField());
463462
if (!$productId) {
464-
throw new \InvalidArgumentException(
465-
'Impossible to generate cache ID for the product'
466-
);
463+
return null;
467464
}
468465

469466
return __CLASS__ . $productId . '_' . $product->getStoreId();
@@ -474,18 +471,14 @@ private function generateConfigurableAttributesCacheId(
474471
*
475472
* @param Product $product
476473
*
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.
479476
*/
480477
private function findCachedConfigurableAttributes(
481478
Product $product
482479
) {
483480
//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);
489482
if ($cacheId) {
490483
$configurableAttributes = $this->getCache()->load($cacheId);
491484
$configurableAttributes
@@ -520,9 +513,7 @@ private function findCachedConfigurableAttributes(
520513
return $configurableAttributes;
521514
}
522515

523-
throw new \RuntimeException(
524-
'Couldn\'t find attributes for configurable product.'
525-
);
516+
return null;
526517
}
527518

528519
/**
@@ -544,11 +535,12 @@ private function cacheConfigurableAttributes(
544535
/** @var string $productHashId */
545536
$productHashId = spl_object_hash($product);
546537

547-
if ($productId) {
538+
$cacheId = $this->generateConfigurableAttributesCacheId($product);
539+
if ($productId && $cacheId) {
548540
$this->getCache()
549541
->save(
550542
serialize($collection),
551-
$this->generateConfigurableAttributesCacheId($product),
543+
$cacheId,
552544
array_merge(
553545
$product->getIdentities(),
554546
[self::TYPE_CODE . '_' . $productId]
@@ -574,10 +566,10 @@ public function getConfigurableAttributes($product)
574566
['group' => 'CONFIGURABLE', 'method' => __METHOD__]
575567
);
576568
if (!$product->hasData($this->_configurableAttributes)) {
577-
try {
578-
$configurableAttributes
569+
$configurableAttributes
579570
= $this->findCachedConfigurableAttributes($product);
580-
} catch (\RuntimeException $exception) {
571+
572+
if (!$configurableAttributes) {
581573
//Couldn't find attributes in cache, loading.
582574
$configurableAttributes
583575
= $this->getConfigurableAttributeCollection($product);

0 commit comments

Comments
 (0)