From caf7cb454224a8df30c21932dbb99aba203d9fe4 Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 2 Aug 2024 15:43:34 +0200 Subject: [PATCH 01/19] feat: Implemented visuals functionality --- Api/Data/VisualInterface.php | 43 +++++++++++++ Model/Catalog/Product/Collection.php | 57 +++++++++++++++++- Model/Enum/ItemType.php | 10 ++++ Model/Visual.php | 60 +++++++++++++++++++ ViewModel/ProductListItem.php | 48 +++++++++++---- etc/di.xml | 1 + .../frontend/layout/catalog_category_view.xml | 4 ++ .../templates/product/list/visual.phtml | 22 +++++++ 8 files changed, 232 insertions(+), 13 deletions(-) create mode 100644 Api/Data/VisualInterface.php create mode 100644 Model/Enum/ItemType.php create mode 100644 Model/Visual.php create mode 100644 view/frontend/templates/product/list/visual.phtml diff --git a/Api/Data/VisualInterface.php b/Api/Data/VisualInterface.php new file mode 100644 index 00000000..53c3fde1 --- /dev/null +++ b/Api/Data/VisualInterface.php @@ -0,0 +1,43 @@ +applyCollectionSizeValues(); + $this->addVisuals(); return $this; } + /** + * @return void + */ + protected function addVisuals(): void + { + try { + $response = $this->navigationContext->getResponse(); + } catch (Exception $e) { + return; + } + + foreach ($response->getItems() as $item) { + if ($item->getValue('type') !== ItemType::VISUAL->value) { + continue; + } + + /** @var VisualInterface $visual */ + $visual = $this->visualFactory->create(); + $visual->setId($item->getValue('itemno')); + $visual->setTitle($item->getTitle()); + $visual->setImageUrl($item->getImage()); + $visual->setUrl($item->getUrl()); + $itemPosition = array_search($item, $response->getItems()); + + array_splice($this->_items, $itemPosition, 0, [$visual]); + } + } + /** * {@inheritdoc} */ diff --git a/Model/Enum/ItemType.php b/Model/Enum/ItemType.php new file mode 100644 index 00000000..0b5c1098 --- /dev/null +++ b/Model/Enum/ItemType.php @@ -0,0 +1,10 @@ +getData(self::TITLE); + } + + /** + * @param string $title + * @return VisualInterface + */ + public function setTitle(string $title): VisualInterface + { + return $this->setData(self::TITLE, $title); + } + + /** + * @return string + */ + public function getImageUrl(): string + { + return $this->getData(self::IMAGE_URL); + } + + /** + * @param string $imageUrl + * @return VisualInterface + */ + public function setImageUrl(string $imageUrl): VisualInterface + { + return $this->setData(self::IMAGE_URL, $imageUrl); + } + + /** + * @return string + */ + public function getUrl(): string + { + return $this->getData(self::URL); + } + + /** + * @param string $url + * @return VisualInterface + */ + public function setUrl(string $url): VisualInterface + { + return $this->setData(self::URL, $url); + } +} diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index ab2d59c1..40584e98 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -11,6 +11,7 @@ use Magento\Framework\View\Element\Block\ArgumentInterface; use Magento\Framework\View\LayoutInterface; use Tweakwise\Magento2Tweakwise\Helper\Cache; +use Tweakwise\Magento2Tweakwise\Model\Visual; class ProductListItem implements ArgumentInterface { @@ -25,7 +26,7 @@ public function __construct( } /** - * @param Product $product + * @param Product|Visual $item * @param AbstractBlock $parentBlock * @param string $viewMode * @param string $templateType @@ -36,7 +37,7 @@ public function __construct( * @throws NoSuchEntityException */ public function getItemHtml( - Product $product, + Product|Visual $item, AbstractBlock $parentBlock, string $viewMode, string $templateType, @@ -48,7 +49,7 @@ public function getItemHtml( $this->cacheHelper->isTweakwiseAjaxRequest() ) { return $this->getItemHtmlWithRenderer( - $product, + $item, $parentBlock, $viewMode, $templateType, @@ -57,16 +58,21 @@ public function getItemHtml( ); } - $productId = (int) $product->getId(); + $productId = (int) $item->getId(); if (!$this->cacheHelper->load($productId)) { - $itemHtml = $this->getItemHtmlWithRenderer( - $product, - $parentBlock, - $viewMode, - $templateType, - $imageDisplayArea, - $showDescription - ); + if ($item instanceof Visual) { + $itemHtml = $this->getVisualHtml($item); + } else { + $itemHtml = $this->getItemHtmlWithRenderer( + $item, + $parentBlock, + $viewMode, + $templateType, + $imageDisplayArea, + $showDescription + ); + } + $this->cacheHelper->save($itemHtml, $productId); } @@ -114,4 +120,22 @@ private function getItemHtmlWithRenderer( return $itemRendererBlock->toHtml(); } + + /** + * @param Visual $visual + * @return string + */ + private function getVisualHtml(Visual $visual): string + { + /** @var AbstractBlock $visualRendererBlock */ + $visualRendererBlock = $this->layout->getBlock('tweakwise.catalog.product.list.visual'); + + if (! $visualRendererBlock) { + return ''; + } + + $visualRendererBlock->setData('visual', $visual); + + return $visualRendererBlock->toHtml(); + } } diff --git a/etc/di.xml b/etc/di.xml index 507485c1..0a1374fa 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -12,6 +12,7 @@ + diff --git a/view/frontend/layout/catalog_category_view.xml b/view/frontend/layout/catalog_category_view.xml index ae8a2b45..4b093759 100644 --- a/view/frontend/layout/catalog_category_view.xml +++ b/view/frontend/layout/catalog_category_view.xml @@ -33,6 +33,10 @@ name="tweakwise.catalog.product.list.item" template="Tweakwise_Magento2Tweakwise::product/list/item.phtml" ifconfig="tweakwise/personal_merchandising/enabled"/> + diff --git a/view/frontend/templates/product/list/visual.phtml b/view/frontend/templates/product/list/visual.phtml new file mode 100644 index 00000000..216103b7 --- /dev/null +++ b/view/frontend/templates/product/list/visual.phtml @@ -0,0 +1,22 @@ +getData('visual'); +if (!$visual) { + return; +} +?> + +
  • +

    escapeHtml($visual->getTitle()) ?>

    +
  • +
    From c910e07553b0c42a7fc0b605173a8c643ca80b18 Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 9 Aug 2024 11:49:14 +0200 Subject: [PATCH 02/19] Only show visuals if merchandising builder is enabled --- Model/Catalog/Product/Collection.php | 8 +++++++- view/frontend/templates/product/list/visual.phtml | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Model/Catalog/Product/Collection.php b/Model/Catalog/Product/Collection.php index 35c31591..eb8ef221 100644 --- a/Model/Catalog/Product/Collection.php +++ b/Model/Catalog/Product/Collection.php @@ -10,6 +10,7 @@ namespace Tweakwise\Magento2Tweakwise\Model\Catalog\Product; use Exception; +use Tweakwise\Magento2Tweakwise\Model\Config; use Tweakwise\Magento2Tweakwise\Model\Enum\ItemType; use Tweakwise\Magento2Tweakwise\Api\Data\VisualInterface; use Tweakwise\Magento2Tweakwise\Model\Catalog\Layer\NavigationContext; @@ -66,6 +67,7 @@ class Collection extends AbstractCollection * @param GroupManagementInterface $groupManagement * @param NavigationContext $navigationContext * @param VisualFactory $visualFactory + * @param Config $config * @param AdapterInterface|null $connection */ public function __construct( @@ -90,6 +92,7 @@ public function __construct( GroupManagementInterface $groupManagement, NavigationContext $navigationContext, private readonly VisualFactory $visualFactory, + private readonly Config $config, AdapterInterface $connection = null ) { parent::__construct( @@ -164,7 +167,10 @@ protected function _afterLoad() parent::_afterLoad(); $this->applyCollectionSizeValues(); - $this->addVisuals(); + + if ($this->config->isPersonalMerchandisingActive()) { + $this->addVisuals(); + } return $this; } diff --git a/view/frontend/templates/product/list/visual.phtml b/view/frontend/templates/product/list/visual.phtml index 216103b7..389d0057 100644 --- a/view/frontend/templates/product/list/visual.phtml +++ b/view/frontend/templates/product/list/visual.phtml @@ -6,7 +6,7 @@ use Tweakwise\Magento2Tweakwise\Model\Visual; /** * @var AbstractProduct $block - * @var Escaper $escaper * + * @var Escaper $escaper */ /** @var Visual $visual */ From e607b44b908a4bdfc79ae519f05f5d871bddf2d1 Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 9 Aug 2024 12:28:52 +0200 Subject: [PATCH 03/19] Fixed showing visual on tweakwise ajax request --- ViewModel/ProductListItem.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 40584e98..1e9b160b 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -44,10 +44,15 @@ public function getItemHtml( string $imageDisplayArea, bool $showDescription ): string { + $isVisual = $item instanceof Visual; if ( !$this->cacheHelper->personalMerchandisingCanBeApplied() || $this->cacheHelper->isTweakwiseAjaxRequest() ) { + if ($isVisual) { + return $this->getVisualHtml($item); + } + return $this->getItemHtmlWithRenderer( $item, $parentBlock, @@ -60,7 +65,7 @@ public function getItemHtml( $productId = (int) $item->getId(); if (!$this->cacheHelper->load($productId)) { - if ($item instanceof Visual) { + if ($isVisual) { $itemHtml = $this->getVisualHtml($item); } else { $itemHtml = $this->getItemHtmlWithRenderer( From cb0727206230421ed4a7175b86b214729d1e414b Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Thu, 15 Aug 2024 10:23:12 +0200 Subject: [PATCH 04/19] Removed title functionality --- Api/Data/VisualInterface.php | 12 ------------ Model/Catalog/Product/Collection.php | 1 - Model/Visual.php | 17 ----------------- .../templates/product/list/visual.phtml | 1 - 4 files changed, 31 deletions(-) diff --git a/Api/Data/VisualInterface.php b/Api/Data/VisualInterface.php index 53c3fde1..0441ad12 100644 --- a/Api/Data/VisualInterface.php +++ b/Api/Data/VisualInterface.php @@ -4,21 +4,9 @@ interface VisualInterface { - public const TITLE = 'title'; public const IMAGE_URL = 'image'; public const URL = 'url'; - /** - * @return string - */ - public function getTitle(): string; - - /** - * @param string $title - * @return self - */ - public function setTitle(string $title): self; - /** * @return string */ diff --git a/Model/Catalog/Product/Collection.php b/Model/Catalog/Product/Collection.php index eb8ef221..a4a1752a 100644 --- a/Model/Catalog/Product/Collection.php +++ b/Model/Catalog/Product/Collection.php @@ -194,7 +194,6 @@ protected function addVisuals(): void /** @var VisualInterface $visual */ $visual = $this->visualFactory->create(); $visual->setId($item->getValue('itemno')); - $visual->setTitle($item->getTitle()); $visual->setImageUrl($item->getImage()); $visual->setUrl($item->getUrl()); $itemPosition = array_search($item, $response->getItems()); diff --git a/Model/Visual.php b/Model/Visual.php index 3bd0ef36..4a854cfa 100644 --- a/Model/Visual.php +++ b/Model/Visual.php @@ -7,23 +7,6 @@ class Visual extends Product implements VisualInterface { - /** - * @return string - */ - public function getTitle(): string - { - return $this->getData(self::TITLE); - } - - /** - * @param string $title - * @return VisualInterface - */ - public function setTitle(string $title): VisualInterface - { - return $this->setData(self::TITLE, $title); - } - /** * @return string */ diff --git a/view/frontend/templates/product/list/visual.phtml b/view/frontend/templates/product/list/visual.phtml index 389d0057..1dd11962 100644 --- a/view/frontend/templates/product/list/visual.phtml +++ b/view/frontend/templates/product/list/visual.phtml @@ -17,6 +17,5 @@ if (!$visual) { ?>
  • -

    escapeHtml($visual->getTitle()) ?>

  • From 1ed28ba018534d9ede6d4742bfd398602a1eead1 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 15 Aug 2024 12:47:28 +0200 Subject: [PATCH 05/19] fix: remember sorting and page limit for query parameter stategy --- Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php b/Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php index f867334f..aa89e8c7 100644 --- a/Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php +++ b/Model/Catalog/Layer/Url/Strategy/QueryParameterStrategy.php @@ -161,10 +161,7 @@ protected function getCurrentQueryUrl(MagentoHttpRequest $request, array $query) { $selectedFilters = $request->getQuery(); $reservedParams = [ - self::PARAM_LIMIT, - self::PARAM_MODE, self::PARAM_PAGE, - self::PARAM_ORDER, self::PARAM_CATEGORY, ]; From e5982d0d70285657b276e1c70e71d0e456c27576 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:08:22 +0200 Subject: [PATCH 06/19] Add styling --- .../frontend/templates/product/list/visual.phtml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/view/frontend/templates/product/list/visual.phtml b/view/frontend/templates/product/list/visual.phtml index 1dd11962..248e80cf 100644 --- a/view/frontend/templates/product/list/visual.phtml +++ b/view/frontend/templates/product/list/visual.phtml @@ -14,8 +14,18 @@ $visual = $block->getData('visual'); if (!$visual) { return; } +$hasUrl = $visual->getUrl() !== null; ?> - -
  • + +
  • + + + +
    + +
    + +
    +
  • - + From 601abd723bab21d3580ffd86c9fffcfd9918bf7b Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 16 Aug 2024 11:14:26 +0200 Subject: [PATCH 07/19] Style changes --- .../templates/product/list/visual.phtml | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/view/frontend/templates/product/list/visual.phtml b/view/frontend/templates/product/list/visual.phtml index 248e80cf..59fc4c6f 100644 --- a/view/frontend/templates/product/list/visual.phtml +++ b/view/frontend/templates/product/list/visual.phtml @@ -14,18 +14,18 @@ $visual = $block->getData('visual'); if (!$visual) { return; } -$hasUrl = $visual->getUrl() !== null; +$hasUrl = !empty($visual->getUrl()); ?> -
  • - - - -
    - -
    - -
    - -
  • +
  • + + + +
    + +
    + +
    + +
  • From 1fcf471d9d1d0e3be71485aa7bf5c9871eda8610 Mon Sep 17 00:00:00 2001 From: tjeujansen Date: Fri, 23 Aug 2024 12:04:14 +0200 Subject: [PATCH 08/19] Fixed multiple visuals issue --- Controller/Product/Card.php | 6 +++--- Helper/Cache.php | 18 +++++++++--------- ViewModel/LinkedProductListItem.php | 4 ++-- ViewModel/ProductListItem.php | 8 ++++---- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Controller/Product/Card.php b/Controller/Product/Card.php index d9954a83..00a4bd60 100644 --- a/Controller/Product/Card.php +++ b/Controller/Product/Card.php @@ -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); diff --git a/Helper/Cache.php b/Helper/Cache.php index 2aeff9e6..ec98b2d5 100644 --- a/Helper/Cache.php +++ b/Helper/Cache.php @@ -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)); } /** @@ -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(); @@ -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 ); diff --git a/ViewModel/LinkedProductListItem.php b/ViewModel/LinkedProductListItem.php index cd76b70d..ae573864 100644 --- a/ViewModel/LinkedProductListItem.php +++ b/ViewModel/LinkedProductListItem.php @@ -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( @@ -60,7 +60,7 @@ public function getItemHtml( } return sprintf( - '', + '', Cache::PRODUCT_CARD_PATH, $productId, $cardType diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 1e9b160b..2a2d6869 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -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 { @@ -78,10 +78,10 @@ public function getItemHtml( ); } - $this->cacheHelper->save($itemHtml, $productId); + $this->cacheHelper->save($itemHtml, $itemId); } - return sprintf('', Cache::PRODUCT_CARD_PATH, $productId); + return sprintf('', Cache::PRODUCT_CARD_PATH, $itemId); } /** From a6ede1cc10267ff4608781d5cd2965b309171c16 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:42:12 +0200 Subject: [PATCH 09/19] fix: wrong product tiles --- ViewModel/ProductListItem.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index ab2d59c1..ca5b150b 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -11,6 +11,7 @@ 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 { @@ -20,7 +21,8 @@ class ProductListItem implements ArgumentInterface */ public function __construct( private readonly LayoutInterface $layout, - private readonly Cache $cacheHelper + private readonly Cache $cacheHelper, + private readonly StoreManagerInterface $storeManager ) { } @@ -58,6 +60,7 @@ public function getItemHtml( } $productId = (int) $product->getId(); + $storeId = $this->storeManager->getStore()->getId(); if (!$this->cacheHelper->load($productId)) { $itemHtml = $this->getItemHtmlWithRenderer( $product, @@ -70,7 +73,8 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $productId); } - return sprintf('', Cache::PRODUCT_CARD_PATH, $productId); + //return sprintf('', Cache::PRODUCT_CARD_PATH, $productId); + return sprintf('', Cache::PRODUCT_CARD_PATH, $productId, $storeId); } /** From 72368ded9542e3adf8b257ad413f5d300e82780a Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:45:41 +0200 Subject: [PATCH 10/19] remove old code --- ViewModel/ProductListItem.php | 1 - 1 file changed, 1 deletion(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index ca5b150b..006d686b 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -73,7 +73,6 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $productId); } - //return sprintf('', Cache::PRODUCT_CARD_PATH, $productId); return sprintf('', Cache::PRODUCT_CARD_PATH, $productId, $storeId); } From ca92e8e743bbabb67e5a5748f8a1418239fd6fe2 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 18 Sep 2024 16:58:22 +0200 Subject: [PATCH 11/19] Style fixes --- ViewModel/ProductListItem.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 006d686b..6984f830 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -73,7 +73,8 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $productId); } - return sprintf('', Cache::PRODUCT_CARD_PATH, $productId, $storeId); + return sprintf('', + Cache::PRODUCT_CARD_PATH, $productId, $storeId); } /** From 6c65a9641fca150b5a73e79fa3f83604d6533bd2 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:00:00 +0200 Subject: [PATCH 12/19] Style fixes --- ViewModel/ProductListItem.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 6984f830..4febb571 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -73,8 +73,10 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $productId); } - return sprintf('', - Cache::PRODUCT_CARD_PATH, $productId, $storeId); + return sprintf( + '', + Cache::PRODUCT_CARD_PATH, $productId, $storeId + ); } /** From 763e44015e3ee909044c54b8c28360f2a956390b Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 18 Sep 2024 17:02:11 +0200 Subject: [PATCH 13/19] Style fixes --- ViewModel/ProductListItem.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 4febb571..928816d7 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -75,7 +75,9 @@ public function getItemHtml( return sprintf( '', - Cache::PRODUCT_CARD_PATH, $productId, $storeId + Cache::PRODUCT_CARD_PATH, + $productId, + $storeId ); } From d5619ac1e7363b1da4b5627ee236b94ae0d456d2 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 19 Sep 2024 09:55:07 +0200 Subject: [PATCH 14/19] fix: recommendations tile --- ViewModel/LinkedProductListItem.php | 13 +++++++++++-- ViewModel/ProductListItem.php | 14 ++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/ViewModel/LinkedProductListItem.php b/ViewModel/LinkedProductListItem.php index cd76b70d..3c39ca3d 100644 --- a/ViewModel/LinkedProductListItem.php +++ b/ViewModel/LinkedProductListItem.php @@ -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 { @@ -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 ) { } @@ -59,10 +63,15 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $productId, $cardType); } + $storeId = $this->storeManager->getStore()->getId(); + $customerGroupId = $this->customerSession->getCustomerGroupId(); + return sprintf( - '', + '', Cache::PRODUCT_CARD_PATH, $productId, + $storeId, + $customerGroupId, $cardType ); } diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 928816d7..8b1ba98f 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -5,6 +5,7 @@ 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; @@ -22,7 +23,8 @@ class ProductListItem implements ArgumentInterface public function __construct( private readonly LayoutInterface $layout, private readonly Cache $cacheHelper, - private readonly StoreManagerInterface $storeManager + private readonly StoreManagerInterface $storeManager, + private readonly Session $customerSession ) { } @@ -60,7 +62,7 @@ public function getItemHtml( } $productId = (int) $product->getId(); - $storeId = $this->storeManager->getStore()->getId(); + if (!$this->cacheHelper->load($productId)) { $itemHtml = $this->getItemHtmlWithRenderer( $product, @@ -73,11 +75,15 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $productId); } + $storeId = $this->storeManager->getStore()->getId(); + $customerGroupId = $this->customerSession->getCustomerGroupId(); + return sprintf( - '', + '', Cache::PRODUCT_CARD_PATH, $productId, - $storeId + $storeId, + $customerGroupId ); } From 9f4857d18fdc627c3647e8691a8bd9a104ea4e52 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:14:12 +0200 Subject: [PATCH 15/19] remove cardtype --- ViewModel/ProductListItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 8b1ba98f..1ebcfbcb 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -79,7 +79,7 @@ public function getItemHtml( $customerGroupId = $this->customerSession->getCustomerGroupId(); return sprintf( - '', + '', Cache::PRODUCT_CARD_PATH, $productId, $storeId, From 403d3733d3b6e0a19b75cc210766ea7619fcae23 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 19 Sep 2024 11:06:00 +0200 Subject: [PATCH 16/19] fix: bump php version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ea2c3102..ffe9d6bc 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "license": "OSL-3.0", "description": "Magento 2 module for Tweakwise integration", "require": { - "php": "^8.0", + "php": "^8.1", "ext-json": "*", "ext-pcre": "*", "ext-simplexml": "*", From 382a26108a61ce32880b79e5e1da3a3555a01a33 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 19 Sep 2024 12:02:34 +0200 Subject: [PATCH 17/19] Fix style --- ViewModel/ProductListItem.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 2982837e..93792ccc 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -87,7 +87,7 @@ public function getItemHtml( return sprintf( '', - Cache::PRODUCT_CARD_PATH, + Cache::PRODUCT_CARD_PATH, $itemId, $storeId, $customerGroupId From b0e223bc7118d34973728df8c574c1fd96193e94 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 19 Sep 2024 13:11:31 +0200 Subject: [PATCH 18/19] fix code removed bij merge --- ViewModel/ProductListItem.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ViewModel/ProductListItem.php b/ViewModel/ProductListItem.php index 93792ccc..0faa6df4 100644 --- a/ViewModel/ProductListItem.php +++ b/ViewModel/ProductListItem.php @@ -85,6 +85,9 @@ public function getItemHtml( $this->cacheHelper->save($itemHtml, $itemId); } + $storeId = $this->storeManager->getStore()->getId(); + $customerGroupId = $this->customerSession->getCustomerGroupId(); + return sprintf( '', Cache::PRODUCT_CARD_PATH, From 4b1bc4b2999eb27b040d37151ce571f4e9852b76 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 24 Sep 2024 10:31:27 +0200 Subject: [PATCH 19/19] bump version nr --- etc/adminhtml/system.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 263a9b45..61284868 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -12,7 +12,7 @@
    - Tweakwise version v8.0.0 + Tweakwise version v8.1.0 Provided by Tweakwise (8 alphanumeric characters)