Download project

This commit is contained in:
Roman Pyrih
2024-11-20 09:09:44 +01:00
parent 547a138d6a
commit 5ff041757f
40737 changed files with 7766183 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* 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 and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsxMarketingWithGoogle\Provider;
use Carrier;
use Currency;
use Language;
use PrestaShop\Module\PsxMarketingWithGoogle\Adapter\ConfigurationAdapter;
use PrestaShop\Module\PsxMarketingWithGoogle\Builder\CarrierBuilder;
use PrestaShop\Module\PsxMarketingWithGoogle\DTO\Carrier as DTOCarrier;
use RangePrice;
use RangeWeight;
class CarrierDataProvider
{
/**
* @var ConfigurationAdapter
*/
private $configurationAdapter;
/**
* @var CarrierBuilder
*/
private $carrierBuilder;
public function __construct(
ConfigurationAdapter $configurationAdapter,
CarrierBuilder $carrierBuilder
) {
$this->configurationAdapter = $configurationAdapter;
$this->carrierBuilder = $carrierBuilder;
}
public function getFormattedData(): array
{
$language = new Language($this->configurationAdapter->get('PS_LANG_DEFAULT'));
$currency = new Currency($this->configurationAdapter->get('PS_CURRENCY_DEFAULT'));
$carriers = Carrier::getCarriers($language->id, false, false, false, null, Carrier::ALL_CARRIERS);
/** @var DTOCarrier[] $carrierLines */
$carrierLines = $this->carrierBuilder->buildCarriers(
$carriers,
$language,
$currency,
$this->configurationAdapter->get('PS_WEIGHT_UNIT')
);
return $carrierLines;
}
/**
* @param array $deliveryPriceByRange
*
* @return false|RangeWeight|RangePrice
*
* @throws \PrestaShopDatabaseException
* @throws \PrestaShopException
*/
public function getCarrierRange(array $deliveryPriceByRange)
{
if (isset($deliveryPriceByRange['id_range_weight'])) {
return new RangeWeight($deliveryPriceByRange['id_range_weight']);
}
if (isset($deliveryPriceByRange['id_range_price'])) {
return new RangePrice($deliveryPriceByRange['id_range_price']);
}
return false;
}
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* 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 and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsxMarketingWithGoogle\Provider;
use Context;
use PrestaShop\Module\PsxMarketingWithGoogle\DTO\ConversionEventData;
class CartEventDataProvider
{
/**
* @var Context
*/
protected $context;
public function __construct(Context $context)
{
$this->context = $context;
}
/**
* Return the items concerned by the transaction
* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#action-data
*/
public function getEventData($sendTo, $data): ConversionEventData
{
$product = $data['product'];
$idProductAttribute = isset($data['id_product_attribute']) ? $data['id_product_attribute'] : 0;
return (new ConversionEventData())
->setSendTo($sendTo)
->setCurrency($this->context->currency->iso_code)
->setValue((string) \Product::getPriceStatic($product->id, true, $idProductAttribute, 2));
}
}

View File

@@ -0,0 +1,59 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* 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 and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsxMarketingWithGoogle\Provider;
use Context;
use PrestaShop\Module\PsxMarketingWithGoogle\DTO\ConversionEventData;
class PageViewEventDataProvider
{
/**
* @var Context
*/
protected $context;
public function __construct(Context $context)
{
$this->context = $context;
}
/**
* Return the items concerned by the transaction
* https://developers.google.com/analytics/devguides/collection/gtagjs/enhanced-ecommerce#action-data
*
* @return ConversionEventData|null
*/
public function getEventData($sendTo)
{
if ($this->context->controller instanceof \ProductControllerCore) {
/** @var \ProductControllerCore $controller */
$controller = $this->context->controller;
$product = $controller->getTemplateVarProduct();
return (new ConversionEventData())
->setSendTo($sendTo)
->setCurrency($this->context->currency->iso_code)
->setValue((string) $product['price_amount']);
}
return null;
}
}

View File

@@ -0,0 +1,73 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* 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 and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsxMarketingWithGoogle\Provider;
use Context;
use PrestaShop\Module\PsxMarketingWithGoogle\DTO\Remarketing\ProductData;
class ProductDataProvider
{
/**
* @var Context
*/
protected $context;
public function __construct(Context $context)
{
$this->context = $context;
}
public function getProductDataByProductArray(array $product): ProductData
{
$productData = new ProductData();
$productData->setId(implode(
'-',
[
(int) $product['id_product'],
(int) $product['id_product_attribute'],
]
));
$productData->setPrice((float) $product['product_price_wt']);
$productData->setQuantity((int) $product['product_quantity']);
return $productData;
}
public function getProductDataByProductObject(array $params): ProductData
{
$product = $params['product'];
$productData = new ProductData();
$productData->setId(implode(
'-',
[
(int) $product->id,
(int) $params['id_product_attribute'],
]
));
$productData->setPrice($product->price);
$productData->setQuantity($params['quantity']);
return $productData;
}
}

View File

@@ -0,0 +1,109 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* 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 and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsxMarketingWithGoogle\Provider;
use Context;
use Order;
use PrestaShop\Module\PsxMarketingWithGoogle\Adapter\ConfigurationAdapter;
use PrestaShop\Module\PsxMarketingWithGoogle\Config\Config;
use PrestaShop\Module\PsxMarketingWithGoogle\DTO\Remarketing\PurchaseEventData;
use PrestaShop\Module\PsxMarketingWithGoogle\Repository\CountryRepository;
use PrestaShop\Module\PsxMarketingWithGoogle\Repository\LanguageRepository;
class PurchaseEventDataProvider
{
/**
* @var ProductDataProvider
*/
protected $productDataProvider;
/**
* @var Context
*/
protected $context;
/**
* @var ConfigurationAdapter
*/
private $configurationAdapter;
/**
* @var LanguageRepository
*/
private $languageRepository;
/**
* @var CountryRepository
*/
private $countryRepository;
public function __construct(
ProductDataProvider $productDataProvider,
Context $context,
ConfigurationAdapter $configurationAdapter,
LanguageRepository $languageRepository,
CountryRepository $countryRepository
) {
$this->productDataProvider = $productDataProvider;
$this->context = $context;
$this->configurationAdapter = $configurationAdapter;
$this->languageRepository = $languageRepository;
$this->countryRepository = $countryRepository;
}
/**
* Return the items concerned by the transaction
*
* @see https://support.google.com/google-ads/answer/9028614
*/
public function getEventData($sendTo, Order $order): PurchaseEventData
{
$purchaseData = new PurchaseEventData();
// Common details
$purchaseData->setSendTo($sendTo);
$purchaseData->setCurrency($this->context->currency->iso_code);
$purchaseData->setValue((string) $order->total_products_wt);
$purchaseData->setTransactionId($order->id_cart);
// CwCD Parameters
$purchaseData->setDiscount((float) $order->total_discounts_tax_incl);
$purchaseData->setAwMerchandId((int) $this->configurationAdapter->get(Config::REMARKETING_CONVERSION_MERCHANT_GMC_ID));
$purchaseData->setAwFeedCountry(
$this->countryRepository->getIsoById(
$this->context->country->id
)
);
$purchaseData->setAwFeedLanguage(
$this->languageRepository->getIsoById(
$this->context->language->id
)
);
$items = [];
foreach ($order->getCartProducts() as $product) {
$items[] = $this->productDataProvider->getProductDataByProductArray($product);
}
$purchaseData->setItems($items);
return $purchaseData;
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* 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 and Contributors <contact@prestashop.com>
* @copyright Since 2007 PrestaShop SA and Contributors
* @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0
*/
namespace PrestaShop\Module\PsxMarketingWithGoogle\Provider;
use DateInterval;
use DateTimeImmutable;
use DateTimeZone;
use PrestaShop\Module\PsxMarketingWithGoogle\Adapter\ConfigurationAdapter;
use PrestaShop\Module\PsxMarketingWithGoogle\Config\Config;
use PrestaShop\Module\PsxMarketingWithGoogle\Repository\VerificationTagRepository;
class VerificationTagDataProvider
{
/**
* @var ConfigurationAdapter
*/
private $configurationAdapter;
/**
* @var VerificationTagRepository
*/
private $verificationTagRepository;
public function __construct(
ConfigurationAdapter $configurationAdapter,
VerificationTagRepository $verificationTagRepository
) {
$this->configurationAdapter = $configurationAdapter;
$this->verificationTagRepository = $verificationTagRepository;
}
public function isUpdateRequested(): bool
{
// If GMC account is not onboarded, do nothing.
if (empty($this->configurationAdapter->get(Config::REMARKETING_CONVERSION_MERCHANT_GMC_ID))) {
return false;
}
$configuration = $this->verificationTagRepository->getConfiguration();
return !$configuration || (
(new DateTimeImmutable($configuration['date_upd'], new DateTimeZone('UTC'))) <
(new DateTimeImmutable('now', new DateTimeZone('UTC')))->sub(new DateInterval('P30D'))
);
}
}

View File

@@ -0,0 +1,11 @@
<?php
header('Expires: Mon, 26 Jul 1997 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;