From 997c67c33b8d08eaa1084985ca8d18937f61b431 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 6 Nov 2024 10:42:05 +0100 Subject: [PATCH 01/32] feat: tweakwise analytics api --- Block/Catalog/Product/ProductPage.php | 40 +++++++++++++++++++ view/frontend/layout/catalog_product_view.xml | 28 ++++++++----- view/frontend/templates/product/page.phtml | 4 ++ view/frontend/web/js/product_page.js | 26 ++++++++++++ 4 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 Block/Catalog/Product/ProductPage.php create mode 100644 view/frontend/templates/product/page.phtml create mode 100644 view/frontend/web/js/product_page.js diff --git a/Block/Catalog/Product/ProductPage.php b/Block/Catalog/Product/ProductPage.php new file mode 100644 index 00000000..aea939f7 --- /dev/null +++ b/Block/Catalog/Product/ProductPage.php @@ -0,0 +1,40 @@ +tweakwiseConfig->getOrSetProfileKey(); + } + + public function getProductKey() + { + return 'test'; + } + + public function getApiUrl() + { + return 'https://navigator-analytics.tweakwise.com/api/pageview'; + } + + public function getInstanceKey() + { + return $this->tweakwiseConfig->getGeneralAuthenticationKey(); + } +} diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml index b6a0211b..6422bb8c 100644 --- a/view/frontend/layout/catalog_product_view.xml +++ b/view/frontend/layout/catalog_product_view.xml @@ -9,18 +9,24 @@ --> + + diff --git a/view/frontend/web/js/product-page.js b/view/frontend/web/js/product-page.js new file mode 100644 index 00000000..fd9302e8 --- /dev/null +++ b/view/frontend/web/js/product-page.js @@ -0,0 +1,48 @@ +define('Tweakwise_Magento2Tweakwise/js/product-page', ['jquery'], function($) { + 'use strict'; + + function getCookie(name) { + const value = `; ${document.cookie}`; + const parts = value.split(`; ${name}=`); + if (parts.length === 2) return parts.pop().split(';').shift(); + } + + function setCookie(name, value, days) { + const date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + const expires = `expires=${date.toUTCString()}`; + document.cookie = `${name}=${value}; ${expires}; path=/`; + } + + return function(config) { + $(document).ready(function() { + var apiUrl = config.apiUrl; + var productKey = config.productKey; + var instanceKey = config.instanceKey; + var cookieName = config.tweakwiseCookieName; + + //check cookie for profile key + var profileKey = getCookie(cookieName); + //if cookie not set, generate an random profile key + if (!profileKey) { + profileKey = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + setCookie(cookieName, profileKey, { expires: 365, path: '/' }); + } + + $.ajax({ + url: apiUrl, + method: 'POST', + headers: { + 'Instance-Key': instanceKey + }, + data: { + profileKey: profileKey, + productKey: productKey + }, + error: function(error) { + console.error('Tweakwise API call failed:', error); + } + }); + }); + }; +}); From cabb16d016e9aef9304427f94920b1bd36fef062 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:11:28 +0100 Subject: [PATCH 03/32] Wip --- Block/Product/ListSearchProduct.php | 139 ++++++++++++++++++ etc/frontend/di.xml | 5 + .../layout/catalogsearch_result_index.xml | 26 ++++ 3 files changed, 170 insertions(+) create mode 100644 Block/Product/ListSearchProduct.php diff --git a/Block/Product/ListSearchProduct.php b/Block/Product/ListSearchProduct.php new file mode 100644 index 00000000..19a05961 --- /dev/null +++ b/Block/Product/ListSearchProduct.php @@ -0,0 +1,139 @@ +cacheHelper->personalMerchandisingCanBeApplied() || + $this->cacheHelper->isTweakwiseAjaxRequest() + ) { + return parent::getCacheLifetime(); + } + + $this->setData('ttl', Cache::PRODUCT_LIST_TTL); + $this->setData('cache_lifetime', Cache::PRODUCT_LIST_TTL); + return $this->getData('cache_lifetime'); + } + + /** + * @param string $route + * @param array $params + * @return string + */ + public function getUrl($route = '', $params = []) + { + if ( + !$this->cacheHelper->personalMerchandisingCanBeApplied() || + $route !== 'page_cache/block/esi' + ) { + return parent::getUrl($route, $params); + } + + $queryParams = []; + $profileKey = $this->getProfileKey(); + if ($profileKey) { + $queryParams['tn_pk'] = $profileKey; + } + + $category = $this->registry->registry('current_category'); + if ($category) { + $queryParams['cc_id'] = $category->getId(); + } + + $queryParams = array_merge($this->request->getParams(), $queryParams); + $params['_query'] = $queryParams; + + return parent::getUrl($route, $params); + } + + /** + * @return string + */ + public function getTemplate() + { + if ( + !$this->cacheHelper->personalMerchandisingCanBeApplied() || + $this->cacheHelper->isHyvaTheme() + ) { + return parent::getTemplate(); + } + + return 'Tweakwise_Magento2Tweakwise::product/list.phtml'; + } + + /** + * @return string|null + */ + private function getProfileKey(): ?string + { + return $this->cookieManager->getCookie( + $this->tweakwiseConfig->getPersonalMerchandisingCookieName(), + null + ); + } + + public function _getProductCollection() + { + return parent::_getProductCollection(); + } +} diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 9a7da881..46a9f965 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -23,6 +23,11 @@ + + + Tweakwise\Magento2Tweakwise\ViewModel\LinkedProductListItem + + Tweakwise\Magento2Tweakwise\Model\NavigationConfig\Search + + @@ -28,6 +36,24 @@ + + + Tweakwise_Magento2Tweakwise::product/list.phtml + + + + Tweakwise\Magento2Tweakwise\ViewModel\ProductListItem + + + + + Tweakwise\Magento2Tweakwise\Model\NavigationConfig\Search From b403649841a2b4d22a17fd5526adee3289ee3db1 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:59:06 +0100 Subject: [PATCH 04/32] Wip --- etc/frontend/di.xml | 7 ++----- view/frontend/layout/catalogsearch_result_index.xml | 3 --- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 46a9f965..fd21aa96 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -23,11 +23,8 @@ - - - Tweakwise\Magento2Tweakwise\ViewModel\LinkedProductListItem - - + - - Tweakwise_Magento2Tweakwise::product/list.phtml - Tweakwise\Magento2Tweakwise\ViewModel\ProductListItem From 61b44ec8b7b948f4190d9bbc8940653f7f9cda1d Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 15 Nov 2024 13:47:29 +0100 Subject: [PATCH 05/32] Fix search results --- Block/Product/ListSearchProduct.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Block/Product/ListSearchProduct.php b/Block/Product/ListSearchProduct.php index 19a05961..4824d623 100644 --- a/Block/Product/ListSearchProduct.php +++ b/Block/Product/ListSearchProduct.php @@ -9,6 +9,7 @@ use Magento\Catalog\Block\Product\ListProduct as MagentoListProduct; use Magento\Catalog\Helper\Output as OutputHelper; use Magento\Catalog\Model\Layer\Resolver; +use Magento\Catalog\Model\Layer\Search as SearchLayer; use Magento\Framework\App\RequestInterface; use Magento\Framework\Data\Helper\PostHelper; use Magento\Framework\Registry; @@ -44,6 +45,7 @@ public function __construct( private readonly Cache $cacheHelper, private readonly Registry $registry, private readonly RequestInterface $request, + readonly SearchLayer $searchLayer, array $data = [], ?OutputHelper $outputHelper = null ) { @@ -58,6 +60,11 @@ public function __construct( ); } + public function getLayer() + { + return $this->searchLayer; + } + /** * @return int|bool|null */ From 136e7d0f5eb555a49e09627be6d3fb6ede034ee5 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 15 Nov 2024 14:12:42 +0100 Subject: [PATCH 06/32] Update ListSearchProduct.php --- Block/Product/ListSearchProduct.php | 90 +++-------------------------- 1 file changed, 8 insertions(+), 82 deletions(-) diff --git a/Block/Product/ListSearchProduct.php b/Block/Product/ListSearchProduct.php index 4824d623..f0b5a8df 100644 --- a/Block/Product/ListSearchProduct.php +++ b/Block/Product/ListSearchProduct.php @@ -6,7 +6,7 @@ use Magento\Catalog\Api\CategoryRepositoryInterface; use Magento\Catalog\Block\Product\Context; -use Magento\Catalog\Block\Product\ListProduct as MagentoListProduct; +use Tweakwise\Magento2Tweakwise\Block\Product\ListProduct; use Magento\Catalog\Helper\Output as OutputHelper; use Magento\Catalog\Model\Layer\Resolver; use Magento\Catalog\Model\Layer\Search as SearchLayer; @@ -18,7 +18,7 @@ use Tweakwise\Magento2Tweakwise\Model\Config; use Tweakwise\Magento2Tweakwise\Helper\Cache; -class ListSearchProduct extends MagentoListProduct +class ListSearchProduct extends ListProduct { /** * @param Context $context @@ -45,7 +45,7 @@ public function __construct( private readonly Cache $cacheHelper, private readonly Registry $registry, private readonly RequestInterface $request, - readonly SearchLayer $searchLayer, + private readonly SearchLayer $searchLayer, array $data = [], ?OutputHelper $outputHelper = null ) { @@ -55,6 +55,11 @@ public function __construct( $layerResolver, $categoryRepository, $urlHelper, + $tweakwiseConfig, + $cookieManager, + $cacheHelper, + $registry, + $request, $data, $outputHelper ); @@ -64,83 +69,4 @@ public function getLayer() { return $this->searchLayer; } - - /** - * @return int|bool|null - */ - protected function getCacheLifetime() - { - if ( - !$this->cacheHelper->personalMerchandisingCanBeApplied() || - $this->cacheHelper->isTweakwiseAjaxRequest() - ) { - return parent::getCacheLifetime(); - } - - $this->setData('ttl', Cache::PRODUCT_LIST_TTL); - $this->setData('cache_lifetime', Cache::PRODUCT_LIST_TTL); - return $this->getData('cache_lifetime'); - } - - /** - * @param string $route - * @param array $params - * @return string - */ - public function getUrl($route = '', $params = []) - { - if ( - !$this->cacheHelper->personalMerchandisingCanBeApplied() || - $route !== 'page_cache/block/esi' - ) { - return parent::getUrl($route, $params); - } - - $queryParams = []; - $profileKey = $this->getProfileKey(); - if ($profileKey) { - $queryParams['tn_pk'] = $profileKey; - } - - $category = $this->registry->registry('current_category'); - if ($category) { - $queryParams['cc_id'] = $category->getId(); - } - - $queryParams = array_merge($this->request->getParams(), $queryParams); - $params['_query'] = $queryParams; - - return parent::getUrl($route, $params); - } - - /** - * @return string - */ - public function getTemplate() - { - if ( - !$this->cacheHelper->personalMerchandisingCanBeApplied() || - $this->cacheHelper->isHyvaTheme() - ) { - return parent::getTemplate(); - } - - return 'Tweakwise_Magento2Tweakwise::product/list.phtml'; - } - - /** - * @return string|null - */ - private function getProfileKey(): ?string - { - return $this->cookieManager->getCookie( - $this->tweakwiseConfig->getPersonalMerchandisingCookieName(), - null - ); - } - - public function _getProductCollection() - { - return parent::_getProductCollection(); - } } From 01f4f342191486b094cd81b0676e428d149614b3 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 19 Nov 2024 09:42:53 +0100 Subject: [PATCH 07/32] Wip --- Block/Product/ListProduct.php | 9 +++- Block/Product/ListSearchProduct.php | 72 ----------------------------- etc/frontend/di.xml | 10 +++- 3 files changed, 16 insertions(+), 75 deletions(-) delete mode 100644 Block/Product/ListSearchProduct.php diff --git a/Block/Product/ListProduct.php b/Block/Product/ListProduct.php index 627be40c..952a9ae2 100644 --- a/Block/Product/ListProduct.php +++ b/Block/Product/ListProduct.php @@ -8,6 +8,7 @@ use Magento\Catalog\Block\Product\Context; use Magento\Catalog\Block\Product\ListProduct as MagentoListProduct; use Magento\Catalog\Helper\Output as OutputHelper; +use Magento\Catalog\Model\Layer; use Magento\Catalog\Model\Layer\Resolver; use Magento\Framework\App\RequestInterface; use Magento\Framework\Data\Helper\PostHelper; @@ -32,6 +33,7 @@ class ListProduct extends MagentoListProduct * @param RequestInterface $request * @param array $data * @param OutputHelper|null $outputHelper + * @param Layer|null $catalogLayer */ public function __construct( Context $context, @@ -45,7 +47,8 @@ public function __construct( private readonly Registry $registry, private readonly RequestInterface $request, array $data = [], - ?OutputHelper $outputHelper = null + ?OutputHelper $outputHelper = null, + ?Layer $catalogLayer = null ) { parent::__construct( $context, @@ -56,6 +59,10 @@ public function __construct( $data, $outputHelper ); + + if ($catalogLayer) { + $this->_catalogLayer = $catalogLayer; + } } /** diff --git a/Block/Product/ListSearchProduct.php b/Block/Product/ListSearchProduct.php deleted file mode 100644 index f0b5a8df..00000000 --- a/Block/Product/ListSearchProduct.php +++ /dev/null @@ -1,72 +0,0 @@ -searchLayer; - } -} diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index fd21aa96..34d579f8 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -21,10 +21,16 @@ + + + Magento\Catalog\Model\Layer\Search + + + - Date: Wed, 20 Nov 2024 10:07:07 +0100 Subject: [PATCH 08/32] Wip --- ...php => PersonalMerchandisingAnalytics.php} | 27 ++++++--- Model/PersonalMerchandising.php | 58 ------------------- .../layout/catalogsearch_result_index.xml | 4 ++ view/frontend/templates/product/page.phtml | 10 ++-- view/frontend/templates/search/page.phtml | 21 +++++++ view/frontend/web/js/product_page.js | 26 --------- view/frontend/web/js/search-page.js | 48 +++++++++++++++ 7 files changed, 96 insertions(+), 98 deletions(-) rename Block/Catalog/{Product/ProductPage.php => PersonalMerchandisingAnalytics.php} (62%) delete mode 100644 Model/PersonalMerchandising.php create mode 100644 view/frontend/templates/search/page.phtml delete mode 100644 view/frontend/web/js/product_page.js create mode 100644 view/frontend/web/js/search-page.js diff --git a/Block/Catalog/Product/ProductPage.php b/Block/Catalog/PersonalMerchandisingAnalytics.php similarity index 62% rename from Block/Catalog/Product/ProductPage.php rename to Block/Catalog/PersonalMerchandisingAnalytics.php index 638828f9..d16b4f60 100644 --- a/Block/Catalog/Product/ProductPage.php +++ b/Block/Catalog/PersonalMerchandisingAnalytics.php @@ -1,46 +1,55 @@ getRequest()->getParam('id'); $storeId = $this->storeManager->getStore()->getId(); + if (!$productId) { + return 0; + } + return $this->helper->getTweakwiseId($storeId, $productId); } - public function getApiUrl() + public function getApiUrl(): string { - return 'https://navigator-analytics.tweakwise.com/api/pageview'; + return 'https://navigator-analytics.tweakwise.com/api/'; } - public function getInstanceKey() + public function getInstanceKey(): string { return $this->tweakwiseConfig->getGeneralAuthenticationKey(); } - public function getCookieName() + public function getCookieName(): string { return $this->tweakwiseConfig->getPersonalMerchandisingCookieName(); } + + public function getSearchQuery(): string + { + return $this->getRequest()->getParam('q'); + } } diff --git a/Model/PersonalMerchandising.php b/Model/PersonalMerchandising.php deleted file mode 100644 index 4fc30bd9..00000000 --- a/Model/PersonalMerchandising.php +++ /dev/null @@ -1,58 +0,0 @@ -config->getPersonalMerchandisingCookieName(); - - if (empty($cookieName)) { - $cookieName = 'tw_analytics'; - } - - $profileKey = $this->cookieManager->getCookie( - $cookieName, - null - ); - - //if there is no profile key, generate an profileKey and save it in the cookie - if (!$profileKey) { - $profileKey = $this->generateProfileKey(); - - $metadata = $this->cookieMetadataFactory - ->createPublicCookieMetadata() - ->setDuration(86400) // Cookie will expire after one day (86400 seconds) - ->setSecure(true) //the cookie is only available under HTTPS - ->setPath('/')// The cookie will be available to all pages and subdirectories within the /subfolder path - ->setHttpOnly(false); - - $this->cookieManager->setPublicCookie( - $cookieName, - $profileKey, - $metadata - ); - } - - return $profileKey; - } - - private function generateProfileKey(): string - { - return sha1(random_bytes(18)); - } -} diff --git a/view/frontend/layout/catalogsearch_result_index.xml b/view/frontend/layout/catalogsearch_result_index.xml index 89af652d..418c62ab 100644 --- a/view/frontend/layout/catalogsearch_result_index.xml +++ b/view/frontend/layout/catalogsearch_result_index.xml @@ -6,6 +6,9 @@ */ --> + + diff --git a/view/frontend/web/js/product_page.js b/view/frontend/web/js/product_page.js deleted file mode 100644 index 53cbd5bf..00000000 --- a/view/frontend/web/js/product_page.js +++ /dev/null @@ -1,26 +0,0 @@ -define(['jquery'], function($) { - 'use strict'; - - return function(config) { - $(document).ready(function() { - var apiUrl = config.apiUrl; - var profileKey = config.profileKey; - var productKey = config.productKey; - - $.ajax({ - url: apiUrl, - method: 'POST', - data: { - profileKey: profileKey, - productKey: productKey - }, - success: function(response) { - console.log(response); - }, - error: function(error) { - console.error('Tweakwise API call failed:', error); - } - }); - }); - }; -}); diff --git a/view/frontend/web/js/search-page.js b/view/frontend/web/js/search-page.js new file mode 100644 index 00000000..42296953 --- /dev/null +++ b/view/frontend/web/js/search-page.js @@ -0,0 +1,48 @@ +define('Tweakwise_Magento2Tweakwise/js/search-page', ['jquery'], function($) { + 'use strict'; + + function getCookie(name) { + const value = `; ${document.cookie}`; + const parts = value.split(`; ${name}=`); + if (parts.length === 2) return parts.pop().split(';').shift(); + } + + function setCookie(name, value, days) { + const date = new Date(); + date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); + const expires = `expires=${date.toUTCString()}`; + document.cookie = `${name}=${value}; ${expires}; path=/`; + } + + return function(config) { + $(document).ready(function() { + var apiUrl = config.apiUrl; + var searchQuery = config.searchQuery; + var instanceKey = config.instanceKey; + var cookieName = config.tweakwiseCookieName; + + //check cookie for profile key + var profileKey = getCookie(cookieName); + //if cookie not set, generate an random profile key + if (!profileKey) { + profileKey = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); + setCookie(cookieName, profileKey, { expires: 365, path: '/' }); + } + + $.ajax({ + url: apiUrl, + method: 'POST', + headers: { + 'Instance-Key': instanceKey + }, + data: { + profileKey: profileKey, + searchTerm: searchQuery + }, + error: function(error) { + console.error('Tweakwise API call failed:', error); + } + }); + }); + }; +}); From 2e95bc8f4ca31d47cf9bc1633496d31fb30d0072 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 20 Nov 2024 13:31:17 +0100 Subject: [PATCH 09/32] Add purshase request --- Model/Client.php | 41 +++++++++++---- Model/Client/Request.php | 11 ++++ Model/Client/Request/PurchaseRequest.php | 43 +++++++++++++++ Observer/TweakwiseCheckout.php | 66 ++++++++++++++++++++++++ etc/adminhtml/system.xml | 7 ++- etc/config.xml | 1 + etc/di.xml | 11 +++- etc/events.xml | 3 ++ 8 files changed, 172 insertions(+), 11 deletions(-) create mode 100644 Model/Client/Request/PurchaseRequest.php create mode 100644 Observer/TweakwiseCheckout.php diff --git a/Model/Client.php b/Model/Client.php index 18ee7fcf..2d53154c 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -71,16 +71,13 @@ class Client * @param Logger $log * @param ResponseFactory $responseFactory * @param EndpointManager $endpointManager - * @param Timer $timer - * @param ModuleInformation $moduleInformation */ public function __construct( Config $config, Logger $log, ResponseFactory $responseFactory, EndpointManager $endpointManager, - Timer $timer, - private readonly ModuleInformation $moduleInformation + Timer $timer ) { $this->config = $config; $this->log = $log; @@ -99,8 +96,7 @@ protected function getClient(): HttpClient RequestOptions::TIMEOUT => self::REQUEST_TIMEOUT, RequestOptions::HEADERS => [ 'user-agent' => $this->config->getUserAgentString(), - 'Accept-Encoding' => 'gzip, deflate', - 'TWN-Source' => $this->moduleInformation->getModuleVersion(), + 'Accept-Encoding' => 'gzip, deflate' ] ]; $this->client = new HttpClient($options); @@ -114,10 +110,34 @@ protected function getClient(): HttpClient * @return HttpRequest */ protected function createHttpRequest(Request $tweakwiseRequest): HttpRequest + { + if ($tweakwiseRequest->isPostRequest()) { + return $this->createPostRequest($tweakwiseRequest); + } else { + return $this->createGetRequest($tweakwiseRequest); + } + } + + protected function createPostRequest(Request $tweakwiseRequest): HttpRequest + { + $path = $tweakwiseRequest->getPath(); + $headers = []; + + $headers['Content-Type'] = 'application/json'; + $headers['Instance-Key'] = $this->config->getGeneralAuthenticationKey(); + $body = json_encode($tweakwiseRequest->getParameters()); + //post request are used for the analytics api + $uri = new Uri($tweakwiseRequest->getApiUrl().'/'.$path); + return new HttpRequest('POST', $uri, $headers, $body); + } + + protected function createGetRequest(Request $tweakwiseRequest): HttpRequest { $path = $tweakwiseRequest->getPath(); $pathSuffix = $tweakwiseRequest->getPathSuffix(); + $headers = []; + if ($path === "recommendations/featured") { if ($this->config->getRecommendationsFeaturedCategory()) { $tweakwiseRequest->setCategory(); @@ -134,12 +154,11 @@ protected function createHttpRequest(Request $tweakwiseRequest): HttpRequest if ($tweakwiseRequest->getParameters()) { $query = http_build_query($tweakwiseRequest->getParameters()); - $url = sprintf('%s?%s', $url, $query); + $url = sprintf('%s?%s', $url, $query); } $uri = new Uri($url); - - return new HttpRequest('GET', $uri); + return new HttpRequest('GET', $uri, $headers); } /** @@ -208,6 +227,10 @@ public function handleRequestSuccess( ) ); + if ($statusCode === 204) { + return $this->responseFactory->create($tweakwiseRequest, []); + } + if ($statusCode !== 200) { throw new ApiException( sprintf( diff --git a/Model/Client/Request.php b/Model/Client/Request.php index 233124bf..7b076785 100644 --- a/Model/Client/Request.php +++ b/Model/Client/Request.php @@ -326,4 +326,15 @@ public function setProfileKey(string $profileKey) $this->setParameter('tn_profilekey', $profileKey); return $this; } + + public function setParameterArray(string $parameter, array $value) + { + $this->parameters[$parameter] = $value; + return $this; + } + + public function isPostRequest() + { + return false; + } } diff --git a/Model/Client/Request/PurchaseRequest.php b/Model/Client/Request/PurchaseRequest.php new file mode 100644 index 00000000..c10c11fa --- /dev/null +++ b/Model/Client/Request/PurchaseRequest.php @@ -0,0 +1,43 @@ +apiUrl; + } + + public function setProfileKey(string $profileKey) + { + $this->setParameter('ProfileKey', $profileKey); + } +} diff --git a/Observer/TweakwiseCheckout.php b/Observer/TweakwiseCheckout.php new file mode 100644 index 00000000..3d205929 --- /dev/null +++ b/Observer/TweakwiseCheckout.php @@ -0,0 +1,66 @@ +config->isPersonalMerchandisingActive()) { + $order = $observer->getEvent()->getOrder(); + // Get the order items + $items = $order->getAllItems(); + + $this->sendCheckout($items); + } + } + + private function sendCheckout($items) + { + $storeId = (int)$this->storeManager->getStore()->getId(); + $profileKey = $this->cookieManager->getCookie( + $this->config->getPersonalMerchandisingCookieName(), + null + ); + $tweakwiseRequest = $this->requestFactory->create(); + + $tweakwiseRequest->setParameter('profileKey', $profileKey); + $tweakwiseRequest->setPath('purchase'); + + foreach ($items as $item) { + $productTwId[] = $this->helper->getTweakwiseId($storeId, (int)$item->getProductId()); + } + + $tweakwiseRequest->setParameterArray('ProductKeys', $productTwId); + + try { + $this->client->request($tweakwiseRequest); + } catch (ApiException $e) { + // Log error + $this->log->error('Purchase request for tw failed: ' . $e->getMessage()); + } + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 0503db62..097860e5 100644 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -235,9 +235,14 @@ setting below) + + + Magento\Config\Model\Config\Source\Yesno + Note only enable this if you don't use javascript to send productviews/search/purchases requests to tweakwise + - Name of cookie which holds tweakwise profile information, this is usually set in the tweakwise measure script. + 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 1 diff --git a/etc/config.xml b/etc/config.xml index 8b86c9e7..6183c6b7 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -42,6 +42,7 @@ cid 3600 + 0 0 diff --git a/etc/di.xml b/etc/di.xml index 0a1374fa..8676d01a 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -235,6 +235,11 @@ Tweakwise\Magento2Tweakwise\Model\Client\RequestFactory\FacetAttributeRequest + + + Tweakwise\Magento2Tweakwise\Model\Client\RequestFactory\PurchaseRequest + + @@ -418,5 +423,9 @@ Tweakwise\Magento2Tweakwise\Model\Client\Request\Recommendations\FeaturedRequest - + + + Tweakwise\Magento2Tweakwise\Model\Client\Request\PurchaseRequest + + diff --git a/etc/events.xml b/etc/events.xml index 48e717da..8486f01e 100644 --- a/etc/events.xml +++ b/etc/events.xml @@ -5,4 +5,7 @@ instance="Tweakwise\Magento2Tweakwise\Observer\CreateTweakwiseSlugsAfterSaveAttribute" /> + + + From f69937ef28bae69a805175b4b781c3c6ac34515e Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:00:09 +0100 Subject: [PATCH 10/32] Add setting --- Observer/TweakwiseCheckout.php | 14 ++++++++------ view/frontend/layout/catalog_product_view.xml | 2 +- .../frontend/layout/catalogsearch_result_index.xml | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Observer/TweakwiseCheckout.php b/Observer/TweakwiseCheckout.php index 3d205929..ed86bf31 100644 --- a/Observer/TweakwiseCheckout.php +++ b/Observer/TweakwiseCheckout.php @@ -29,12 +29,14 @@ public function __construct( public function execute(Observer $observer) { - if ($this->config->isPersonalMerchandisingActive()) { - $order = $observer->getEvent()->getOrder(); - // Get the order items - $items = $order->getAllItems(); + if ($this->config->getStoreConfig('tweakwise/personal_merchandising/analytics_enabled')) { + if ($this->config->isPersonalMerchandisingActive()) { + $order = $observer->getEvent()->getOrder(); + // Get the order items + $items = $order->getAllItems(); - $this->sendCheckout($items); + $this->sendCheckout($items); + } } } @@ -58,7 +60,7 @@ private function sendCheckout($items) try { $this->client->request($tweakwiseRequest); - } catch (ApiException $e) { + } catch (\Exception $e) { // Log error $this->log->error('Purchase request for tw failed: ' . $e->getMessage()); } diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml index 6422bb8c..dfe314e9 100644 --- a/view/frontend/layout/catalog_product_view.xml +++ b/view/frontend/layout/catalog_product_view.xml @@ -14,7 +14,7 @@ - + diff --git a/view/frontend/layout/catalogsearch_result_index.xml b/view/frontend/layout/catalogsearch_result_index.xml index 418c62ab..18caef79 100644 --- a/view/frontend/layout/catalogsearch_result_index.xml +++ b/view/frontend/layout/catalogsearch_result_index.xml @@ -18,7 +18,7 @@ - + Tweakwise\Magento2Tweakwise\Model\NavigationConfig\Search From c1a26b212d51a00c29174575e16381d39365800d Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:43:32 +0100 Subject: [PATCH 11/32] feat: tweakwise analytics --- Block/Catalog/PersonalMerchandisingAnalytics.php | 4 ++-- view/frontend/layout/catalog_product_view.xml | 5 +---- view/frontend/layout/catalogsearch_result_index.xml | 3 --- view/frontend/templates/product/page.phtml | 1 + view/frontend/templates/search/page.phtml | 1 + 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/Block/Catalog/PersonalMerchandisingAnalytics.php b/Block/Catalog/PersonalMerchandisingAnalytics.php index d16b4f60..b8a4dc8f 100644 --- a/Block/Catalog/PersonalMerchandisingAnalytics.php +++ b/Block/Catalog/PersonalMerchandisingAnalytics.php @@ -21,7 +21,7 @@ public function __construct( parent::__construct($context, $data); } - public function getProductKey(): int + public function getProductKey(): string { $productId = $this->getRequest()->getParam('id'); $storeId = $this->storeManager->getStore()->getId(); @@ -30,7 +30,7 @@ public function getProductKey(): int return 0; } - return $this->helper->getTweakwiseId($storeId, $productId); + return $this->helper->getTweakwiseId((int)$storeId, (int)$productId); } public function getApiUrl(): string diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml index dfe314e9..83015a38 100644 --- a/view/frontend/layout/catalog_product_view.xml +++ b/view/frontend/layout/catalog_product_view.xml @@ -9,12 +9,9 @@ --> - - + diff --git a/view/frontend/templates/search/page.phtml b/view/frontend/templates/search/page.phtml index a9e85328..f4a2226d 100644 --- a/view/frontend/templates/search/page.phtml +++ b/view/frontend/templates/search/page.phtml @@ -19,3 +19,4 @@ $instanceKey = $block->getInstanceKey(); } } + From 944cfc018defb00a1f0d2fcb19cec5c460644394 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:00:18 +0100 Subject: [PATCH 12/32] Style fixes --- Model/Client.php | 2 +- Model/Config.php | 1 + Observer/TweakwiseCheckout.php | 1 + view/frontend/templates/product/page.phtml | 18 +++++++++++------- view/frontend/templates/search/page.phtml | 13 ++++++++----- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/Model/Client.php b/Model/Client.php index 2d53154c..0243cbf8 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -127,7 +127,7 @@ protected function createPostRequest(Request $tweakwiseRequest): HttpRequest $headers['Instance-Key'] = $this->config->getGeneralAuthenticationKey(); $body = json_encode($tweakwiseRequest->getParameters()); //post request are used for the analytics api - $uri = new Uri($tweakwiseRequest->getApiUrl().'/'.$path); + $uri = new Uri($tweakwiseRequest->getApiUrl() . '/'.$path); return new HttpRequest('POST', $uri, $headers, $body); } diff --git a/Model/Config.php b/Model/Config.php index 26248eb9..f02fa57a 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -413,6 +413,7 @@ public function getPersonalMerchandisingCookieName(Store $store = null) if (empty($cookie)) { $cookie = 'tw_analytics'; } + return $cookie; } diff --git a/Observer/TweakwiseCheckout.php b/Observer/TweakwiseCheckout.php index ed86bf31..463c51c8 100644 --- a/Observer/TweakwiseCheckout.php +++ b/Observer/TweakwiseCheckout.php @@ -1,4 +1,5 @@ getCookieName(); -$apiUrl = $block->getApiUrl(); -$productKey = $block->getProductKey(); -$instanceKey = $block->getInstanceKey(); +$apiUrl = $block->getApiUrl(); +$productKey = $block->getProductKey(); +$instanceKey = $block->getInstanceKey(); ?> - + From b15fbe679d4966f06888f799d8731bae1387111e Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:44:37 +0100 Subject: [PATCH 13/32] Fix config --- Model/Config.php | 2 +- Model/PersonalMerchandisingConfig.php | 15 +++++++++++++++ Observer/TweakwiseCheckout.php | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 Model/PersonalMerchandisingConfig.php diff --git a/Model/Config.php b/Model/Config.php index f02fa57a..9f1cfe3a 100644 --- a/Model/Config.php +++ b/Model/Config.php @@ -541,7 +541,7 @@ public function getSearchLanguage(Store $store = null) * @return mixed|string|null * @throws LocalizedException */ - public function getStoreConfig(string $path, Store $store = null) + protected function getStoreConfig(string $path, Store $store = null) { if ($store) { return $store->getConfig($path); diff --git a/Model/PersonalMerchandisingConfig.php b/Model/PersonalMerchandisingConfig.php new file mode 100644 index 00000000..e3b3f296 --- /dev/null +++ b/Model/PersonalMerchandisingConfig.php @@ -0,0 +1,15 @@ +getStoreConfig('tweakwise/personal_merchandising/analytics_enabled', $store); + } +} diff --git a/Observer/TweakwiseCheckout.php b/Observer/TweakwiseCheckout.php index 463c51c8..a3c6170b 100644 --- a/Observer/TweakwiseCheckout.php +++ b/Observer/TweakwiseCheckout.php @@ -12,25 +12,35 @@ use Tweakwise\Magento2Tweakwise\Model\Client; use Tweakwise\Magento2Tweakwise\Model\Client\RequestFactory; use Magento\Framework\App\Request\Http as Request; +use Tweakwise\Magento2Tweakwise\Model\PersonalMerchandisingConfig; use Tweakwise\Magento2TweakwiseExport\Model\Helper; use Magento\Store\Model\StoreManagerInterface; -use Tweakwise\Magento2Tweakwise\Model\Config; class TweakwiseCheckout implements ObserverInterface { + /** + * Constructor. + * + * @param RequestFactory $requestFactory + * @param Client $client + * @param Helper $helper + * @param StoreManagerInterface $storeManager + * @param PersonalMerchandisingConfig $config + * @param CookieManagerInterface $cookieManager + */ public function __construct( private readonly RequestFactory $requestFactory, private readonly Client $client, private readonly Helper $helper, private readonly StoreManagerInterface $storeManager, - private readonly Config $config, + private readonly PersonalMerchandisingConfig $config, private readonly CookieManagerInterface $cookieManager ) { } public function execute(Observer $observer) { - if ($this->config->getStoreConfig('tweakwise/personal_merchandising/analytics_enabled')) { + if ($this->config->isAnalyticsEnabled('tweakwise/personal_merchandising/analytics_enabled')) { if ($this->config->isPersonalMerchandisingActive()) { $order = $observer->getEvent()->getOrder(); // Get the order items From 02b3907dca77fac448e3e17f69c20d8f132f7ea8 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:47:42 +0100 Subject: [PATCH 14/32] Style fixes --- Model/Client.php | 2 +- view/frontend/templates/product/page.phtml | 2 +- view/frontend/templates/search/page.phtml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Model/Client.php b/Model/Client.php index 0243cbf8..8b38d549 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -127,7 +127,7 @@ protected function createPostRequest(Request $tweakwiseRequest): HttpRequest $headers['Instance-Key'] = $this->config->getGeneralAuthenticationKey(); $body = json_encode($tweakwiseRequest->getParameters()); //post request are used for the analytics api - $uri = new Uri($tweakwiseRequest->getApiUrl() . '/'.$path); + $uri = new Uri($tweakwiseRequest->getApiUrl() . '/' . $path); return new HttpRequest('POST', $uri, $headers, $body); } diff --git a/view/frontend/templates/product/page.phtml b/view/frontend/templates/product/page.phtml index 7fd856e1..f72cea5d 100644 --- a/view/frontend/templates/product/page.phtml +++ b/view/frontend/templates/product/page.phtml @@ -23,4 +23,4 @@ $instanceKey = $block->getInstanceKey(); } } - + diff --git a/view/frontend/templates/search/page.phtml b/view/frontend/templates/search/page.phtml index 6fb3ce81..515bfd6e 100644 --- a/view/frontend/templates/search/page.phtml +++ b/view/frontend/templates/search/page.phtml @@ -22,4 +22,4 @@ $instanceKey = $block->getInstanceKey(); } } - + From 53a51422f2ba73c0a3300fa6b3c84e973e38414a Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Wed, 4 Dec 2024 13:47:14 +0100 Subject: [PATCH 15/32] Move personalised search result to seperate pull request --- Block/Product/ListProduct.php | 9 +-------- .../layout/catalogsearch_result_index.xml | 16 ---------------- 2 files changed, 1 insertion(+), 24 deletions(-) diff --git a/Block/Product/ListProduct.php b/Block/Product/ListProduct.php index 952a9ae2..627be40c 100644 --- a/Block/Product/ListProduct.php +++ b/Block/Product/ListProduct.php @@ -8,7 +8,6 @@ use Magento\Catalog\Block\Product\Context; use Magento\Catalog\Block\Product\ListProduct as MagentoListProduct; use Magento\Catalog\Helper\Output as OutputHelper; -use Magento\Catalog\Model\Layer; use Magento\Catalog\Model\Layer\Resolver; use Magento\Framework\App\RequestInterface; use Magento\Framework\Data\Helper\PostHelper; @@ -33,7 +32,6 @@ class ListProduct extends MagentoListProduct * @param RequestInterface $request * @param array $data * @param OutputHelper|null $outputHelper - * @param Layer|null $catalogLayer */ public function __construct( Context $context, @@ -47,8 +45,7 @@ public function __construct( private readonly Registry $registry, private readonly RequestInterface $request, array $data = [], - ?OutputHelper $outputHelper = null, - ?Layer $catalogLayer = null + ?OutputHelper $outputHelper = null ) { parent::__construct( $context, @@ -59,10 +56,6 @@ public function __construct( $data, $outputHelper ); - - if ($catalogLayer) { - $this->_catalogLayer = $catalogLayer; - } } /** diff --git a/view/frontend/layout/catalogsearch_result_index.xml b/view/frontend/layout/catalogsearch_result_index.xml index 94c2345b..cf20d13d 100644 --- a/view/frontend/layout/catalogsearch_result_index.xml +++ b/view/frontend/layout/catalogsearch_result_index.xml @@ -21,14 +21,6 @@ Tweakwise\Magento2Tweakwise\Model\NavigationConfig\Search - - @@ -43,14 +35,6 @@ Tweakwise\Magento2Tweakwise\ViewModel\ProductListItem - - From ffb2038760f197c3247100db00a6eb8bdb5a8827 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Thu, 5 Dec 2024 13:57:16 +0100 Subject: [PATCH 16/32] Wip --- Controller/Ajax/Analytics.php | 44 ++++++++++++++++++++++++++++ view/frontend/web/js/product-page.js | 31 ++------------------ 2 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 Controller/Ajax/Analytics.php diff --git a/Controller/Ajax/Analytics.php b/Controller/Ajax/Analytics.php new file mode 100644 index 00000000..ae4eade0 --- /dev/null +++ b/Controller/Ajax/Analytics.php @@ -0,0 +1,44 @@ +resultJsonFactory = $resultJsonFactory; + $this->curl = $curl; + parent::__construct($context); + } + + public function execute() + { + $result = $this->resultJsonFactory->create(); + $type = $this->getRequest()->getParam('type'); + + if ($type === 'product') { + $productKey = $this->getRequest()->getParam('productKey'); + } + + try { + + $response = $this->curl->getBody(); + $result->setData(['success' => true, 'response' => $response]); + } catch (\Exception $e) { + $result->setData(['success' => false, 'message' => $e->getMessage()]); + } + + return $result; + } +} diff --git a/view/frontend/web/js/product-page.js b/view/frontend/web/js/product-page.js index fd9302e8..a4a90c7b 100644 --- a/view/frontend/web/js/product-page.js +++ b/view/frontend/web/js/product-page.js @@ -1,42 +1,15 @@ define('Tweakwise_Magento2Tweakwise/js/product-page', ['jquery'], function($) { 'use strict'; - function getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); - } - - function setCookie(name, value, days) { - const date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - const expires = `expires=${date.toUTCString()}`; - document.cookie = `${name}=${value}; ${expires}; path=/`; - } - return function(config) { $(document).ready(function() { - var apiUrl = config.apiUrl; var productKey = config.productKey; - var instanceKey = config.instanceKey; - var cookieName = config.tweakwiseCookieName; - - //check cookie for profile key - var profileKey = getCookie(cookieName); - //if cookie not set, generate an random profile key - if (!profileKey) { - profileKey = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); - setCookie(cookieName, profileKey, { expires: 365, path: '/' }); - } $.ajax({ - url: apiUrl, + url: '/tweakwise/ajax/analytics', method: 'POST', - headers: { - 'Instance-Key': instanceKey - }, data: { - profileKey: profileKey, + type: 'product', productKey: productKey }, error: function(error) { From dbcd9ee000ed60f8f1ace9b9ff0efe9fd238d0f4 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:17:45 +0100 Subject: [PATCH 17/32] Refactor --- Controller/Ajax/Analytics.php | 64 +++++++++++++++------- Model/Client/Request/AnalyticsRequest.php | 53 ++++++++++++++++++ Model/Client/Request/PurchaseRequest.php | 11 ++++ Model/PersonalMerchandisingConfig.php | 67 +++++++++++++++++++++++ Observer/TweakwiseCheckout.php | 34 +++++++----- etc/di.xml | 10 ++++ view/frontend/web/js/search-page.js | 31 +---------- 7 files changed, 207 insertions(+), 63 deletions(-) create mode 100644 Model/Client/Request/AnalyticsRequest.php diff --git a/Controller/Ajax/Analytics.php b/Controller/Ajax/Analytics.php index ae4eade0..06546e00 100644 --- a/Controller/Ajax/Analytics.php +++ b/Controller/Ajax/Analytics.php @@ -1,44 +1,68 @@ resultJsonFactory = $resultJsonFactory; - $this->curl = $curl; parent::__construct($context); } + /** + * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface + */ public function execute() { $result = $this->resultJsonFactory->create(); - $type = $this->getRequest()->getParam('type'); + if ($this->config->isAnalyticsEnabled()) { - if ($type === 'product') { - $productKey = $this->getRequest()->getParam('productKey'); - } + $type = $this->getRequest()->getParam('type'); + $profileKey = $this->config->getProfileKey(); - try { + $tweakwiseRequest = $this->requestFactory->create(); + $tweakwiseRequest->setProfileKey($profileKey); - $response = $this->curl->getBody(); - $result->setData(['success' => true, 'response' => $response]); - } catch (\Exception $e) { - $result->setData(['success' => false, 'message' => $e->getMessage()]); - } + if ($type === 'product') { + $productKey = $this->getRequest()->getParam('productKey'); + $tweakwiseRequest->setParameter('productKey', $productKey); + $tweakwiseRequest->setPath('pageview'); + } elseif ($type === 'search') { + $searchTerm = $this->getRequest()->getParam('searchTerm'); + $tweakwiseRequest->setParameter('searchTerm', $searchTerm); + $tweakwiseRequest->setPath('search'); + } + try { + $this->client->request($tweakwiseRequest); + $result->setData(['success' => true]); + } catch (\Exception $e) { + $result->setData(['success' => false, 'message' => $e->getMessage()]); + } + } return $result; } } diff --git a/Model/Client/Request/AnalyticsRequest.php b/Model/Client/Request/AnalyticsRequest.php new file mode 100644 index 00000000..a1dbc0c0 --- /dev/null +++ b/Model/Client/Request/AnalyticsRequest.php @@ -0,0 +1,53 @@ +apiUrl; + } + + public function setProfileKey(string $profileKey) + { + $this->setParameter('ProfileKey', $profileKey); + } + + public function setPath($path) + { + $this->path = $path; + } + + public function getProfileKey() + { + $profileKey = $this->getCookie($this->config->getPersonalMerchandisingCookieName()); + if (!$profileKey) { + $profileKey = $this->generateProfileKey(); + $this->setCookie('profileKey', $profileKey); + } + return $profileKey; + } +} diff --git a/Model/Client/Request/PurchaseRequest.php b/Model/Client/Request/PurchaseRequest.php index c10c11fa..094ee3aa 100644 --- a/Model/Client/Request/PurchaseRequest.php +++ b/Model/Client/Request/PurchaseRequest.php @@ -26,16 +26,27 @@ class PurchaseRequest extends Request protected $apiUrl = 'https://navigator-analytics.tweakwise.com/api'; + /** + * @return true + */ public function isPostRequest() { return true; } + /** + * @return mixed|string + */ public function getApiurl() { return $this->apiUrl; } + /** + * @param string $profileKey + * + * @return void + */ public function setProfileKey(string $profileKey) { $this->setParameter('ProfileKey', $profileKey); diff --git a/Model/PersonalMerchandisingConfig.php b/Model/PersonalMerchandisingConfig.php index e3b3f296..8895c3fb 100644 --- a/Model/PersonalMerchandisingConfig.php +++ b/Model/PersonalMerchandisingConfig.php @@ -2,8 +2,31 @@ namespace Tweakwise\Magento2Tweakwise\Model; +use Magento\Framework\App\Cache\TypeListInterface; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Framework\App\Config\Storage\WriterInterface; +use Magento\Framework\App\RequestInterface; +use Magento\Framework\App\State; +use Magento\Framework\Serialize\Serializer\Json; +use Magento\Framework\Stdlib\CookieManagerInterface; +use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory; + class PersonalMerchandisingConfig extends Config { + public function __construct( + ScopeConfigInterface $config, + Json $jsonSerializer, + RequestInterface $request, + State $state, + WriterInterface $configWriter, + TypeListInterface $cacheTypeList, + private CookieManagerInterface $cookieManager, + private CookieMetadataFactory $cookieMetadataFactory + ) { + parent::__construct($config, $jsonSerializer, $request, $state, + $configWriter, $cacheTypeList); + } + /** * @param Store|null $store * @return bool @@ -12,4 +35,48 @@ public function isAnalyticsEnabled(Store $store = null) { return (bool)$this->getStoreConfig('tweakwise/personal_merchandising/analytics_enabled', $store); } + + public function getProfileKey() + { + $profileKey = $this->cookieManager->getCookie( + $this->getPersonalMerchandisingCookieName(), + null + ); + + if($this->isAnalyticsEnabled()) { + if ($profileKey === null) { + $profileKey = $this->generateProfileKey(); + $this->cookieManager->setPublicCookie( + $this->getPersonalMerchandisingCookieName(), + $profileKey, + $this->getCookieMetadata() + ); + } + } + return $profileKey; + } + + private function getCookieMetadata() + { + return $this->cookieMetadataFactory + ->createPublicCookieMetadata() + ->setDuration(86400) + ->setPath('/') + ->setDomain($this->getCookieDomain()) + ->setSecure($this->getRequest()->isSecure()) + ->setHttpOnly(true); + } + + private function getCookieDomain() + { + return $this->scopeConfig->getValue( + 'web/cookie/cookie_domain', + ScopeInterface::SCOPE_STORE + ); + } + + private function generateProfileKey() + { + return md5(uniqid('', true)); + } } diff --git a/Observer/TweakwiseCheckout.php b/Observer/TweakwiseCheckout.php index a3c6170b..29add3fd 100644 --- a/Observer/TweakwiseCheckout.php +++ b/Observer/TweakwiseCheckout.php @@ -33,31 +33,38 @@ public function __construct( private readonly Client $client, private readonly Helper $helper, private readonly StoreManagerInterface $storeManager, - private readonly PersonalMerchandisingConfig $config, - private readonly CookieManagerInterface $cookieManager + private readonly PersonalMerchandisingConfig $config ) { } + /** + * @param Observer $observer + * + * @return void + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ public function execute(Observer $observer) { if ($this->config->isAnalyticsEnabled('tweakwise/personal_merchandising/analytics_enabled')) { - if ($this->config->isPersonalMerchandisingActive()) { - $order = $observer->getEvent()->getOrder(); - // Get the order items - $items = $order->getAllItems(); + $order = $observer->getEvent()->getOrder(); + // Get the order items + $items = $order->getAllItems(); + + $this->sendCheckout($items); - $this->sendCheckout($items); - } } } + /** + * @param $items + * + * @return void + * @throws \Magento\Framework\Exception\NoSuchEntityException + */ private function sendCheckout($items) { $storeId = (int)$this->storeManager->getStore()->getId(); - $profileKey = $this->cookieManager->getCookie( - $this->config->getPersonalMerchandisingCookieName(), - null - ); + $profileKey = $this->config->getProfileKey(); $tweakwiseRequest = $this->requestFactory->create(); $tweakwiseRequest->setParameter('profileKey', $profileKey); @@ -72,8 +79,7 @@ private function sendCheckout($items) try { $this->client->request($tweakwiseRequest); } catch (\Exception $e) { - // Log error - $this->log->error('Purchase request for tw failed: ' . $e->getMessage()); + // Do nothing } } } diff --git a/etc/di.xml b/etc/di.xml index 8676d01a..5b732537 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -240,6 +240,11 @@ Tweakwise\Magento2Tweakwise\Model\Client\RequestFactory\PurchaseRequest + + + Tweakwise\Magento2Tweakwise\Model\Client\RequestFactory\AnalyticsRequest + + @@ -428,4 +433,9 @@ Tweakwise\Magento2Tweakwise\Model\Client\Request\PurchaseRequest + + + Tweakwise\Magento2Tweakwise\Model\Client\Request\AnalyticsRequest + + diff --git a/view/frontend/web/js/search-page.js b/view/frontend/web/js/search-page.js index 42296953..f4bab44f 100644 --- a/view/frontend/web/js/search-page.js +++ b/view/frontend/web/js/search-page.js @@ -1,42 +1,15 @@ define('Tweakwise_Magento2Tweakwise/js/search-page', ['jquery'], function($) { 'use strict'; - function getCookie(name) { - const value = `; ${document.cookie}`; - const parts = value.split(`; ${name}=`); - if (parts.length === 2) return parts.pop().split(';').shift(); - } - - function setCookie(name, value, days) { - const date = new Date(); - date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000)); - const expires = `expires=${date.toUTCString()}`; - document.cookie = `${name}=${value}; ${expires}; path=/`; - } - return function(config) { $(document).ready(function() { - var apiUrl = config.apiUrl; var searchQuery = config.searchQuery; - var instanceKey = config.instanceKey; - var cookieName = config.tweakwiseCookieName; - - //check cookie for profile key - var profileKey = getCookie(cookieName); - //if cookie not set, generate an random profile key - if (!profileKey) { - profileKey = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15); - setCookie(cookieName, profileKey, { expires: 365, path: '/' }); - } $.ajax({ - url: apiUrl, + url: '/tweakwise/ajax/analytics', method: 'POST', - headers: { - 'Instance-Key': instanceKey - }, data: { - profileKey: profileKey, + type: 'search', searchTerm: searchQuery }, error: function(error) { From 696c2f01a05c522598440c9bc23fd8ef6979babd Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:55:12 +0100 Subject: [PATCH 18/32] Fix cookie --- Model/PersonalMerchandisingConfig.php | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/Model/PersonalMerchandisingConfig.php b/Model/PersonalMerchandisingConfig.php index 8895c3fb..2bf447d6 100644 --- a/Model/PersonalMerchandisingConfig.php +++ b/Model/PersonalMerchandisingConfig.php @@ -62,21 +62,11 @@ private function getCookieMetadata() ->createPublicCookieMetadata() ->setDuration(86400) ->setPath('/') - ->setDomain($this->getCookieDomain()) - ->setSecure($this->getRequest()->isSecure()) - ->setHttpOnly(true); - } - - private function getCookieDomain() - { - return $this->scopeConfig->getValue( - 'web/cookie/cookie_domain', - ScopeInterface::SCOPE_STORE - ); + ->setSecure(true); } private function generateProfileKey() { - return md5(uniqid('', true)); + return uniqid('', true); } } From 11ec0a65d388331020bde811f0eb119d9cc5cedd Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 10 Dec 2024 11:13:43 +0100 Subject: [PATCH 19/32] Fis styling --- Controller/Ajax/Analytics.php | 2 +- Model/Client/Request/AnalyticsRequest.php | 16 ++++++++++++++++ Model/PersonalMerchandisingConfig.php | 15 ++++++++++++--- Observer/TweakwiseCheckout.php | 3 +-- view/frontend/templates/product/page.phtml | 8 +------- view/frontend/templates/search/page.phtml | 10 ++-------- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Controller/Ajax/Analytics.php b/Controller/Ajax/Analytics.php index 06546e00..e2c6f5d2 100644 --- a/Controller/Ajax/Analytics.php +++ b/Controller/Ajax/Analytics.php @@ -39,7 +39,6 @@ public function execute() { $result = $this->resultJsonFactory->create(); if ($this->config->isAnalyticsEnabled()) { - $type = $this->getRequest()->getParam('type'); $profileKey = $this->config->getProfileKey(); @@ -63,6 +62,7 @@ public function execute() $result->setData(['success' => false, 'message' => $e->getMessage()]); } } + return $result; } } diff --git a/Model/Client/Request/AnalyticsRequest.php b/Model/Client/Request/AnalyticsRequest.php index a1dbc0c0..3423ea18 100644 --- a/Model/Client/Request/AnalyticsRequest.php +++ b/Model/Client/Request/AnalyticsRequest.php @@ -21,26 +21,41 @@ class AnalyticsRequest extends Request protected $apiUrl = 'https://navigator-analytics.tweakwise.com/api'; + /** + * @return string + */ public function isPostRequest() { return true; } + /** + * @return string + */ public function getApiurl() { return $this->apiUrl; } + /** + * @return string + */ public function setProfileKey(string $profileKey) { $this->setParameter('ProfileKey', $profileKey); } + /** + * @return string + */ public function setPath($path) { $this->path = $path; } + /** + * @return string + */ public function getProfileKey() { $profileKey = $this->getCookie($this->config->getPersonalMerchandisingCookieName()); @@ -48,6 +63,7 @@ public function getProfileKey() $profileKey = $this->generateProfileKey(); $this->setCookie('profileKey', $profileKey); } + return $profileKey; } } diff --git a/Model/PersonalMerchandisingConfig.php b/Model/PersonalMerchandisingConfig.php index 2bf447d6..2f862c59 100644 --- a/Model/PersonalMerchandisingConfig.php +++ b/Model/PersonalMerchandisingConfig.php @@ -23,8 +23,7 @@ public function __construct( private CookieManagerInterface $cookieManager, private CookieMetadataFactory $cookieMetadataFactory ) { - parent::__construct($config, $jsonSerializer, $request, $state, - $configWriter, $cacheTypeList); + parent::__construct($config, $jsonSerializer, $request, $state, $configWriter, $cacheTypeList); } /** @@ -36,6 +35,9 @@ public function isAnalyticsEnabled(Store $store = null) return (bool)$this->getStoreConfig('tweakwise/personal_merchandising/analytics_enabled', $store); } + /** + * @return string|null + */ public function getProfileKey() { $profileKey = $this->cookieManager->getCookie( @@ -43,7 +45,7 @@ public function getProfileKey() null ); - if($this->isAnalyticsEnabled()) { + if ($this->isAnalyticsEnabled()) { if ($profileKey === null) { $profileKey = $this->generateProfileKey(); $this->cookieManager->setPublicCookie( @@ -53,9 +55,13 @@ public function getProfileKey() ); } } + return $profileKey; } + /** + * @return string + */ private function getCookieMetadata() { return $this->cookieMetadataFactory @@ -65,6 +71,9 @@ private function getCookieMetadata() ->setSecure(true); } + /** + * @return string + */ private function generateProfileKey() { return uniqid('', true); diff --git a/Observer/TweakwiseCheckout.php b/Observer/TweakwiseCheckout.php index 29add3fd..7c1896d1 100644 --- a/Observer/TweakwiseCheckout.php +++ b/Observer/TweakwiseCheckout.php @@ -26,7 +26,6 @@ class TweakwiseCheckout implements ObserverInterface * @param Helper $helper * @param StoreManagerInterface $storeManager * @param PersonalMerchandisingConfig $config - * @param CookieManagerInterface $cookieManager */ public function __construct( private readonly RequestFactory $requestFactory, @@ -51,7 +50,6 @@ public function execute(Observer $observer) $items = $order->getAllItems(); $this->sendCheckout($items); - } } @@ -79,6 +77,7 @@ private function sendCheckout($items) try { $this->client->request($tweakwiseRequest); } catch (\Exception $e) { + // @phpcs:ignore // Do nothing } } diff --git a/view/frontend/templates/product/page.phtml b/view/frontend/templates/product/page.phtml index f72cea5d..087223dd 100644 --- a/view/frontend/templates/product/page.phtml +++ b/view/frontend/templates/product/page.phtml @@ -5,20 +5,14 @@ use Magento\Framework\Escaper; -$tweakwiseCookieName = $block->getCookieName(); -$apiUrl = $block->getApiUrl(); $productKey = $block->getProductKey(); -$instanceKey = $block->getInstanceKey(); ?> - + diff --git a/view/frontend/templates/search/page.phtml b/view/frontend/templates/search/page.phtml index 361286ed..3ea2f5ae 100644 --- a/view/frontend/templates/search/page.phtml +++ b/view/frontend/templates/search/page.phtml @@ -2,18 +2,18 @@ use Magento\Framework\Escaper; -/** @var \Tweakwise\Magento2Tweakwise\Block\Catalog\PersonalMerchandisingAnalytics $block */ - -$searchQuery = $block->getSearchQuery(); +/** @var \Tweakwise\Magento2Tweakwise\ViewModel\PersonalMerchandisingAnalytics $viewModel */ +$viewModel = $block->getData('viewModel'); ?> - + diff --git a/view/frontend/web/js/analytics.js b/view/frontend/web/js/analytics.js new file mode 100644 index 00000000..7d9e295d --- /dev/null +++ b/view/frontend/web/js/analytics.js @@ -0,0 +1,26 @@ +define('Tweakwise_Magento2Tweakwise/js/analytics', ['jquery'], function($) { + 'use strict'; + + return function(config) { + $(document).ready(function() { + var requestData = { + type: config.type + }; + + if (config.type === 'search') { + requestData.searchTerm = config.searchQuery; + } else if (config.type === 'product') { + requestData.productKey = config.productKey; + } + + $.ajax({ + url: '/tweakwise/ajax/analytics', + method: 'POST', + data: requestData, + error: function(error) { + console.error('Tweakwise API call failed:', error); + } + }); + }); + }; +}); diff --git a/view/frontend/web/js/product-page.js b/view/frontend/web/js/product-page.js deleted file mode 100644 index a4a90c7b..00000000 --- a/view/frontend/web/js/product-page.js +++ /dev/null @@ -1,21 +0,0 @@ -define('Tweakwise_Magento2Tweakwise/js/product-page', ['jquery'], function($) { - 'use strict'; - - return function(config) { - $(document).ready(function() { - var productKey = config.productKey; - - $.ajax({ - url: '/tweakwise/ajax/analytics', - method: 'POST', - data: { - type: 'product', - productKey: productKey - }, - error: function(error) { - console.error('Tweakwise API call failed:', error); - } - }); - }); - }; -}); diff --git a/view/frontend/web/js/search-page.js b/view/frontend/web/js/search-page.js deleted file mode 100644 index f4bab44f..00000000 --- a/view/frontend/web/js/search-page.js +++ /dev/null @@ -1,21 +0,0 @@ -define('Tweakwise_Magento2Tweakwise/js/search-page', ['jquery'], function($) { - 'use strict'; - - return function(config) { - $(document).ready(function() { - var searchQuery = config.searchQuery; - - $.ajax({ - url: '/tweakwise/ajax/analytics', - method: 'POST', - data: { - type: 'search', - searchTerm: searchQuery - }, - error: function(error) { - console.error('Tweakwise API call failed:', error); - } - }); - }); - }; -}); From 2aa87e4df4d1b42c7021133a17a180bf4ff39c32 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:33:28 +0100 Subject: [PATCH 26/32] Add phpdoc --- Model/Client/Request.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Model/Client/Request.php b/Model/Client/Request.php index 7b076785..901f06fa 100644 --- a/Model/Client/Request.php +++ b/Model/Client/Request.php @@ -327,12 +327,18 @@ public function setProfileKey(string $profileKey) return $this; } + /** + * @return string|null + */ public function setParameterArray(string $parameter, array $value) { $this->parameters[$parameter] = $value; return $this; } + /** + * @return string|null + */ public function isPostRequest() { return false; From ed7db6e21beff03faa8d90331e26c452c5904a80 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:34:33 +0100 Subject: [PATCH 27/32] Add phpdoc --- Model/Client.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Model/Client.php b/Model/Client.php index 8b38d549..52840cb3 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -118,6 +118,10 @@ protected function createHttpRequest(Request $tweakwiseRequest): HttpRequest } } + /** + * @param Request $tweakwiseRequest + * @return HttpRequest + */ protected function createPostRequest(Request $tweakwiseRequest): HttpRequest { $path = $tweakwiseRequest->getPath(); From 548761aa489e1847d9798d2e6c890ab757b47686 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:35:54 +0100 Subject: [PATCH 28/32] Add phpdoc --- Model/Client.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Model/Client.php b/Model/Client.php index 52840cb3..3db1741b 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -135,6 +135,10 @@ protected function createPostRequest(Request $tweakwiseRequest): HttpRequest return new HttpRequest('POST', $uri, $headers, $body); } + /** + * @param Request $tweakwiseRequest + * @return HttpRequest + */ protected function createGetRequest(Request $tweakwiseRequest): HttpRequest { $path = $tweakwiseRequest->getPath(); From cfc6c00ea6fb58f4524599ce79c9dbb8c676465d Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:39:32 +0100 Subject: [PATCH 29/32] remove personal merchandising code --- etc/frontend/di.xml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/etc/frontend/di.xml b/etc/frontend/di.xml index 34d579f8..9a7da881 100644 --- a/etc/frontend/di.xml +++ b/etc/frontend/di.xml @@ -21,14 +21,6 @@ - - - Magento\Catalog\Model\Layer\Search - - - Date: Tue, 17 Dec 2024 10:38:22 +0100 Subject: [PATCH 30/32] Implement requested changes --- Controller/Ajax/Analytics.php | 12 ++++++----- Model/Client.php | 7 ++++--- .../{search/page.phtml => analytics.phtml} | 6 ++++-- view/frontend/templates/product/page.phtml | 20 ------------------- view/frontend/web/js/analytics.js | 9 ++------- 5 files changed, 17 insertions(+), 37 deletions(-) rename view/frontend/templates/{search/page.phtml => analytics.phtml} (60%) delete mode 100644 view/frontend/templates/product/page.phtml diff --git a/Controller/Ajax/Analytics.php b/Controller/Ajax/Analytics.php index 9956157d..ea699614 100644 --- a/Controller/Ajax/Analytics.php +++ b/Controller/Ajax/Analytics.php @@ -10,6 +10,9 @@ use Magento\Framework\Stdlib\Cookie\PublicCookieMetadata; use Magento\Framework\Stdlib\CookieManagerInterface; use Tweakwise\Magento2Tweakwise\Model\Client\RequestFactory; +use Magento\Framework\App\ResponseInterface; +use Magento\Framework\Controller\Result\Json; +use Magento\Framework\Controller\ResultInterface; class Analytics extends Action { @@ -33,7 +36,7 @@ public function __construct( } /** - * @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\Result\Json|\Magento\Framework\Controller\ResultInterface + * @return ResponseInterface|Json|ResultInterface */ public function execute() { @@ -44,14 +47,13 @@ public function execute() $tweakwiseRequest = $this->requestFactory->create(); $tweakwiseRequest->setProfileKey($profileKey); + $value = $this->getRequest()->getParam('value'); if ($type === 'product') { - $productKey = $this->getRequest()->getParam('productKey'); - $tweakwiseRequest->setParameter('productKey', $productKey); + $tweakwiseRequest->setParameter('productKey', $value); $tweakwiseRequest->setPath('pageview'); } elseif ($type === 'search') { - $searchTerm = $this->getRequest()->getParam('searchTerm'); - $tweakwiseRequest->setParameter('searchTerm', $searchTerm); + $tweakwiseRequest->setParameter('searchTerm', $value); $tweakwiseRequest->setPath('search'); } diff --git a/Model/Client.php b/Model/Client.php index 3db1741b..5a6c2a6f 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -20,12 +20,12 @@ use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Promise\PromiseInterface; use GuzzleHttp\Psr7\Request as HttpRequest; -use GuzzleHttp\Psr7\Uri; use GuzzleHttp\RequestOptions; use Magento\Framework\Profiler; use Psr\Http\Message\ResponseInterface; use SimpleXMLElement; use GuzzleHttp\Client as HttpClient; +use Magento\Framework\UrlInterface; class Client { @@ -77,7 +77,8 @@ public function __construct( Logger $log, ResponseFactory $responseFactory, EndpointManager $endpointManager, - Timer $timer + Timer $timer, + private UrlInterface $urlBuilder ) { $this->config = $config; $this->log = $log; @@ -131,7 +132,7 @@ protected function createPostRequest(Request $tweakwiseRequest): HttpRequest $headers['Instance-Key'] = $this->config->getGeneralAuthenticationKey(); $body = json_encode($tweakwiseRequest->getParameters()); //post request are used for the analytics api - $uri = new Uri($tweakwiseRequest->getApiUrl() . '/' . $path); + $uri = $this->urlBuilder->getUrl($tweakwiseRequest->getApiUrl() . '/' . $path); return new HttpRequest('POST', $uri, $headers, $body); } diff --git a/view/frontend/templates/search/page.phtml b/view/frontend/templates/analytics.phtml similarity index 60% rename from view/frontend/templates/search/page.phtml rename to view/frontend/templates/analytics.phtml index 3ea2f5ae..482bee6c 100644 --- a/view/frontend/templates/search/page.phtml +++ b/view/frontend/templates/analytics.phtml @@ -4,14 +4,16 @@ use Magento\Framework\Escaper; /** @var \Tweakwise\Magento2Tweakwise\ViewModel\PersonalMerchandisingAnalytics $viewModel */ $viewModel = $block->getData('viewModel'); +$analyticsType = $block->getData('analyticsType'); +$value = $analyticsType === 'product' ? $viewModel->getProductKey() : $viewModel->getSearchQuery(); ?> - diff --git a/view/frontend/web/js/analytics.js b/view/frontend/web/js/analytics.js index 7d9e295d..599e5f06 100644 --- a/view/frontend/web/js/analytics.js +++ b/view/frontend/web/js/analytics.js @@ -4,15 +4,10 @@ define('Tweakwise_Magento2Tweakwise/js/analytics', ['jquery'], function($) { return function(config) { $(document).ready(function() { var requestData = { - type: config.type + type: config.type, + value: config.value }; - if (config.type === 'search') { - requestData.searchTerm = config.searchQuery; - } else if (config.type === 'product') { - requestData.productKey = config.productKey; - } - $.ajax({ url: '/tweakwise/ajax/analytics', method: 'POST', From 47118ce45a48909153951d9d53c772647746cf93 Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:40:30 +0100 Subject: [PATCH 31/32] Update xml --- view/frontend/layout/catalog_product_view.xml | 3 ++- view/frontend/layout/catalogsearch_result_index.xml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/view/frontend/layout/catalog_product_view.xml b/view/frontend/layout/catalog_product_view.xml index 38adb62b..4290a020 100644 --- a/view/frontend/layout/catalog_product_view.xml +++ b/view/frontend/layout/catalog_product_view.xml @@ -11,9 +11,10 @@ xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> - + Tweakwise\Magento2Tweakwise\ViewModel\PersonalMerchandisingAnalytics + product diff --git a/view/frontend/layout/catalogsearch_result_index.xml b/view/frontend/layout/catalogsearch_result_index.xml index 0de6ef3b..9008d141 100644 --- a/view/frontend/layout/catalogsearch_result_index.xml +++ b/view/frontend/layout/catalogsearch_result_index.xml @@ -15,9 +15,10 @@ - + Tweakwise\Magento2Tweakwise\ViewModel\PersonalMerchandisingAnalytics + search From b3dd05ba22500d82cc0c31c722e80fe9ab9f826a Mon Sep 17 00:00:00 2001 From: ah-net <103565001+ah-net@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:53:09 +0100 Subject: [PATCH 32/32] Removed space --- Model/Client.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Model/Client.php b/Model/Client.php index 5a6c2a6f..74916bc1 100644 --- a/Model/Client.php +++ b/Model/Client.php @@ -163,7 +163,7 @@ protected function createGetRequest(Request $tweakwiseRequest): HttpRequest if ($tweakwiseRequest->getParameters()) { $query = http_build_query($tweakwiseRequest->getParameters()); - $url = sprintf('%s?%s', $url, $query); + $url = sprintf('%s?%s', $url, $query); } $uri = new Uri($url);