Skip to content

Commit

Permalink
Added getScopeCacheKey in order to validate the store ID and return t…
Browse files Browse the repository at this point in the history
…he right cache key
  • Loading branch information
matiashidalgo committed Mar 4, 2020
1 parent 5a9fcab commit 69946cc
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion app/code/Magento/Catalog/Model/CategoryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Exception\SerializationException;
use Magento\Framework\Exception\StateException;
use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Framework\Phrase;

/**
* Repository for categories.
Expand Down Expand Up @@ -128,10 +130,11 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)

/**
* @inheritdoc
* @throws SerializationException
*/
public function get($categoryId, $storeId = null)
{
$cacheKey = $storeId ?? 'all';
$cacheKey = $this->getScopeCacheKey($storeId);
if (!isset($this->instances[$categoryId][$cacheKey])) {
/** @var Category $category */
$category = $this->categoryFactory->create();
Expand Down Expand Up @@ -238,4 +241,26 @@ private function getMetadataPool()
}
return $this->metadataPool;
}

/**
* Returns a cache key based on scope
*
* @param string|integer|null $storeId
*
* @throws SerializationException
* @return integer
*/
private function getScopeCacheKey($storeId = null)
{
if (null !== $storeId && !is_numeric($storeId)) {
throw new SerializationException(
new Phrase(
'The "%value" value\'s type is invalid. The "%type" type was expected. '
. 'Verify and try again.',
['value' => $storeId, 'type' => 'int']
)
);
}
return $storeId ?? 'all';
}
}

0 comments on commit 69946cc

Please sign in to comment.