-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: notice when using searchbanners (#33) * feat: searchable filters (#32) feat: searchable filters * fix: make installable on php 8.3 (#38) * feat(TW-29): Personal merchandising functionality BREAKING CHANGE: Personal merchandising works with Varnish now. * fix(TW-29): Changed required magento2-tweakwise version * fix: filter search (#42)
- Loading branch information
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tweakwise\TweakwiseHyva\Plugin\ViewModel; | ||
|
||
use Hyva\Theme\ViewModel\ProductListItem as Subject; | ||
use Tweakwise\Magento2Tweakwise\Model\Config as TweakwiseConfig; | ||
use Tweakwise\Magento2Tweakwise\Helper\Cache; | ||
use Magento\Catalog\Model\Product; | ||
use Magento\Framework\Exception\LocalizedException; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Framework\View\Element\AbstractBlock; | ||
|
||
class ProductListItem | ||
{ | ||
/** | ||
* @param Cache $cacheHelper | ||
* @param TweakwiseConfig $config | ||
*/ | ||
public function __construct( | ||
private readonly Cache $cacheHelper, | ||
private readonly TweakwiseConfig $config, | ||
) { | ||
} | ||
|
||
/** | ||
* @param Subject $subject | ||
* @param callable $proceed | ||
* @param Product $product | ||
* @param AbstractBlock $parentBlock | ||
* @param string $viewMode | ||
* @param string $templateType | ||
* @param string $imageDisplayArea | ||
* @param bool $showDescription | ||
* @return string | ||
* @throws NoSuchEntityException | ||
* @throws LocalizedException | ||
*/ | ||
public function aroundGetItemHtml( | ||
Subject $subject, | ||
callable $proceed, | ||
Product $product, | ||
AbstractBlock $parentBlock, | ||
string $viewMode, | ||
string $templateType, | ||
string $imageDisplayArea, | ||
bool $showDescription | ||
) { | ||
if ( | ||
!$this->cacheHelper->isVarnishEnabled() || | ||
!$this->config->isPersonalMerchandisingActive() || | ||
$this->cacheHelper->isTweakwiseAjaxRequest() | ||
) { | ||
return $proceed($product, $parentBlock, $viewMode, $templateType, $imageDisplayArea, $showDescription); | ||
} | ||
|
||
$productId = (int) $product->getId(); | ||
if (!$this->cacheHelper->load($productId)) { | ||
$itemHtml = $proceed($product, $parentBlock, $viewMode, $templateType, $imageDisplayArea, $showDescription); | ||
$this->cacheHelper->save($itemHtml, $productId); | ||
} | ||
|
||
return sprintf('<esi:include src="/%s?product_id=%s" />', Cache::PRODUCT_CARD_PATH, $productId); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters