Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Block/Product/ListProduct.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,10 @@ public function getUrl($route = '', $params = [])
*/
public function getTemplate()
{
if ($this->cacheHelper->isHyvaTheme()) {
if (
!$this->cacheHelper->shouldUseMerchandisingListing() ||
$this->cacheHelper->isHyvaTheme()
) {
return parent::getTemplate();
}

Expand Down
8 changes: 8 additions & 0 deletions Helper/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,14 @@ public function personalMerchandisingCanBeApplied(): bool
return $this->isVarnishEnabled() && $this->config->isPersonalMerchandisingActive();
}

/**
* @return bool
*/
public function shouldUseMerchandisingListing(): bool
{
return $this->personalMerchandisingCanBeApplied() || $this->config->isVisualsEnabled();
}

/**
* @param RequestInterface $request
* @return bool
Expand Down
17 changes: 14 additions & 3 deletions Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/**
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
*/
class Config
{
Expand Down Expand Up @@ -69,7 +70,8 @@ class Config
*/
public const FALLBACK_SERVER_URL = 'https://gateway.tweakwisenavigator.com';

private const PRODUCT_CARD_LIFETIME_XML_PATH = 'tweakwise/personal_merchandising/product_card_lifetime';
private const PRODUCT_CARD_LIFETIME_XML_PATH =
'tweakwise/merchandising_builder/personal_merchandising/product_card_lifetime';

/**
* @var ScopeConfigInterface
Expand Down Expand Up @@ -388,7 +390,16 @@ public function getSearchTemplateId(Store $store = null)
*/
public function isPersonalMerchandisingActive(Store $store = null)
{
return (bool) $this->getStoreConfig('tweakwise/personal_merchandising/enabled', $store);
return (bool) $this->getStoreConfig('tweakwise/merchandising_builder/personal_merchandising/enabled', $store);
}

/**
* @param Store|null $store
* @return bool
*/
public function isVisualsEnabled(Store $store = null)
{
return (bool)$this->getStoreConfig('tweakwise/merchandising_builder/visuals/enabled', $store);
}

/**
Expand All @@ -407,7 +418,7 @@ public function isSearchBannersActive(Store $store = null)
*/
public function getPersonalMerchandisingCookieName(Store $store = null)
{
$cookie = $this->getStoreConfig('tweakwise/personal_merchandising/cookie_name', $store);
$cookie = $this->getStoreConfig('tweakwise/merchandising_builder/personal_merchandising/cookie_name', $store);

if (empty($cookie)) {
$cookie = 'tw_analytics';
Expand Down
5 changes: 4 additions & 1 deletion Model/PersonalMerchandisingConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ public function __construct(
*/
public function isAnalyticsEnabled(Store $store = null): bool
{
return (bool)$this->getStoreConfig('tweakwise/personal_merchandising/analytics_enabled', $store);
return (bool)$this->getStoreConfig(
'tweakwise/merchandising_builder/personal_merchandising/analytics_enabled',
$store
);
}

/**
Expand Down
64 changes: 64 additions & 0 deletions Setup/Patch/Data/UpdatePersonalMerchandisingConfigs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

declare(strict_types=1);

namespace Tweakwise\Magento2Tweakwise\Setup\Patch\Data;

use Magento\Framework\Setup\Patch\DataPatchInterface;
use Magento\Framework\App\Config\Storage\WriterInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;

class UpdatePersonalMerchandisingConfigs implements DataPatchInterface
{
/**
* @param WriterInterface $configWriter
* @param ScopeConfigInterface $scopeConfig
*/
public function __construct(
private readonly WriterInterface $configWriter,
private readonly ScopeConfigInterface $scopeConfig
) {
}

/**
* @return $this
*/
public function apply(): UpdatePersonalMerchandisingConfigs
{
$configurationPaths = [
'tweakwise/personal_merchandising/enabled' =>
'tweakwise/merchandising_builder/personal_merchandising/enabled',
'tweakwise/personal_merchandising/cookie_name' =>
'tweakwise/merchandising_builder/personal_merchandising/cookie_name',
'tweakwise/personal_merchandising/product_card_lifetime' =>
'tweakwise/merchandising_builder/personal_merchandising/product_card_lifetime',
'tweakwise/personal_merchandising/analytics_enabled' =>
'tweakwise/merchandising_builder/personal_merchandising/analytics_enabled',
];

foreach ($configurationPaths as $oldPath => $newPath) {
$value = $this->scopeConfig->getValue($oldPath);
if ($value !== null) {
$this->configWriter->save($newPath, $value);
}
}

return $this;
}

/**
* @return array|string[]
*/
public static function getDependencies(): array
{
return [];
}

/**
* @return array|string[]
*/
public function getAliases(): array
{
return [];
}
}
76 changes: 45 additions & 31 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,37 +221,51 @@
</depends>
</field>
</group>
<group id="personal_merchandising" translate="label" type="text" sortOrder="55" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Personal Merchandising</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Note that Varnish must be enabled and properly configured for personal merchandising to
work properly in cached blocks. Enabling this can have impact on performance, caching of ajax
filter requests will be disabled for requests which have a profile cookie value (see Cookie name
setting below)
</comment>
</field>
<field id="cookie_name" translate="label,comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Cookie name</label>
<comment>Name of cookie which holds tweakwise profile information, this is usually set in the tweakwise measure script. Or when analytics is enabled, it is done automaticly</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="product_card_lifetime" translate="label,comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Product Card TTL</label>
<comment>The cache lifetime for a product tile on the category view.</comment>
<validate>validate-number</validate>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="analytics_enabled" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Send analytics events to Tweakwise</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Note only enable this if you don't use javascript to send productviews/search/purchases requests to tweakwise</comment>
</field>
<group id="merchandising_builder" translate="label" type="text" sortOrder="55" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Merchandising Builder</label>
<group id="personal_merchandising" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Personal Merchandising</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Note that Varnish must be enabled and properly configured for personal merchandising to
work properly in cached blocks. Enabling this can have impact on performance, caching of ajax
filter requests will be disabled for requests which have a profile cookie value (see Cookie name
setting below)
</comment>
</field>
<field id="cookie_name" translate="label,comment" type="text" sortOrder="20" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Cookie name</label>
<comment>Name of cookie which holds tweakwise profile information, this is usually set in the tweakwise measure script. Or when analytics is enabled, it is done automaticly</comment>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="product_card_lifetime" translate="label,comment" type="text" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Product Card TTL</label>
<comment>The cache lifetime for a product tile on the category view.</comment>
<validate>validate-number</validate>
<depends>
<field id="enabled">1</field>
</depends>
</field>
<field id="analytics_enabled" translate="label" type="select" sortOrder="40" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Send analytics events to Tweakwise</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Note only enable this if you don't use javascript to send productviews/search/purchases requests to tweakwise</comment>
</field>
</group>
<group id="visuals" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Visuals</label>
<field id="enabled" translate="label" type="select" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Enabled</label>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
<comment>Enable this if you want to show visuals on the PLP. This is automatically enabled when the personal merchandising configuration is enabled.</comment>
</field>
<depends>
<field id="tweakwise/merchandising_builder/personal_merchandising/enabled">0</field>
</depends>
</group>
</group>
<group id="recommendations" translate="label" type="text" sortOrder="60" showInDefault="1" showInWebsite="1" showInStore="1">
<label>Recommendations</label>
Expand Down
10 changes: 6 additions & 4 deletions etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ cid
<enabled>0</enabled>
<template/>
</search>
<personal_merchandising>
<product_card_lifetime>3600</product_card_lifetime>
<analytics_enabled>0</analytics_enabled>
</personal_merchandising>
<merchandising_builder>
<personal_merchandising>
<product_card_lifetime>3600</product_card_lifetime>
<analytics_enabled>0</analytics_enabled>
</personal_merchandising>
</merchandising_builder>
<recommendations>
<crosssell_enabled>0</crosssell_enabled>
<crosssell_template />
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/layout/catalog_category_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<block class="Magento\Catalog\Block\Product\AbstractProduct"
name="tweakwise.catalog.linked.product.list.item"
template="Tweakwise_Magento2Tweakwise::product/list/linked-item.phtml"
ifconfig="tweakwise/personal_merchandising/enabled"/>
ifconfig="tweakwise/merchandising_builder/personal_merchandising/enabled"/>
</block>
</referenceContainer>
<referenceBlock name="category.products.list">
Expand Down
6 changes: 3 additions & 3 deletions view/frontend/layout/catalog_product_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Framework\View\Element\Template" name="magento2tweakwise.productpage" template="Tweakwise_Magento2Tweakwise::analytics.phtml" ifconfig="tweakwise/personal_merchandising/analytics_enabled">
<block class="Magento\Framework\View\Element\Template" name="magento2tweakwise.productpage" template="Tweakwise_Magento2Tweakwise::analytics.phtml" ifconfig="tweakwise/merchandising_builder/personal_merchandising/analytics_enabled">
<arguments>
<argument name="viewModel" xsi:type="object">Tweakwise\Magento2Tweakwise\ViewModel\PersonalMerchandisingAnalytics</argument>
<argument name="analyticsType" xsi:type="string">product</argument>
Expand All @@ -27,7 +27,7 @@
<block class="Magento\Catalog\Block\Product\AbstractProduct"
name="tweakwise.catalog.linked.product.list.item"
template="Tweakwise_Magento2Tweakwise::product/list/linked-item.phtml"
ifconfig="tweakwise/personal_merchandising/enabled"/>
ifconfig="tweakwise/merchandising_builder/personal_merchandising/enabled"/>
</referenceBlock>
<referenceBlock name="catalog.product.related">
<arguments>
Expand All @@ -38,7 +38,7 @@
<block class="Magento\Catalog\Block\Product\AbstractProduct"
name="tweakwise.catalog.linked.product.list.item"
template="Tweakwise_Magento2Tweakwise::product/list/linked-item.phtml"
ifconfig="tweakwise/personal_merchandising/enabled"/>
ifconfig="tweakwise/merchandising_builder/personal_merchandising/enabled"/>
</referenceBlock>
</body>
</page>
2 changes: 1 addition & 1 deletion view/frontend/layout/catalogsearch_result_index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
</block>
</referenceBlock>
<referenceBlock name="content">
<block class="Magento\Framework\View\Element\Template" name="magento2tweakwise.analytics" template="Tweakwise_Magento2Tweakwise::analytics.phtml" ifconfig="tweakwise/personal_merchandising/analytics_enabled">
<block class="Magento\Framework\View\Element\Template" name="magento2tweakwise.analytics" template="Tweakwise_Magento2Tweakwise::analytics.phtml" ifconfig="tweakwise/merchandising_builder/personal_merchandising/analytics_enabled">
<arguments>
<argument name="viewModel" xsi:type="object">Tweakwise\Magento2Tweakwise\ViewModel\PersonalMerchandisingAnalytics</argument>
<argument name="analyticsType" xsi:type="string">search</argument>
Expand Down
Loading