Skip to content

Commit

Permalink
Minor bugfixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
arunas-stonis committed Jan 18, 2023
1 parent a2573c8 commit 8271180
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
46 changes: 30 additions & 16 deletions Block/Trustbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand All @@ -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);
Expand Down
9 changes: 7 additions & 2 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
3 changes: 2 additions & 1 deletion Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
],
Expand Down
3 changes: 2 additions & 1 deletion view/frontend/templates/head/head.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down

2 comments on commit 8271180

@jzembala
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guys, you pushed that version of module to the GitHub before pushing it to repo.magento.com and it breaks the deployment because of Magento checks.

@arunas-stonis
Copy link
Contributor

@arunas-stonis arunas-stonis commented on 8271180 Jan 18, 2023 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.