diff --git a/Block/Trustbox.php b/Block/Trustbox.php index 052bddc..082936f 100644 --- a/Block/Trustbox.php +++ b/Block/Trustbox.php @@ -87,6 +87,32 @@ private function repeatData($trustBoxes) { return false; } + private function loadSkus($current_product, $skuSelector, $includeIds) + { + $skus = array(); + if ($includeIds) { + array_push($skus, \Trustpilot\Reviews\Model\Config::TRUSTPILOT_PRODUCT_ID_PREFIX . $current_product->getId()); + } + $productSku = $this->_helper->loadSelector($current_product, $skuSelector); + if ($productSku) { + array_push($skus, $productSku); + } + + if ($current_product->getTypeId() == 'configurable') { + $collection = $this->_linkManagement->getChildren($current_product->getSku()); + foreach ($collection as $product) { + if ($includeIds) { + array_push($skus, \Trustpilot\Reviews\Model\Config::TRUSTPILOT_PRODUCT_ID_PREFIX . $product->getId()); + } + $productSku = $this->_helper->loadSelector($product, $skuSelector); + if ($productSku) { + array_push($skus, $productSku); + } + } + } + return implode(',', $skus); + } + private function loadPageTrustboxes($settings, $page) { $data = []; @@ -95,23 +121,11 @@ private function loadPageTrustboxes($settings, $page) if ((rtrim($trustbox->page, '/') == rtrim($page, '/') || $this->checkCustomPage($trustbox->page, $page)) && $trustbox->enabled == 'enabled') { $current_product = $this->_registry->registry('current_product'); if ($current_product) { - $skus = array(); - $productSku = $this->_helper->loadSelector($current_product, $skuSelector); - if ($productSku) { - array_push($skus, $productSku); - } - array_push($skus, \Trustpilot\Reviews\Model\Config::TRUSTPILOT_PRODUCT_ID_PREFIX . $current_product->getId()); - if ($current_product->getTypeId() == 'configurable') { - $collection = $this->_linkManagement->getChildren($current_product->getSku()); - foreach ($collection as $product) { - $productSku = $this->_helper->loadSelector($product, $skuSelector); - if ($productSku) { - array_push($skus, $productSku); - } - array_push($skus, \Trustpilot\Reviews\Model\Config::TRUSTPILOT_PRODUCT_ID_PREFIX . $product->getId()); - } + $sku = $this->loadSkus($current_product, $skuSelector, true); + if (strlen($sku) > \Trustpilot\Reviews\Model\Config::MAX_SKU_LENGTH) { + $sku = $this->loadSkus($current_product, $skuSelector, false); } - $trustbox->sku = implode(',', $skus); + $trustbox->sku = $sku; $trustbox->name = $current_product->getName(); } array_push($data, $trustbox); diff --git a/Helper/Data.php b/Helper/Data.php index 4be289e..6632a57 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -258,8 +258,13 @@ public function getPageUrl($page, $scope, $storeId) return $this->_storeManager->getStore($storeId)->getBaseUrl().'?___store='.$storeCode; case 'trustpilot_trustbox_category': $category = $this->getFirstCategory($storeId); - $productUrl = strtok($category->getUrl(),'?').'?___store='.$storeCode; - return $productUrl; + $categoryUrl = $this->_url->getUrl('catalog/category/view', [ + '_scope' => $storeId, + 'id' => $category->getId(), + '_nosid' => true, + '_query' => ['___store' => $storeCode] + ]); + return $categoryUrl; case 'trustpilot_trustbox_product': $product = $this->getFirstProduct('store', $storeId); $productUrl = $this->_url->getUrl('catalog/product/view', [ diff --git a/Model/Config.php b/Model/Config.php index 1849928..0de13ca 100755 --- a/Model/Config.php +++ b/Model/Config.php @@ -16,7 +16,7 @@ class Config const TRUSTPILOT_GENERAL_CONFIGURATION = 'general'; const TRUSTPILOT_TRUSTBOX_CONFIGURATION = 'trustbox'; const TRUSTPILOT_INTEGRATION_KEY = 'key'; - const TRUSTPILOT_PLUGIN_VERSION = '2.6.574'; + const TRUSTPILOT_PLUGIN_VERSION = '2.6.580'; const TRUSTPILOT_SCRIPT = 'TrustpilotScriptUrl'; const TRUSTPILOT_INTEGRATION_APP = 'IntegrationAppUrl'; const TRUSTPILOT_WIDGET_SCRIPT = 'WidgetScriptUrl'; @@ -32,4 +32,5 @@ class Config const TRUSTPILOT_TRUSTBOX_PREVIEW_URL = '//ecommplugins-trustboxpreview.trustpilot.com/v1.0/trustboxpreview.min.js'; const TRUSTPILOT_IS_FROM_MARKETPLACE = 'false'; const TRUSTPILOT_PRODUCT_ID_PREFIX = 'TRUSTPILOT_SKU_VALUE_'; + const MAX_SKU_LENGTH = 6000; } diff --git a/composer.json b/composer.json index 7845229..53fccc0 100755 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "trustpilot/module-reviews", "description": "The Trustpilot Review extension makes it simple and easy for merchants to collect reviews from their customers to power their marketing efforts, increase sales conversion, build their online reputation and draw business insights.", "type": "magento2-module", - "version": "2.6.574", + "version": "2.6.580", "license": [ "OSL-3.0" ], diff --git a/view/frontend/templates/head/head.phtml b/view/frontend/templates/head/head.phtml index 192779e..67a276c 100755 --- a/view/frontend/templates/head/head.phtml +++ b/view/frontend/templates/head/head.phtml @@ -35,7 +35,8 @@ if (inIframe()) { window.addEventListener('message', function(e) { var adminOrign = new URL(window.location).hostname; - if (!e.data || e.origin.indexOf(adminOrign) === -1) { + var eventOriginHostname = new URL(e.origin).hostname; + if (!e.data || adminOrign !== eventOriginHostname) { return; } if (typeof TrustpilotPreview !== 'undefined') {