Skip to content

Commit

Permalink
Merge pull request #219 from EmicoEcommerce/fix-wrong-product-tiles
Browse files Browse the repository at this point in the history
fix: wrong product tiles
  • Loading branch information
ah-net authored Sep 19, 2024
2 parents 645bf81 + 9f4857d commit 8eec3ae
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
13 changes: 11 additions & 2 deletions ViewModel/LinkedProductListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace Tweakwise\Magento2Tweakwise\ViewModel;

use Magento\Catalog\Model\Product;
use Magento\Customer\Model\Session;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Framework\View\LayoutInterface;
use Tweakwise\Magento2Tweakwise\Helper\Cache;
use Magento\Store\Model\StoreManagerInterface;

class LinkedProductListItem implements ArgumentInterface
{
Expand All @@ -20,7 +22,9 @@ class LinkedProductListItem implements ArgumentInterface
*/
public function __construct(
private readonly LayoutInterface $layout,
private readonly Cache $cacheHelper
private readonly Cache $cacheHelper,
private readonly StoreManagerInterface $storeManager,
private readonly Session $customerSession
) {
}

Expand Down Expand Up @@ -59,10 +63,15 @@ public function getItemHtml(
$this->cacheHelper->save($itemHtml, $productId, $cardType);
}

$storeId = $this->storeManager->getStore()->getId();
$customerGroupId = $this->customerSession->getCustomerGroupId();

return sprintf(
'<esi:include src="/%s?product_id=%s&card_type=%s" />',
'<esi:include src="/%s?product_id=%s&store_id=%s&customer_group_id=%s&card_type=%s" />',
Cache::PRODUCT_CARD_PATH,
$productId,
$storeId,
$customerGroupId,
$cardType
);
}
Expand Down
18 changes: 16 additions & 2 deletions ViewModel/ProductListItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
namespace Tweakwise\Magento2Tweakwise\ViewModel;

use Magento\Catalog\Model\Product;
use Magento\Customer\Model\Session;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\View\Element\AbstractBlock;
use Magento\Framework\View\Element\Block\ArgumentInterface;
use Magento\Framework\View\LayoutInterface;
use Tweakwise\Magento2Tweakwise\Helper\Cache;
use Magento\Store\Model\StoreManagerInterface;

class ProductListItem implements ArgumentInterface
{
Expand All @@ -20,7 +22,9 @@ class ProductListItem implements ArgumentInterface
*/
public function __construct(
private readonly LayoutInterface $layout,
private readonly Cache $cacheHelper
private readonly Cache $cacheHelper,
private readonly StoreManagerInterface $storeManager,
private readonly Session $customerSession
) {
}

Expand Down Expand Up @@ -58,6 +62,7 @@ public function getItemHtml(
}

$productId = (int) $product->getId();

if (!$this->cacheHelper->load($productId)) {
$itemHtml = $this->getItemHtmlWithRenderer(
$product,
Expand All @@ -70,7 +75,16 @@ public function getItemHtml(
$this->cacheHelper->save($itemHtml, $productId);
}

return sprintf('<esi:include src="/%s?product_id=%s" />', Cache::PRODUCT_CARD_PATH, $productId);
$storeId = $this->storeManager->getStore()->getId();
$customerGroupId = $this->customerSession->getCustomerGroupId();

return sprintf(
'<esi:include src="/%s?product_id=%s&store_id=%s&customer_group_id=%s" />',
Cache::PRODUCT_CARD_PATH,
$productId,
$storeId,
$customerGroupId
);
}

/**
Expand Down

0 comments on commit 8eec3ae

Please sign in to comment.