first commit

This commit is contained in:
2024-10-28 22:14:22 +01:00
commit b65352c452
40581 changed files with 5712079 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
drwxr-xr-x 2 30094 users 14 Oct 6 10:16 .
drwxr-xr-x 8 30094 users 10 Oct 6 10:16 ..
-rw-r--r-- 1 30094 users 2053 Apr 5 2022 HookActionCarrierProcess.php
-rw-r--r-- 1 30094 users 5333 Apr 5 2022 HookActionCartSave.php
-rw-r--r-- 1 30094 users 2977 Apr 5 2022 HookActionOrderStatusPostUpdate.php
-rw-r--r-- 1 30094 users 2223 Apr 5 2022 HookActionProductCancel.php
-rw-r--r-- 1 30094 users 4575 Apr 5 2022 HookDisplayBackOfficeHeader.php
-rw-r--r-- 1 30094 users 4276 Apr 5 2022 HookDisplayFooter.php
-rw-r--r-- 1 30094 users 2577 Apr 5 2022 HookDisplayFooterProduct.php
-rw-r--r-- 1 30094 users 3502 Apr 5 2022 HookDisplayHeader.php
-rw-r--r-- 1 30094 users 2735 Apr 5 2022 HookDisplayHome.php
-rw-r--r-- 1 30094 users 4141 Apr 5 2022 HookDisplayOrderConfirmation.php
-rw-r--r-- 1 30094 users 1105 Apr 5 2022 HookInterface.php
-rw-r--r-- 1 30094 users 1083 Apr 5 2022 index.php

View File

@@ -0,0 +1,68 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Context;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsDataHandler;
use PrestaShop\Module\Ps_Googleanalytics\Repository\CarrierRepository;
use Ps_Googleanalytics;
class HookActionCarrierProcess implements HookInterface
{
private $module;
private $context;
private $params;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return void
*/
public function run()
{
if (isset($this->params['cart']->id_carrier)) {
$carrierRepository = new CarrierRepository();
$ganalyticsDataHandler = new GanalyticsDataHandler(
$this->context->cart->id,
$this->context->shop->id
);
$carrierName = $carrierRepository->findByCarrierId((int) $this->params['cart']->id_carrier);
$ganalyticsDataHandler->manageData('MBG.addCheckoutOption(2,\'' . $carrierName . '\');', 'A');
}
}
/**
* setParams
*
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
}

View File

@@ -0,0 +1,136 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Configuration;
use Context;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsDataHandler;
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
use Product;
use Ps_Googleanalytics;
use Tools;
use Validate;
class HookActionCartSave implements HookInterface
{
private $module;
/**
* @var Context
*/
private $context;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return void
*/
public function run()
{
if (!isset($this->context->cart)) {
return;
}
if (!Tools::getIsset('id_product')) {
return;
}
$cart = [
'controller' => Tools::getValue('controller'),
'addAction' => Tools::getValue('add') ? 'add' : '',
'removeAction' => Tools::getValue('delete') ? 'delete' : '',
'extraAction' => Tools::getValue('op'),
'qty' => (int) Tools::getValue('qty', 1),
];
$cartProducts = $this->context->cart->getProducts();
if (!empty($cartProducts)) {
foreach ($cartProducts as $cartProduct) {
if ($cartProduct['id_product'] == Tools::getValue('id_product')) {
$addProduct = $cartProduct;
break;
}
}
}
if ($cart['removeAction'] == 'delete') {
$addProductObject = new Product((int) Tools::getValue('id_product'), true, (int) Configuration::get('PS_LANG_DEFAULT'));
if (Validate::isLoadedObject($addProductObject)) {
$addProduct['name'] = $addProductObject->name;
$addProduct['manufacturer_name'] = $addProductObject->manufacturer_name;
$addProduct['category'] = $addProductObject->category;
$addProduct['reference'] = $addProductObject->reference;
$addProduct['link_rewrite'] = $addProductObject->link_rewrite;
$addProduct['link'] = $addProductObject->link_rewrite;
$addProduct['price'] = $addProductObject->price;
$addProduct['ean13'] = $addProductObject->ean13;
$addProduct['id_product'] = Tools::getValue('id_product');
$addProduct['id_category_default'] = $addProductObject->id_category_default;
$addProduct['out_of_stock'] = $addProductObject->out_of_stock;
$addProduct['minimal_quantity'] = 1;
$addProduct['unit_price_ratio'] = 0;
$addProduct = Product::getProductProperties((int) Configuration::get('PS_LANG_DEFAULT'), $addProduct);
}
}
if (isset($addProduct) && !in_array((int) Tools::getValue('id_product'), $this->module->products)) {
$ganalyticsDataHandler = new GanalyticsDataHandler(
$this->context->cart->id,
$this->context->shop->id
);
$this->module->products[] = (int) Tools::getValue('id_product');
$productWrapper = new ProductWrapper($this->context);
$gaProducts = $productWrapper->wrapProduct($addProduct, $cart, 0, true);
if (array_key_exists('id_product_attribute', $gaProducts) && $gaProducts['id_product_attribute'] != '' && $gaProducts['id_product_attribute'] != 0) {
$productId = $gaProducts['id_product_attribute'];
} else {
$productId = Tools::getValue('id_product');
}
$gaCart = $ganalyticsDataHandler->manageData('', 'R');
if ($cart['removeAction'] == 'delete') {
$gaProducts['quantity'] = -1;
} elseif ($cart['extraAction'] == 'down') {
if (array_key_exists($productId, $gaCart)) {
$gaProducts['quantity'] = $gaCart[$productId]['quantity'] - $cart['qty'];
} else {
$gaProducts['quantity'] = $cart['qty'] * -1;
}
} elseif (Tools::getValue('step') <= 0) { // Sometimes cartsave is called in checkout
if (array_key_exists($productId, $gaCart)) {
$gaProducts['quantity'] = $gaCart[$productId]['quantity'] + $cart['qty'];
}
}
$gaCart[$productId] = $gaProducts;
$ganalyticsDataHandler->manageData($gaCart, 'W');
}
}
}

View File

@@ -0,0 +1,96 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Configuration;
use Context;
use Db;
use Ps_Googleanalytics;
class HookActionOrderStatusPostUpdate implements HookInterface
{
/**
* @var Ps_Googleanalytics
*/
private $module;
/**
* @var Context
*/
private $context;
/**
* @var array
*/
private $params;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return void
*/
public function run()
{
// If we do not have an order or a new order status, we return
if (empty($this->params['id_order']) || empty($this->params['newOrderStatus']->id)) {
return;
}
// We get all states in which the merchant want to have refund sent and check if the new state being set belongs there
$gaCancelledStates = json_decode(Configuration::get('GA_CANCELLED_STATES'), true);
if (empty($gaCancelledStates) || !in_array($this->params['newOrderStatus']->id, $gaCancelledStates)) {
return;
}
// We check if the refund was already sent to Google Analytics
$gaRefundSent = Db::getInstance()->getValue(
'SELECT id_order FROM `' . _DB_PREFIX_ . 'ganalytics` WHERE id_order = ' . (int) $this->params['id_order'] . ' AND refund_sent = 1'
);
// If it was not already refunded
if ($gaRefundSent === false) {
// We refund it and set the "sent" flag to true
$this->context->cookie->__set('ga_admin_refund', 'MBG.refundByOrderId(' . json_encode(['id' => $this->params['id_order']]) . ');');
$this->context->cookie->write();
// We save this information to database
Db::getInstance()->execute(
'UPDATE `' . _DB_PREFIX_ . 'ganalytics` SET refund_sent = 1 WHERE id_order = ' . (int) $this->params['id_order']
);
}
}
/**
* setParams
*
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
}

View File

@@ -0,0 +1,75 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Context;
use OrderDetail;
use Ps_Googleanalytics;
class HookActionProductCancel implements HookInterface
{
private $module;
private $context;
private $params;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return void
*/
public function run()
{
if (!isset($this->params['id_order_detail']) || !isset($this->params['cancel_quantity'])) {
return;
}
// Display GA refund product
$orderDetail = new OrderDetail($this->params['id_order_detail']);
$gaScripts = 'MBG.add(' . json_encode(
[
'id' => empty($orderDetail->product_attribute_id) ? $orderDetail->product_id : $orderDetail->product_id . '-' . $orderDetail->product_attribute_id,
'quantity' => $this->params['cancel_quantity'],
])
. ');';
$this->context->cookie->__set(
'ga_admin_refund',
$gaScripts . 'MBG.refundByProduct(' . json_encode(['id' => $this->params['order']->id]) . ');'
);
$this->context->cookie->write();
}
/**
* setParams
*
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
}

View File

@@ -0,0 +1,111 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Configuration;
use Context;
use Order;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
use PrestaShop\Module\Ps_Googleanalytics\Repository\GanalyticsRepository;
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\OrderWrapper;
use Ps_Googleanalytics;
use Tools;
use Validate;
class HookDisplayBackOfficeHeader implements HookInterface
{
private $module;
private $context;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return string
*/
public function run()
{
$js = '';
if (strcmp(Tools::getValue('configure'), $this->module->name) === 0) {
$this->context->controller->addCSS($this->module->getPathUri() . 'views/css/ganalytics.css');
}
$ga_account_id = Configuration::get('GA_ACCOUNT_ID');
if (!empty($ga_account_id) && $this->module->active) {
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
$this->context->controller->addJs($this->module->getPathUri() . 'views/js/GoogleAnalyticActionLib.js');
$this->context->smarty->assign('GA_ACCOUNT_ID', $ga_account_id);
$gaScripts = '';
if ($this->context->controller->controller_name == 'AdminOrders') {
$ganalyticsRepository = new GanalyticsRepository();
if (Tools::getValue('id_order')) {
$order = new Order((int) Tools::getValue('id_order'));
if (Validate::isLoadedObject($order) && strtotime('+1 day', strtotime($order->date_add)) > time()) {
$gaOrderSent = $ganalyticsRepository->findGaOrderByOrderId((int) Tools::getValue('id_order'));
if ($gaOrderSent === false) {
$ganalyticsRepository->addNewRow(
[
'id_order' => (int) Tools::getValue('id_order'),
'id_shop' => (int) $this->context->shop->id,
'sent' => 0,
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
]
);
}
}
} else {
$gaOrderRecords = $ganalyticsRepository->findAllByShopIdAndDateAdd((int) $this->context->shop->id);
if ($gaOrderRecords) {
$orderWrapper = new OrderWrapper($this->context);
foreach ($gaOrderRecords as $row) {
$transaction = $orderWrapper->wrapOrder($row['id_order']);
if (!empty($transaction)) {
$ganalyticsRepository->updateData(
[
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
'sent' => 1,
],
'id_order = ' . (int) $row['id_order'] . ' AND id_shop = ' . (int) $this->context->shop->id
);
$transaction = json_encode($transaction);
$gaScripts .= 'MBG.addTransaction(' . $transaction . ');';
}
}
}
}
}
return $js . $this->module->hookdisplayHeader(null, true) . $gaTagHandler->generate($gaScripts, true);
}
return $js;
}
}

View File

@@ -0,0 +1,117 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Context;
use Hook;
use PrestaShop\Module\Ps_Googleanalytics\GoogleAnalyticsTools;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsDataHandler;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
use Ps_Googleanalytics;
use RecursiveArrayIterator;
use RecursiveIteratorIterator;
use Tools;
class HookDisplayFooter implements HookInterface
{
private $module;
private $context;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return string
*/
public function run()
{
$gaTools = new GoogleAnalyticsTools();
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
$ganalyticsDataHandler = new GanalyticsDataHandler(
$this->context->cart->id,
$this->context->shop->id
);
$gaScripts = '';
$this->module->js_state = 0;
$gacarts = $ganalyticsDataHandler->manageData('', 'R');
$controller_name = Tools::getValue('controller');
if (count($gacarts) > 0 && $controller_name != 'product') {
$this->module->filterable = 0;
foreach ($gacarts as $gacart) {
if (isset($gacart['quantity'])) {
if ($gacart['quantity'] > 0) {
$gaScripts .= 'MBG.addToCart(' . json_encode($gacart) . ');';
} elseif ($gacart['quantity'] < 0) {
$gacart['quantity'] = abs($gacart['quantity']);
$gaScripts .= 'MBG.removeFromCart(' . json_encode($gacart) . ');';
}
} elseif (is_array($gacart)) {
$it = new RecursiveIteratorIterator(new RecursiveArrayIterator($gacart));
foreach ($it as $v) {
$gaScripts .= $v;
}
} else {
$gaScripts .= $gacart;
}
}
$ganalyticsDataHandler->manageData('', 'D');
}
$listing = $this->context->smarty->getTemplateVars('listing');
$productWrapper = new ProductWrapper($this->context);
$products = $productWrapper->wrapProductList(isset($listing['products']) ? $listing['products'] : [], [], true);
if ($controller_name == 'order' || $controller_name == 'orderopc') {
$this->module->js_state = 1;
$this->module->eligible = 1;
$step = Tools::getValue('step');
if (empty($step)) {
$step = 0;
}
$gaScripts .= $gaTools->addProductFromCheckout($products);
$gaScripts .= 'MBG.addCheckout(\'' . (int) $step . '\');';
}
$confirmation_hook_id = (int) Hook::getIdByName('displayOrderConfirmation');
if (isset(Hook::$executed_hooks[$confirmation_hook_id])) {
$this->module->eligible = 1;
}
if (isset($products) && count($products) && $controller_name != 'index') {
if ($this->module->eligible == 0) {
$gaScripts .= $gaTools->addProductImpression($products);
}
$gaScripts .= $gaTools->addProductClick($products);
}
return $gaTagHandler->generate($gaScripts);
}
}

View File

@@ -0,0 +1,84 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Context;
use PrestaShop\Module\Ps_Googleanalytics\GoogleAnalyticsTools;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
use Product;
use Ps_Googleanalytics;
use Tools;
class HookDisplayFooterProduct implements HookInterface
{
private $module;
private $context;
private $params;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return string
*/
public function run()
{
$gaTools = new GoogleAnalyticsTools();
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
$controllerName = Tools::getValue('controller');
if ('product' !== $controllerName) {
return '';
}
if ($this->params['product'] instanceof Product) {
$this->params['product'] = (array) $this->params['product'];
}
// Add product view
$productWrapper = new ProductWrapper($this->context);
$gaProduct = $productWrapper->wrapProduct($this->params['product'], null, 0, true);
$js = 'MBG.addProductDetailView(' . json_encode($gaProduct) . ');';
if (isset($_SERVER['HTTP_REFERER']) && strpos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) > 0) {
$js .= $gaTools->addProductClickByHttpReferal([$gaProduct]);
}
$this->module->js_state = 1;
return $gaTagHandler->generate($js);
}
/**
* setParams
*
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
}

View File

@@ -0,0 +1,122 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Configuration;
use Context;
use Ps_Googleanalytics;
use Shop;
use Tools;
class HookDisplayHeader implements HookInterface
{
private $module;
private $context;
private $params;
/**
* @var bool
*/
private $backOffice;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return void|string
*/
public function run()
{
if (!Configuration::get('GA_ACCOUNT_ID')) {
return '';
}
$this->context->controller->addJs($this->module->getPathUri() . 'views/js/GoogleAnalyticActionLib.js');
$shops = Shop::getShops();
$isMultistoreActive = Shop::isFeatureActive();
$currentShopId = (int) Context::getContext()->shop->id;
$userId = null;
$gaCrossdomainEnabled = false;
if (Configuration::get('GA_USERID_ENABLED') &&
$this->context->customer && $this->context->customer->isLogged()
) {
$userId = (int) $this->context->customer->id;
}
$gaAnonymizeEnabled = Configuration::get('GA_ANONYMIZE_ENABLED');
if ((int) Configuration::get('GA_CROSSDOMAIN_ENABLED') && $isMultistoreActive && count($shops) > 1) {
$gaCrossdomainEnabled = true;
}
$this->context->smarty->assign(
[
'backOffice' => $this->backOffice,
'trackBackOffice' => Configuration::get('GA_TRACK_BACKOFFICE_ENABLED'),
'currentShopId' => $currentShopId,
'userId' => $userId,
'gaAccountId' => Tools::safeOutput(Configuration::get('GA_ACCOUNT_ID')),
'shops' => $shops,
'gaCrossdomainEnabled' => $gaCrossdomainEnabled,
'gaAnonymizeEnabled' => $gaAnonymizeEnabled,
'useSecureMode' => Configuration::get('PS_SSL_ENABLED'),
]
);
return $this->module->display(
$this->module->getLocalPath() . $this->module->name,
'ps_googleanalytics.tpl'
);
}
/**
* setParams
*
* @param array $params
*/
public function setParams($params)
{
$this->module->params = $params;
}
/**
* @param bool $backOffice
*/
public function setBackOffice($backOffice)
{
$this->acknowledgeBackOfficeContext($backOffice);
}
/**
* @param bool $isBackOffice
*/
public function acknowledgeBackOfficeContext($isBackOffice)
{
$this->backOffice = $isBackOffice;
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Category;
use Configuration;
use Context;
use PrestaShop\Module\Ps_Googleanalytics\GoogleAnalyticsTools;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
use PrestaShop\Module\Ps_Googleanalytics\Handler\ModuleHandler;
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
use Ps_Googleanalytics;
class HookDisplayHome implements HookInterface
{
private $module;
private $context;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return string
*/
public function run()
{
$moduleHandler = new ModuleHandler();
$gaTools = new GoogleAnalyticsTools();
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
$gaScripts = '';
// Home featured products
if ($moduleHandler->isModuleEnabledAndHookedOn('ps_featuredproducts', 'displayHome')) {
$category = new Category($this->context->shop->getCategory(), $this->context->language->id);
$productWrapper = new ProductWrapper($this->context);
$homeFeaturedProducts = $productWrapper->wrapProductList(
$category->getProducts(
(int) $this->context->language->id,
1,
(Configuration::get('HOME_FEATURED_NBR') ? (int) Configuration::get('HOME_FEATURED_NBR') : 8),
'position'
),
[],
true
);
$gaScripts .= $gaTools->addProductImpression($homeFeaturedProducts) . $gaTools->addProductClick($homeFeaturedProducts);
}
$this->module->js_state = 1;
return $gaTagHandler->generate(
$gaTools->filter($gaScripts, $this->module->filterable)
);
}
}

View File

@@ -0,0 +1,114 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Cart;
use Configuration;
use Context;
use PrestaShop\Module\Ps_Googleanalytics\GoogleAnalyticsTools;
use PrestaShop\Module\Ps_Googleanalytics\Handler\GanalyticsJsHandler;
use PrestaShop\Module\Ps_Googleanalytics\Repository\GanalyticsRepository;
use PrestaShop\Module\Ps_Googleanalytics\Wrapper\ProductWrapper;
use Ps_Googleanalytics;
use Shop;
use Validate;
class HookDisplayOrderConfirmation implements HookInterface
{
private $module;
private $context;
private $params;
public function __construct(Ps_Googleanalytics $module, Context $context)
{
$this->module = $module;
$this->context = $context;
}
/**
* run
*
* @return string
*/
public function run()
{
if (true === $this->module->psVersionIs17) {
$order = $this->params['order'];
} else {
$order = $this->params['objOrder'];
}
if (Validate::isLoadedObject($order) && $order->getCurrentState() != (int) Configuration::get('PS_OS_ERROR')) {
$ganalyticsRepository = new GanalyticsRepository();
$gaOrderSent = $ganalyticsRepository->findGaOrderByOrderId((int) $order->id);
if (false === $gaOrderSent) {
$ganalyticsRepository->addNewRow(
[
'id_order' => (int) $order->id,
'id_shop' => (int) $this->context->shop->id,
'sent' => 0,
'date_add' => ['value' => 'NOW()', 'type' => 'sql'],
]
);
if ($order->id_customer == $this->context->cookie->id_customer) {
$orderProducts = [];
$cart = new Cart($order->id_cart);
$gaTools = new GoogleAnalyticsTools();
$gaTagHandler = new GanalyticsJsHandler($this->module, $this->context);
$productWrapper = new ProductWrapper($this->context);
foreach ($cart->getProducts() as $order_product) {
$orderProducts[] = $productWrapper->wrapProduct($order_product, [], 0, true);
}
$gaScripts = 'MBG.addCheckoutOption(3,\'' . $order->payment . '\');';
$transaction = [
'id' => $order->id,
'affiliation' => (Shop::isFeatureActive()) ? $this->context->shop->name : Configuration::get('PS_SHOP_NAME'),
'revenue' => $order->total_paid,
'shipping' => $order->total_shipping,
'tax' => $order->total_paid_tax_incl - $order->total_paid_tax_excl,
'url' => $this->context->link->getModuleLink('ps_googleanalytics', 'ajax', [], true),
'customer' => $order->id_customer, ];
$gaScripts .= $gaTools->addTransaction($orderProducts, $transaction);
$this->module->js_state = 1;
return $gaTagHandler->generate($gaScripts);
}
}
}
return '';
}
/**
* setParams
*
* @param array $params
*/
public function setParams($params)
{
$this->params = $params;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
namespace PrestaShop\Module\Ps_Googleanalytics\Hooks;
use Context;
use Ps_Googleanalytics;
interface HookInterface
{
/**
* @param Ps_Googleanalytics $module
* @param Context $context
*/
public function __construct(Ps_Googleanalytics $module, Context $context);
public function run();
}

View File

@@ -0,0 +1,28 @@
<?php
/**
* 2007-2020 PrestaShop and Contributors
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License 3.0 (AFL-3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2020 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License 3.0 (AFL-3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
header('Expires: Mon, 26 Jul 1998 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate');
header('Cache-Control: post-check=0, pre-check=0', false);
header('Pragma: no-cache');
header('Location: ../');
exit;