Skip to content

Commit

Permalink
Merge pull request #65 from trustpilot/bug-fixes-and-require-dependen…
Browse files Browse the repository at this point in the history
…cies

Bug fixes and require dependencies
  • Loading branch information
vdabar authored Dec 31, 2019
2 parents 7706fc2 + b11c075 commit c66241f
Show file tree
Hide file tree
Showing 12 changed files with 97 additions and 20 deletions.
4 changes: 1 addition & 3 deletions Block/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Trustpilot\Reviews\Helper\OrderData;
use Magento\Store\Model\ScopeInterface as StoreScopeInterface;
use Trustpilot\Reviews\Helper\TrustpilotLog;
use \Magento\Store\Model\StoreManagerInterface;
use \Magento\Framework\UrlInterface;

class Success extends Template
Expand All @@ -31,15 +30,14 @@ public function __construct(
OrderData $orderData,
TrustpilotLog $trustpilotLog,
array $data = [],
StoreManagerInterface $storeManager,
TrustpilotPluginStatus $pluginStatus)
{
$this->_salesFactory = $salesOrderFactory;
$this->_checkoutSession = $checkoutSession;
$this->_helper = $helper;
$this->_orderData = $orderData;
$this->_trustpilotLog = $trustpilotLog;
$this->_storeManager = $storeManager;
$this->_storeManager = $context->getStoreManager();
$this->_pluginStatus = $pluginStatus;

parent::__construct($context, $data);
Expand Down
2 changes: 1 addition & 1 deletion Block/System/Config/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getStoreInformation() {
}

public function getPluginStatus($scope, $storeId) {
return base64_encode($this->_helper->getConfig('plugin_status', $scope, $storeId));
return base64_encode($this->_helper->getConfig('plugin_status', $storeId, $scope));
}

public function getPastOrdersInfo($scope, $storeId) {
Expand Down
1 change: 1 addition & 0 deletions Block/Trustbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public function loadTrustboxes()
}
else if ($this->_registry->registry('current_category')) {
$loadedTrustboxes = array_merge((array)$this->loadPageTrustboxes($settings, 'category'), (array)$loadedTrustboxes);
$trustboxSettings->categoryProductsData = $this->_helper->loadCategoryProductInfo($settings);
}
if ($this->_request->getFullActionName() == 'cms_index_index') {
$loadedTrustboxes = array_merge((array)$this->loadPageTrustboxes($settings, 'landing'), (array)$loadedTrustboxes);
Expand Down
2 changes: 1 addition & 1 deletion Block/Trustpilot.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getStoreInformation() {
}

public function getPluginStatus($scope, $storeId) {
return base64_encode($this->_helper->getConfig('plugin_status', $scope, $storeId));
return base64_encode($this->_helper->getConfig('plugin_status', $storeId, $scope));
}

public function getPastOrdersInfo($scope, $storeId) {
Expand Down
4 changes: 4 additions & 0 deletions Controller/Adminhtml/Index/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public function execute()
);
$this->getResponse()->setBody(json_encode($result));
break;
case 'get_category_product_info':
$result = $this->_helper->loadCategoryProductInfo();
$this->getResponse()->setBody(json_encode($result));
break;
}
}

Expand Down
43 changes: 43 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use \Magento\Store\Model\StoreRepository;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use \Magento\Framework\UrlInterface;
use \Magento\Framework\Registry;
use Magento\ConfigurableProduct\Api\LinkManagementInterface;

class Data extends AbstractHelper
{
Expand All @@ -32,6 +34,8 @@ class Data extends AbstractHelper
protected $_storeRepository;
protected $_integrationAppUrl;
protected $_reinitableConfig;
protected $_registry;
protected $_linkManagement;
protected $_trustpilotLog;

public function __construct(
Expand All @@ -45,6 +49,8 @@ public function __construct(
AttributeRepositoryInterface $attributeRepository,
StoreRepository $storeRepository,
ReinitableConfigInterface $reinitableConfig,
Registry $registry,
LinkManagementInterface $linkManagement,
TrustpilotLog $trustpilotLog
) {
$this->_storeManager = $storeManager;
Expand All @@ -59,6 +65,8 @@ public function __construct(
$this->_storeRepository = $storeRepository;
$this->_integrationAppUrl = \Trustpilot\Reviews\Model\Config::TRUSTPILOT_INTEGRATION_APP_URL;
$this->_reinitableConfig = $reinitableConfig;
$this->_registry = $registry;
$this->_linkManagement = $linkManagement;
$this->_trustpilotLog = $trustpilotLog;
}

Expand Down Expand Up @@ -402,4 +410,39 @@ public function getBusinessInformation($scope, $scopeId) {
'phone' => $config->getValue('general/store_information/phone', $scope, $scopeId)
);
}

public function loadCategoryProductInfo($settings) {
$skuSelector = $settings->skuSelector;
$productList = $variationSkus = $variationIds = array();

$params = $this->_request->getParams();
$category = $params['id'];
$limit = array_key_exists('limit', $params) ? $params['limit'] : $this->scopeConfig->getValue('catalog/frontend/grid_per_page');
$page = array_key_exists('limit', $params) ? $params['p'] : 1;

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$layerResolver = $objectManager->getInstance()->get(\Magento\Catalog\Model\Layer\Resolver::class);
$layer = $layerResolver->get();
$layer->setCurrentCategory($category);

$products = $layer->getProductCollection()->setPage($page, $limit);
foreach ($products->getItems() as $product) {
if ($product->getTypeId() == 'configurable') {
$childProducts = $this->_linkManagement->getChildren($product->getSku());
$variationSkus = $skuSelector != 'id' ? $this->loadSelector($product, $skuSelector, $childProducts) : array();
$variationIds = $this->loadSelector($product, 'id', $childProducts);
}
$sku = $skuSelector != 'id' ? $this->loadSelector($product, $skuSelector) : '';
$id = $this->loadSelector($product, 'id');
array_push($productList, array(
"sku" => $sku,
"id" => $id,
"variationIds" => $variationIds,
"variationSkus" => $variationSkus,
"productUrl" => $product->getProductUrl() ?: '',
"name" => $product->getName(),
));
}
return $productList;
}
}
2 changes: 1 addition & 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.524';
const TRUSTPILOT_PLUGIN_VERSION = '2.6.531';
const TRUSTPILOT_SCRIPT = 'TrustpilotScriptUrl';
const TRUSTPILOT_INTEGRATION_APP = 'IntegrationAppUrl';
const TRUSTPILOT_WIDGET_SCRIPT = 'WidgetScriptUrl';
Expand Down
22 changes: 11 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
"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.524",
"version": "2.6.531",
"license": [
"OSL-3.0"
],
"require": {
"magento/framework": "*",
"magento/module-sales": "*",
"magento/module-store": "*",
"magento/module-checkout": "*",
"magento/module-configurable-product": "*",
"magento/module-catalog": "*",
"magento/module-eav": "*",
"magento/module-admin-notification": "*",
"magento/module-backend": "*",
"psr/log": "*"
"magento/framework": ">=100.0.20",
"magento/module-sales": ">=100.0.16",
"magento/module-store": ">=100.0.9",
"magento/module-checkout": ">=100.0.16",
"magento/module-configurable-product": ">=100.0.12",
"magento/module-catalog": ">=100.0.17",
"magento/module-eav": ">=100.0.12",
"magento/module-admin-notification": ">=100.0.7",
"magento/module-backend": ">=100.0.12",
"psr/log": ">=1.0.0"
},
"autoload": {
"files": [ "registration.php" ],
Expand Down
31 changes: 31 additions & 0 deletions view/adminhtml/web/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,43 @@ function receiveInternalData(e) {
const data = e.data;
const parsedData = {};
if (data && typeof data === 'string' && tryParseJson(data, parsedData)) {
if (parsedData && parsedData.type === 'loadCategoryProductInfo') {
requestCategoryInfo();
}
if (parsedData.type === 'updatePageUrls' || parsedData.type === 'newTrustBox') {
this.submitSettings(parsedData);
}
}
}

function requestCategoryInfo() {
const data = {
action: 'get_category_product_info',
form_key: window.FORM_KEY,
};

if (typeof websiteId !== 'undefined') {
data.website_id = websiteId;
}
if (typeof storeId !== 'undefined') {
data.store_id = storeId;
}

const xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
if (xhr.status >= 400) {
console.log(`callback error: ${xhr.response} ${xhr.status}`);
} else {
window.postMessage(JSON.stringify(xhr.response), window.origin);
}
}
}
xhr.open('POST', `${ajaxUrl}?isAjax=true`, true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send(encodeSettings(data));
}

function submitPastOrdersCommand(data) {
data['form_key'] = window.FORM_KEY;
data['scope'] = scope;
Expand Down
2 changes: 1 addition & 1 deletion view/adminhtml/web/js/admin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c66241f

Please sign in to comment.