Skip to content

Commit

Permalink
Merge beta into master (#43)
Browse files Browse the repository at this point in the history
* 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
ah-net authored Jun 11, 2024
1 parent e82e5c6 commit 67dc47f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"hyva-themes/magento2-compat-module-fallback": "*",
"hyva-themes/magento2-default-theme": "^1.2",
"php": "^8.0",
"tweakwise/magento2-tweakwise": ">=6.0.0."
"tweakwise/magento2-tweakwise": ">=7.0.0."
},
"autoload": {
"files": [
Expand Down
66 changes: 66 additions & 0 deletions src/Plugin/ViewModel/ProductListItem.php
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);
}
}
4 changes: 4 additions & 0 deletions src/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@
<plugin name="tweakwise-hyva" type="Tweakwise\TweakwiseHyva\ViewModel\ProductList\Plugin" sortOrder="0" />
</type>
<preference for="Hyva\Theme\ViewModel\SwatchRenderer" type="Tweakwise\TweakwiseHyva\ViewModel\SwatchRenderer" />
<type name="Hyva\Theme\ViewModel\ProductListItem">
<plugin name="Tweakwise_TweakwiseHyva_Plugin_ViewModel_ProductListItem"
type="Tweakwise\TweakwiseHyva\Plugin\ViewModel\ProductListItem"/>
</type>
</config>
7 changes: 5 additions & 2 deletions src/view/frontend/templates/layer/view.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ $filtered = count($block->getLayer()->getState()->getFilters());
Array.from(items.children).forEach(function(item) {
//find input element in item
let input = item.querySelector('input');
if (input.value.toLowerCase().trim().indexOf(value) === -1) {
if (value.length === 0) {
// Reset to initial state
item.style.display = '';
} else if (input.value.toLowerCase().trim().indexOf(value) === -1) {
item.style.display = 'none';
} else {
item.style.display = '';
item.style.display = 'block';
}
});

Expand Down

0 comments on commit 67dc47f

Please sign in to comment.