|
9 | 9 |
|
10 | 10 | use Magento\Framework\Exception\CouldNotSaveException;
|
11 | 11 | use Magento\Framework\Exception\NoSuchEntityException;
|
| 12 | +use Magento\Framework\Exception\SerializationException; |
12 | 13 | use Magento\Framework\Exception\StateException;
|
13 | 14 | use Magento\Catalog\Api\Data\CategoryInterface;
|
| 15 | +use Magento\Framework\Phrase; |
14 | 16 |
|
15 | 17 | /**
|
16 | 18 | * Repository for categories.
|
@@ -128,10 +130,11 @@ public function save(\Magento\Catalog\Api\Data\CategoryInterface $category)
|
128 | 130 |
|
129 | 131 | /**
|
130 | 132 | * @inheritdoc
|
| 133 | + * @throws SerializationException |
131 | 134 | */
|
132 | 135 | public function get($categoryId, $storeId = null)
|
133 | 136 | {
|
134 |
| - $cacheKey = $storeId ?? 'all'; |
| 137 | + $cacheKey = $this->getScopeCacheKey($storeId); |
135 | 138 | if (!isset($this->instances[$categoryId][$cacheKey])) {
|
136 | 139 | /** @var Category $category */
|
137 | 140 | $category = $this->categoryFactory->create();
|
@@ -238,4 +241,26 @@ private function getMetadataPool()
|
238 | 241 | }
|
239 | 242 | return $this->metadataPool;
|
240 | 243 | }
|
| 244 | + |
| 245 | + /** |
| 246 | + * Returns a cache key based on scope |
| 247 | + * |
| 248 | + * @param string|integer|null $storeId |
| 249 | + * |
| 250 | + * @throws SerializationException |
| 251 | + * @return integer |
| 252 | + */ |
| 253 | + private function getScopeCacheKey($storeId = null) |
| 254 | + { |
| 255 | + if (null !== $storeId && !is_numeric($storeId)) { |
| 256 | + throw new SerializationException( |
| 257 | + new Phrase( |
| 258 | + 'The "%value" value\'s type is invalid. The "%type" type was expected. ' |
| 259 | + . 'Verify and try again.', |
| 260 | + ['value' => $storeId, 'type' => 'int'] |
| 261 | + ) |
| 262 | + ); |
| 263 | + } |
| 264 | + return $storeId ?? 'all'; |
| 265 | + } |
241 | 266 | }
|
0 commit comments