Skip to content

Commit

Permalink
Fixed multiple visuals issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jansentjeu committed Aug 23, 2024
1 parent 601abd7 commit 1fcf471
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Controller/Product/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public function __construct(
*/
public function execute(): HttpInterface
{
$productId = $this->request->getParam('product_id');
$itemId = (string) $this->request->getParam('item_id');
$cardType = $this->request->getParam('card_type');
$itemHtml = $cardType ? $this->cacheHelper->load((int)$productId, $cardType) :
$this->cacheHelper->load((int)$productId);
$itemHtml = $cardType ? $this->cacheHelper->load($itemId, $cardType) :
$this->cacheHelper->load($itemId);

$response = $this->httpFactory->create();
$response->appendBody($itemHtml);
Expand Down
18 changes: 9 additions & 9 deletions Helper/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,29 @@ public function __construct(
}

/**
* @param int $productId
* @param string $itemId
* @param string $cardType
* @return string
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function load(int $productId, string $cardType = 'default'): string
public function load(string $itemId, string $cardType = 'default'): string
{
$result = $this->cache->load($this->getCacheKey($productId, $cardType));
$result = $this->cache->load($this->getCacheKey($itemId, $cardType));
return $result ? $result : '';
}

/**
* @param string $data
* @param int $productId
* @param string $itemId
* @param string $cardType
* @return void
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function save(string $data, int $productId, string $cardType = 'default'): void
public function save(string $data, string $itemId, string $cardType = 'default'): void
{
$this->cache->save($data, $this->getCacheKey($productId, $cardType));
$this->cache->save($data, $this->getCacheKey($itemId, $cardType));
}

/**
Expand Down Expand Up @@ -128,13 +128,13 @@ public function isHyvaTheme(): bool
}

/**
* @param int $productId
* @param string $itemId
* @param string $cardType
* @return string
* @throws LocalizedException
* @throws NoSuchEntityException
*/
private function getCacheKey(int $productId, string $cardType): string
private function getCacheKey(string $itemId, string $cardType): string
{
$storeId = $this->storeManager->getStore()->getId();
$customerGroupId = $this->customerSession->getCustomerGroupId();
Expand All @@ -143,7 +143,7 @@ private function getCacheKey(int $productId, string $cardType): string
'%s_%s_%s_%s_%s',
$storeId,
$customerGroupId,
$productId,
$itemId,
$cardType,
self::REDIS_CACHE_KEY
);
Expand Down
4 changes: 2 additions & 2 deletions ViewModel/LinkedProductListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function getItemHtml(
);
}

$productId = (int) $product->getId();
$productId = (string) $product->getId();
$cardType = str_replace(' ', '_', $params['card_type']);
if (!$this->cacheHelper->load($productId, $cardType)) {
$itemHtml = $this->getItemHtmlWithRenderer(
Expand All @@ -60,7 +60,7 @@ public function getItemHtml(
}

return sprintf(
'<esi:include src="/%s?product_id=%s&card_type=%s" />',
'<esi:include src="/%s?item_id=%s&card_type=%s" />',
Cache::PRODUCT_CARD_PATH,
$productId,
$cardType
Expand Down
8 changes: 4 additions & 4 deletions ViewModel/ProductListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public function getItemHtml(
);
}

$productId = (int) $item->getId();
if (!$this->cacheHelper->load($productId)) {
$itemId = (string) $item->getId();
if (!$this->cacheHelper->load($itemId)) {
if ($isVisual) {
$itemHtml = $this->getVisualHtml($item);
} else {
Expand All @@ -78,10 +78,10 @@ public function getItemHtml(
);
}

$this->cacheHelper->save($itemHtml, $productId);
$this->cacheHelper->save($itemHtml, $itemId);
}

return sprintf('<esi:include src="/%s?product_id=%s" />', Cache::PRODUCT_CARD_PATH, $productId);
return sprintf('<esi:include src="/%s?item_id=%s" />', Cache::PRODUCT_CARD_PATH, $itemId);
}

/**
Expand Down

0 comments on commit 1fcf471

Please sign in to comment.