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,76 @@
<?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\Conversion;
use PrestaShop\Module\PsxMarketingWithGoogle\Adapter\ConfigurationAdapter;
use PrestaShop\Module\PsxMarketingWithGoogle\Config\Config;
class EnhancedConversionToggle
{
/**
* @var ConfigurationAdapter
*/
private $configurationAdapter;
public function __construct(
ConfigurationAdapter $configurationAdapter
) {
$this->configurationAdapter = $configurationAdapter;
}
public function enable(): bool
{
$snippet = base64_decode($this->configurationAdapter->get(
Config::PSX_MKTG_WITH_GOOGLE_REMARKETING_TAG
));
$alteredSnippet = (new SnippetUpdater($snippet))
->addEnhancedConversion()
->getSnippet();
return $this->configurationAdapter->updateValue(
Config::PSX_MKTG_WITH_GOOGLE_REMARKETING_TAG,
base64_encode($alteredSnippet)
) && $this->configurationAdapter->updateValue(
Config::PSX_MKTG_WITH_GOOGLE_REMARKETING_ENHANCED_STATUS,
true
);
}
public function disable(): bool
{
$snippet = base64_decode($this->configurationAdapter->get(
Config::PSX_MKTG_WITH_GOOGLE_REMARKETING_TAG
));
$alteredSnippet = (new SnippetUpdater($snippet))
->removeEnhancedConversion()
->getSnippet();
return $this->configurationAdapter->updateValue(
Config::PSX_MKTG_WITH_GOOGLE_REMARKETING_TAG,
base64_encode($alteredSnippet)
) && $this->configurationAdapter->updateValue(
Config::PSX_MKTG_WITH_GOOGLE_REMARKETING_ENHANCED_STATUS,
false
);
}
}

View File

@@ -0,0 +1,38 @@
<?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\Conversion;
class Hasher
{
/**
* @param string|null $data
*
* @return string|null
*/
public static function hash($data)
{
if (!$data) {
return null;
}
return hash('sha256', $data, false);
}
}

View File

@@ -0,0 +1,74 @@
<?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\Conversion;
use Brick\PhoneNumber\PhoneNumber;
use Brick\PhoneNumber\PhoneNumberFormat;
use Exception;
class Normalizer
{
/**
* @param string|null $data
* @param string|null $additionalNormalization
*
* @return string|null
*/
public static function normalize($data, $additionalNormalization = null)
{
if (empty($data)) {
return null;
}
$data = trim(strtolower($data));
if ($additionalNormalization === 'phone') {
return self::normalizePhoneNumber($data);
}
return $data;
}
public static function normalizePhoneNumber(string $data): string
{
$dataWithPlusAndNumbers = preg_replace('/([-\s\(\)])/', '', $data);
return preg_replace('/^(0{2})/', '+', $dataWithPlusAndNumbers);
}
/**
* @param string|null $data
* @param string $countryCode
*
* @return string|null
*/
public static function normalizeInE164($data, $countryCode)
{
if (empty($data)) {
return null;
}
try {
return PhoneNumber::parse($data, $countryCode)->format(PhoneNumberFormat::E164);
} catch (Exception $e) {
return $data;
}
}
}

View File

@@ -0,0 +1,54 @@
<?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\Conversion;
class SnippetUpdater
{
/**
* @var string
*/
private $snippet;
public function __construct(
string $originalSnippet
) {
$this->snippet = $originalSnippet;
}
public function addEnhancedConversion(): self
{
$this->snippet = preg_replace("/(gtag\('config', 'AW-[0-9]+')()(\);)/im", '${1}, {\'allow_enhanced_conversions\': true}${3}', $this->snippet);
return $this;
}
public function removeEnhancedConversion(): self
{
$this->snippet = str_replace(", {'allow_enhanced_conversions': true}", '', $this->snippet);
return $this;
}
public function getSnippet(): string
{
return $this->snippet;
}
}

View File

@@ -0,0 +1,278 @@
<?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\Conversion;
use JsonSerializable;
class UserAddressData implements JsonSerializable
{
/**
* @var string|null
*/
private $firstName;
/**
* @var string|null
*/
private $lastName;
/**
* @var string|null
*/
private $street;
/**
* @var string|null
*/
private $city;
/**
* @var string|null
*/
private $region;
/**
* @var string|null
*/
private $postalCode;
/**
* @var string|null
*/
private $country;
public function jsonSerialize(): array
{
$data = [];
if (!empty($this->firstName)) {
$data['sha256_first_name'] = $this->firstName;
}
if (!empty($this->lastName)) {
$data['sha256_last_name'] = $this->lastName;
}
if (!empty($this->street)) {
$data['street'] = $this->street;
}
if (!empty($this->city)) {
$data['city'] = $this->city;
}
if (!empty($this->region)) {
$data['region'] = $this->region;
}
if (!empty($this->postalCode)) {
$data['postal_code'] = $this->postalCode;
}
if (!empty($this->country)) {
$data['country'] = $this->country;
}
return $data;
}
/**
* @return bool
*/
public function isEmpty()
{
foreach (get_object_vars($this) as $value) {
if (!empty($value)) {
return false;
}
}
return true;
}
/**
* Get the value of firstName
*
* @return string
*/
public function getFirstName()
{
return $this->firstName;
}
/**
* Set the value of firstName
*
* @param string|null $firstName
*
* @return self
*/
public function setFirstName($firstName)
{
$this->firstName = $firstName;
return $this;
}
/**
* Get the value of lastName
*
* @return string
*/
public function getLastName()
{
return $this->lastName;
}
/**
* Set the value of lastName
*
* @param string|null $lastName
*
* @return self
*/
public function setLastName($lastName)
{
$this->lastName = $lastName;
return $this;
}
/**
* Get the value of street
*
* @return string
*/
public function getStreet()
{
return $this->street;
}
/**
* Set the value of street
*
* @param string|null $street
*
* @return self
*/
public function setStreet($street)
{
$this->street = $street;
return $this;
}
/**
* Get the value of city
*
* @return string
*/
public function getCity()
{
return $this->city;
}
/**
* Set the value of city
*
* @param string|null $city
*
* @return self
*/
public function setCity($city)
{
$this->city = $city;
return $this;
}
/**
* Get the value of region
*
* @return string
*/
public function getRegion()
{
return $this->region;
}
/**
* Set the value of region
*
* @param string|null $region
*
* @return self
*/
public function setRegion($region)
{
$this->region = $region;
return $this;
}
/**
* Get the value of postalCode
*
* @return string
*/
public function getPostalCode()
{
return $this->postalCode;
}
/**
* Set the value of postalCode
*
* @param string|null $postalCode
*
* @return self
*/
public function setPostalCode($postalCode)
{
$this->postalCode = $postalCode;
return $this;
}
/**
* Get the value of country
*
* @return string
*/
public function getCountry()
{
return $this->country;
}
/**
* Set the value of country
*
* @param string|null $country
*
* @return self
*/
public function setCountry($country)
{
$this->country = $country;
return $this;
}
}

View File

@@ -0,0 +1,153 @@
<?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\Conversion;
use JsonSerializable;
class UserData implements JsonSerializable
{
/**
* @var string|null
*/
private $email;
/**
* @var string|null
*/
private $phoneNumber;
/**
* @var UserAddressData|null
*/
private $address;
public function jsonSerialize(): array
{
$data = [];
if (!empty($this->email)) {
$data['sha256_email_address'] = $this->email;
}
if (!empty($this->phoneNumber)) {
$data['sha256_phone_number'] = $this->phoneNumber;
}
if (!empty($this->address) && !$this->address->isEmpty()) {
$data['address'] = $this->address;
}
return $data;
}
/**
* @return bool
*/
public function isEmpty()
{
if (!$this->address->isEmpty()) {
return false;
}
foreach (get_object_vars($this) as $var => $value) {
if ($var === 'address') {
continue;
}
if (!empty($value)) {
return false;
}
}
return true;
}
/**
* Get the value of email
*
* @return string|null
*/
public function getEmail()
{
return $this->email;
}
/**
* Set the value of email
*
* @param string|null $email
*
* @return self
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get the value of phoneNumber
*
* @return string|null
*/
public function getPhoneNumber()
{
return $this->phoneNumber;
}
/**
* Set the value of phoneNumber
*
* @param string|null $phoneNumber
*
* @return self
*/
public function setPhoneNumber($phoneNumber)
{
$this->phoneNumber = $phoneNumber;
return $this;
}
/**
* Get the value of address
*
* @return UserAddressData|null
*/
public function getAddress()
{
return $this->address;
}
/**
* Set the value of address
*
* @param UserAddressData|null $address
*
* @return self
*/
public function setAddress($address)
{
$this->address = $address;
return $this;
}
}

View File

@@ -0,0 +1,100 @@
<?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\Conversion;
use Address;
use Cart;
use Country;
use Customer;
use State;
class UserDataProvider
{
/**
* @var Customer
*/
private $customer;
/**
* @var Cart
*/
private $cart;
public function __construct(
Customer $customer,
Cart $cart
) {
$this->customer = $customer;
$this->cart = $cart;
}
/**
* Return the user personal details
*
* @see https://support.google.com/google-ads/answer/13258081#zippy=%2Cidentify-and-define-your-enhanced-conversions-fields
*/
public function getUserData(): UserData
{
$userData = new UserData();
$userDataAddress = new UserAddressData();
$userData->setEmail(Hasher::hash(Normalizer::normalize($this->customer->email)));
$userDataAddress->setFirstName(Hasher::hash(Normalizer::normalize($this->customer->firstname)));
$userDataAddress->setLastName(Hasher::hash(Normalizer::normalize($this->customer->lastname)));
$address = $this->getAddressFromCart();
if (!empty($address)) {
$userData->setPhoneNumber(Hasher::hash(Normalizer::normalizeInE164($address->phone ?: $address->phone_mobile, $this->getCountryIsoCodeFromAddress($address))));
$userDataAddress->setStreet(Normalizer::normalize(trim($address->address1 . ' ' . $address->address2)));
$userDataAddress->setCity(Normalizer::normalize($address->city));
$userDataAddress->setRegion(Normalizer::normalize($address->id_state ? (new State($address->id_state))->name : null));
$userDataAddress->setPostalCode(Normalizer::normalize($address->postcode));
$userDataAddress->setCountry(Normalizer::normalize($address->country));
}
$userData->setAddress($userDataAddress);
return $userData;
}
/**
* @return Address|null
*/
protected function getAddressFromCart()
{
if (!empty($this->cart->id_address_invoice)) {
return new Address($this->cart->id_address_invoice);
}
return null;
}
/**
* @return string|null
*/
protected function getCountryIsoCodeFromAddress(Address $address)
{
if (!empty($address->id_country)) {
return (new Country($address->id_country))->iso_code;
}
return null;
}
}

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;