first commit
This commit is contained in:
39
modules/emarketing/classes/Service/Attributes.php
Normal file
39
modules/emarketing/classes/Service/Attributes.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
/**
|
||||
* Class Attributes
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Attributes
|
||||
{
|
||||
/**
|
||||
* @param $idLang
|
||||
* @return array
|
||||
*/
|
||||
public function buildAttributeInformation($idLang)
|
||||
{
|
||||
$attrGroups = \AttributeGroup::getAttributesGroups($idLang);
|
||||
|
||||
$features = \Feature::getFeatures($idLang);
|
||||
|
||||
$mapData = array(
|
||||
'attributes' => $attrGroups,
|
||||
'features' => $features
|
||||
);
|
||||
|
||||
return $mapData;
|
||||
}
|
||||
}
|
||||
46
modules/emarketing/classes/Service/Category.php
Normal file
46
modules/emarketing/classes/Service/Category.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
use Emarketing\ClientError;
|
||||
|
||||
/**
|
||||
* Class Category
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Category
|
||||
{
|
||||
/**
|
||||
* @param $idCategory
|
||||
* @param $idLang
|
||||
* @return array
|
||||
* @throws ClientError
|
||||
*/
|
||||
public function buildCategoryInformation($idCategory, $idLang)
|
||||
{
|
||||
$category = new \Category($idCategory);
|
||||
|
||||
if (empty($category) || empty($category->id_category)) {
|
||||
throw new ClientError('No category with this ID');
|
||||
}
|
||||
|
||||
$categoryData = get_object_vars($category);
|
||||
|
||||
$categoryData['url'] = $category->getLink(null, $idLang);
|
||||
|
||||
$categoryData['children'] = $category->getSubCategories($idLang, true);
|
||||
|
||||
return $categoryData;
|
||||
}
|
||||
}
|
||||
74
modules/emarketing/classes/Service/Countries.php
Normal file
74
modules/emarketing/classes/Service/Countries.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
/**
|
||||
* Class Countries
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Countries
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function buildCountryInformation()
|
||||
{
|
||||
$context = \Context::getContext();
|
||||
|
||||
$countryData = array(
|
||||
'default' => array(
|
||||
'id_country' => \Configuration::get('PS_COUNTRY_DEFAULT'),
|
||||
'id_language' => \Configuration::get('PS_LANG_DEFAULT'),
|
||||
'id_currency' => \Configuration::get('PS_CURRENCY_DEFAULT')
|
||||
),
|
||||
'active' => array(
|
||||
'countries' => \Country::getCountries($context->language->id, true, false, false),
|
||||
'languages' => \Language::getLanguages(true, $context->shop->id),
|
||||
'currencies' => $this->getCurrencies($context->shop->id)
|
||||
)
|
||||
);
|
||||
|
||||
return $countryData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $shopId
|
||||
* @return array
|
||||
*/
|
||||
private function getCurrencies($shopId)
|
||||
{
|
||||
$currencyData = array();
|
||||
|
||||
$currencies = \Currency::getCurrenciesByIdShop($shopId);
|
||||
foreach ($currencies as $currency) {
|
||||
if ($currency['deleted'] == 1 || $currency['active'] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$currencyData[] = array(
|
||||
'id_currency' => (string)$currency['id_currency'],
|
||||
'name' => $currency['name'],
|
||||
'iso_code' => $currency['iso_code'],
|
||||
'conversion_rate' => $currency['conversion_rate'],
|
||||
'active' => $currency['active'],
|
||||
'deleted' => $currency['deleted'],
|
||||
'sign' => $currency['sign'],
|
||||
'iso_code_num' => $currency['iso_code_num'],
|
||||
'format' => $currency['format']
|
||||
);
|
||||
}
|
||||
|
||||
return $currencyData;
|
||||
}
|
||||
}
|
||||
124
modules/emarketing/classes/Service/FacebookPixel.php
Normal file
124
modules/emarketing/classes/Service/FacebookPixel.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
use Emarketing\Service\Snippets\Snippets;
|
||||
use Emarketing\Service\Products\PriceCalculation;
|
||||
|
||||
/**
|
||||
* Class FacebookPixel
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class FacebookPixel extends Snippets
|
||||
{
|
||||
/**
|
||||
* @param $globalTag
|
||||
* @param $viewContent
|
||||
* @param $addToCart
|
||||
* @param $purchase
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function savePixel($globalTag, $viewContent, $addToCart, $purchase)
|
||||
{
|
||||
$this->saveInConfiguration('FB_GLOBAL', $globalTag);
|
||||
$this->saveInConfiguration('FB_VIEWCONTENT', $viewContent);
|
||||
$this->saveInConfiguration('FB_ADDTOCART', $addToCart);
|
||||
$this->saveInConfiguration('FB_PURCHASE', $purchase);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGlobalTagSnippet()
|
||||
{
|
||||
$snippet = $this->getFromConfiguration('FB_GLOBAL');
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getViewContentSnippet()
|
||||
{
|
||||
$snippet = $this->getFromConfiguration('FB_VIEWCONTENT');
|
||||
|
||||
return $this->replaceProductPageVariables($snippet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getAddToCartSnippet()
|
||||
{
|
||||
$snippet = $this->getFromConfiguration('FB_ADDTOCART');
|
||||
|
||||
$snippet = preg_replace(
|
||||
['/<script>/', '/<\/script>/'],
|
||||
["<script>\ndocument.addEventListener('DOMContentLoaded', function(event) {\n document.querySelectorAll('.add-to-cart, #add_to_cart button, #add_to_cart a, #add_to_cart input').forEach(function(a){\na.addEventListener('click', function(){", "});});});\n</script>"],
|
||||
$snippet
|
||||
);
|
||||
|
||||
return $this->replaceProductPageVariables($snippet);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getPurchaseSnippet()
|
||||
{
|
||||
$snippet = $this->getFromConfiguration('FB_PURCHASE');
|
||||
|
||||
$order = new \Order(\Tools::getValue('id_order'));
|
||||
|
||||
$currency = new \Currency($order->id_currency);
|
||||
|
||||
$snippet = preg_replace(
|
||||
['/\bREPLACE_VALUE\b/', '/\bCURRENCY\b/'],
|
||||
[\Tools::ps_round($order->total_paid, 2), $currency->iso_code],
|
||||
$snippet
|
||||
);
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $snippet
|
||||
* @return string
|
||||
*/
|
||||
private function replaceProductPageVariables($snippet)
|
||||
{
|
||||
$product = \Context::getContext()->controller->getProduct();
|
||||
|
||||
$category = new \Category($product->id_category_default);
|
||||
$categoryName = is_array($category->name) ? reset($category->name) : $category->name;
|
||||
|
||||
$currentCurrency = \Context::getContext()->currency;
|
||||
|
||||
$priceCalculation = new PriceCalculation();
|
||||
$price = $priceCalculation->getFinalPrice($currentCurrency->id, $product->id, true, \Tools::getValue('id_product_attribute'));
|
||||
|
||||
$snippet = preg_replace(
|
||||
['/\bREPLACE_CONTENT\b/', '/\bREPLACE_CATEGORY\b/', '/\bREPLACE_CONTENT_ID\b/', '/\bREPLACE_VALUE\b/', '/\bCURRENCY\b/'],
|
||||
[$product->name, $categoryName, $product->id, $price, $currentCurrency->iso_code],
|
||||
$snippet
|
||||
);
|
||||
|
||||
return $snippet;
|
||||
}
|
||||
}
|
||||
83
modules/emarketing/classes/Service/FrontendHeader.php
Normal file
83
modules/emarketing/classes/Service/FrontendHeader.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
/**
|
||||
* Class FrontendHeader
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class FrontendHeader
|
||||
{
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function buildHtml()
|
||||
{
|
||||
$currentPage = \Context::getContext()->controller->php_self;
|
||||
|
||||
$html = "<!-- emarketing start -->\n";
|
||||
|
||||
$html .= $this->buildGoogle($currentPage);
|
||||
|
||||
$html .= $this->buildFacebook($currentPage);
|
||||
|
||||
$html .= "<!-- emarketing end -->";
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currentPage
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function buildGoogle($currentPage)
|
||||
{
|
||||
$serviceVerification = new Verification;
|
||||
$html = $serviceVerification->getTag() . "\n";
|
||||
|
||||
$serviceTracker = new GoogleTracker();
|
||||
$html .= $serviceTracker->getGlobalSiteTracker() . "\n";
|
||||
|
||||
if ($currentPage == 'order-confirmation') {
|
||||
$html .= $serviceTracker->getConversionTracker() . "\n";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $currentPage
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function buildFacebook($currentPage)
|
||||
{
|
||||
$serviceTracker = new FacebookPixel();
|
||||
|
||||
$html = $serviceTracker->getGlobalTagSnippet() . "\n";
|
||||
|
||||
if ($currentPage == 'product') {
|
||||
$html .= $serviceTracker->getViewContentSnippet() . "\n";
|
||||
$html .= $serviceTracker->getAddToCartSnippet() . "\n";
|
||||
}
|
||||
|
||||
if ($currentPage == 'order-confirmation') {
|
||||
$html .= $serviceTracker->getPurchaseSnippet() . "\n";
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
268
modules/emarketing/classes/Service/Gateway.php
Normal file
268
modules/emarketing/classes/Service/Gateway.php
Normal file
@@ -0,0 +1,268 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
use Emarketing\CurlRequest;
|
||||
|
||||
/**
|
||||
* Class Gateway
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Gateway
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $ecomUrl = "https://app.emarketing.com";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $ecomSignInUrl = "https://app.emarketing.com/?jwt=";
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $gatewayUrl = "https://gateway.emarketing.com/gateway_api/sso";
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function login()
|
||||
{
|
||||
$token = $this->getToken();
|
||||
|
||||
if (empty($token) || strpos($token, ':') === false) {
|
||||
return $this->ecomUrl;
|
||||
}
|
||||
|
||||
$jwt = $this->fetchJwt($token);
|
||||
|
||||
if (empty($jwt)) {
|
||||
return $this->ecomUrl;
|
||||
}
|
||||
|
||||
return $this->ecomSignInUrl . $jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function signup()
|
||||
{
|
||||
$token = $this->register();
|
||||
|
||||
if (empty($token)) {
|
||||
return $this->ecomUrl;
|
||||
}
|
||||
|
||||
$jwt = $this->fetchJwt($token);
|
||||
|
||||
if (empty($jwt)) {
|
||||
return $this->ecomUrl;
|
||||
}
|
||||
|
||||
return $this->ecomSignInUrl . $jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function linkAccount()
|
||||
{
|
||||
$token = $this->getToken();
|
||||
|
||||
if (!empty($token)) {
|
||||
return $this->ecomUrl;
|
||||
}
|
||||
|
||||
$jwt = $this->authorize();
|
||||
|
||||
if (empty($jwt)) {
|
||||
return $this->ecomUrl;
|
||||
}
|
||||
|
||||
return $this->ecomSignInUrl . $jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getToken()
|
||||
{
|
||||
return \Configuration::get('EMARKETING_SHOPTOKEN');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $token
|
||||
* @return bool
|
||||
*/
|
||||
private function saveToken($token)
|
||||
{
|
||||
return \Configuration::updateValue('EMARKETING_SHOPTOKEN', $token);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
private function register()
|
||||
{
|
||||
$data = array(
|
||||
"partner_short_name" => "prestashop",
|
||||
"authorizations" => ['datafeed_api'],
|
||||
"language" => \Tools::strtolower(\Tools::substr(\Language::getIsoById(\Configuration::get('PS_LANG_DEFAULT')), 0, 2)),
|
||||
"country" => \Tools::strtoupper(\Country::getIsoById(\Configuration::get('PS_COUNTRY_DEFAULT'))),
|
||||
"email" => \Configuration::get('PS_SHOP_EMAIL'),
|
||||
"version" => \Module::getInstanceByName('emarketing')->version
|
||||
);
|
||||
|
||||
$data = $this->validateRegistrationData($data);
|
||||
|
||||
$header = "Origin: " . \Context::getContext()->shop->getBaseURL(true);
|
||||
|
||||
$token = $this->registerRequest($data, $header);
|
||||
|
||||
if (empty($token)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->saveToken($token);
|
||||
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @return mixed
|
||||
*/
|
||||
private function validateRegistrationData($data)
|
||||
{
|
||||
$schema = json_decode(\Tools::file_get_contents('https://ecommerce-os.s3.eu-west-1.amazonaws.com/schema/partner.json'));
|
||||
$languages = $schema->links[0]->schema->properties->language->enum;
|
||||
$countries = $schema->links[0]->schema->properties->country->enum;
|
||||
|
||||
if (!in_array($data['language'], $languages)) {
|
||||
$data['language'] = 'en';
|
||||
}
|
||||
|
||||
if (!in_array($data['country'], $countries)) {
|
||||
$data['country'] = 'DE';
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $data
|
||||
* @param $header
|
||||
* @return bool|string
|
||||
*/
|
||||
private function registerRequest($data, $header)
|
||||
{
|
||||
$response = $this->sendRequest('/signup', $header, $data);
|
||||
|
||||
if ($response['code'] == 400) {
|
||||
unset($data['email']);
|
||||
$response = $this->sendRequest('/signup', $header, $data);
|
||||
}
|
||||
|
||||
if ($response['code'] !== 200 || empty($response['body']->token)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response['body']->token;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool|string
|
||||
*/
|
||||
private function authorize()
|
||||
{
|
||||
$data = array(
|
||||
"partner_short_name" => "prestashop",
|
||||
'authorizations' => ['datafeed_api'],
|
||||
"version" => \Module::getInstanceByName('emarketing')->version
|
||||
);
|
||||
|
||||
$header = "Origin: " . \Context::getContext()->shop->getBaseURL(true);
|
||||
|
||||
$response = $this->sendRequest('/authorize', $header, $data);
|
||||
|
||||
if ($response['code'] !== 200 || empty($response['body']->uuid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->saveToken($response['body']->uuid);
|
||||
|
||||
\Configuration::updateValue('EMARKETING_AUTHORIZE_JWT', $response['body']->jwt);
|
||||
|
||||
return $response['body']->jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $token
|
||||
* @return bool|string
|
||||
*/
|
||||
private function fetchJwt($token)
|
||||
{
|
||||
$header = "Authorization: " . $token;
|
||||
|
||||
$response = $this->sendRequest('/jwt', $header);
|
||||
|
||||
if (empty($response['body']->jwt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $response['body']->jwt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param string $additionalHeader
|
||||
* @param array $data
|
||||
* @return array
|
||||
*/
|
||||
private function sendRequest($path, $additionalHeader = "", $data = array())
|
||||
{
|
||||
$curl = new CurlRequest($this->gatewayUrl . $path);
|
||||
|
||||
$dataJson = "";
|
||||
|
||||
if (!empty($data)) {
|
||||
$curl->setOption(CURLOPT_CUSTOMREQUEST, 'POST');
|
||||
|
||||
$dataJson = json_encode($data);
|
||||
$curl->setOption(CURLOPT_POSTFIELDS, $dataJson);
|
||||
}
|
||||
|
||||
$header = array(
|
||||
'Content-Type: application/json; charset=utf-8',
|
||||
'Content-Length: ' . \Tools::strlen($dataJson),
|
||||
$additionalHeader
|
||||
);
|
||||
|
||||
$curl->setOption(CURLOPT_HTTPHEADER, $header);
|
||||
|
||||
$response = $curl->execute();
|
||||
|
||||
$return = array(
|
||||
'body' => json_decode($response),
|
||||
'code' => $curl->getInfo(CURLINFO_HTTP_CODE)
|
||||
);
|
||||
|
||||
$curl->close();
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
68
modules/emarketing/classes/Service/GoogleTracker.php
Normal file
68
modules/emarketing/classes/Service/GoogleTracker.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
use Emarketing\Service\Snippets\Snippets;
|
||||
|
||||
/**
|
||||
* Class GoogleTracker
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class GoogleTracker extends Snippets
|
||||
{
|
||||
/**
|
||||
* @param $globalSiteTracker
|
||||
* @param $conversionTracker
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveTracker($globalSiteTracker, $conversionTracker)
|
||||
{
|
||||
$this->saveInConfiguration('GLOBAL_SITE_TRACKER', $globalSiteTracker);
|
||||
$this->saveInConfiguration('CONVERSION_TRACKER', $conversionTracker);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getGlobalSiteTracker()
|
||||
{
|
||||
$globalSiteTracker = $this->getFromConfiguration('GLOBAL_SITE_TRACKER');
|
||||
|
||||
return $globalSiteTracker;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function getConversionTracker()
|
||||
{
|
||||
$conversionTracker = $this->getFromConfiguration('CONVERSION_TRACKER');
|
||||
|
||||
$order = new \Order(\Tools::getValue('id_order'));
|
||||
|
||||
$currency = new \Currency($order->id_currency);
|
||||
|
||||
$conversionTracker = preg_replace(
|
||||
['/\'value\'\:[\s\S]+?,/', '/\'currency\'\:[\s\S]+?,/', '/\'transaction_id\'\:[\s\S]+?\'\'/'],
|
||||
["'value': " . \Tools::ps_round($order->total_paid, 2) . ",", "'currency': '" . $currency->iso_code . "',", "'transaction_id': '" . $order->id . "',"],
|
||||
$conversionTracker
|
||||
);
|
||||
|
||||
return $conversionTracker;
|
||||
}
|
||||
}
|
||||
191
modules/emarketing/classes/Service/Products.php
Normal file
191
modules/emarketing/classes/Service/Products.php
Normal file
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
use Emarketing\Service\Products\Variants;
|
||||
use Emarketing\Service\Products\Images;
|
||||
use Emarketing\Service\Products\Carriers;
|
||||
use Emarketing\Service\Products\Features;
|
||||
use Emarketing\Service\Products\PriceCalculation;
|
||||
|
||||
/**
|
||||
* Class Products
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Products
|
||||
{
|
||||
/**
|
||||
* @var Carriers
|
||||
*/
|
||||
private $serviceCarriers;
|
||||
|
||||
/**
|
||||
* @var Variants
|
||||
*/
|
||||
private $serviceVariants;
|
||||
|
||||
/**
|
||||
* @var Images
|
||||
*/
|
||||
private $serviceImages;
|
||||
|
||||
/**
|
||||
* @var Features
|
||||
*/
|
||||
private $serviceFeatures;
|
||||
|
||||
/**
|
||||
* @var PriceCalculation
|
||||
*/
|
||||
private $priceCalculation;
|
||||
|
||||
/**
|
||||
* @var \Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Products constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->serviceVariants = new Variants();
|
||||
$this->serviceImages = new Images();
|
||||
$this->serviceCarriers = new Carriers();
|
||||
$this->serviceFeatures = new Features();
|
||||
$this->priceCalculation = new PriceCalculation();
|
||||
|
||||
$this->context = \Context::getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $offset
|
||||
* @param $limit
|
||||
* @param $idLang
|
||||
* @param $idCountry
|
||||
* @param $idCurrency
|
||||
* @return array
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function buildProductsInformation($offset, $limit, $idLang, $idCountry, $idCurrency)
|
||||
{
|
||||
$productsData = array();
|
||||
|
||||
$productsData['settings'] = $this->getShopSettings();
|
||||
|
||||
$products = $this->getAllProducts($offset, $limit, $idLang);
|
||||
|
||||
foreach ($products as $product) {
|
||||
$productData = $this->getProductDetails($product, $idLang, $idCountry, $idCurrency);
|
||||
|
||||
$productsData[$product['id_product']] = $productData;
|
||||
}
|
||||
|
||||
return $productsData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $offset
|
||||
* @param $limit
|
||||
* @param $idLang
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function getAllProducts($offset, $limit, $idLang)
|
||||
{
|
||||
$products = \Product::getProducts($idLang, $offset, $limit, 'id_product', 'ASC', false, true);
|
||||
|
||||
if ($products === false) {
|
||||
throw new \Exception('Error while fetching products.');
|
||||
}
|
||||
|
||||
return $products;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $product
|
||||
* @param $idLang
|
||||
* @param $idCountry
|
||||
* @return array
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
private function getProductDetails($product, $idLang, $idCountry, $idCurrency)
|
||||
{
|
||||
$productData = array();
|
||||
|
||||
$psProduct = new \Product($product['id_product'], false, $idLang);
|
||||
|
||||
$productData['details'] = $product;
|
||||
|
||||
$productData['additional'] = $this->getAdditionalInformation($psProduct, $idLang);
|
||||
|
||||
$productData['variants'] = $this->serviceVariants->buildVariantInformation($psProduct, $idLang, $idCurrency);
|
||||
|
||||
$productData['images'] = $this->serviceImages->buildImageInformation($psProduct, $idLang);
|
||||
|
||||
$productData['carriers'] = $this->serviceCarriers->buildCarrierInformation($idLang, $idCountry, $psProduct);
|
||||
|
||||
$productData['features'] = $this->serviceFeatures->buildFeatureInformation($psProduct, $idLang);
|
||||
|
||||
$productData['attributes'] = $psProduct->getAttributesGroups($idLang);
|
||||
|
||||
$productData['plugin_price'] = $this->priceCalculation->getFinalPrice($idCurrency, $psProduct->id, false);
|
||||
$productData['plugin_sale_price'] = $this->priceCalculation->getFinalPrice($idCurrency, $psProduct->id, true);
|
||||
|
||||
return $productData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function getShopSettings()
|
||||
{
|
||||
$settings = array();
|
||||
|
||||
$settings['dimension_unit'] = \Configuration::get('PS_DIMENSION_UNIT');
|
||||
$settings['weight_unit'] = \Configuration::get('PS_WEIGHT_UNIT');
|
||||
$settings['allow_ordering_oos'] = \Configuration::get('PS_ORDER_OUT_OF_STOCK');
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Product $psProduct
|
||||
* @param $idLang
|
||||
* @return array
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function getAdditionalInformation($psProduct, $idLang)
|
||||
{
|
||||
$additional = array();
|
||||
|
||||
$additional['categories'] = $psProduct->getCategories();
|
||||
|
||||
$additional['url'] = $this->context->link->getProductLink(
|
||||
$psProduct->id,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$idLang
|
||||
);
|
||||
|
||||
$additional['quantity'] = \StockAvailable::getQuantityAvailableByProduct($psProduct->id);
|
||||
|
||||
$additional['availability'] = $psProduct->checkQty(1);
|
||||
|
||||
$additional['special_price'] = \SpecificPrice::getByProductId($psProduct->id);
|
||||
|
||||
return $additional;
|
||||
}
|
||||
}
|
||||
120
modules/emarketing/classes/Service/Products/Carriers.php
Normal file
120
modules/emarketing/classes/Service/Products/Carriers.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service\Products;
|
||||
|
||||
/**
|
||||
* Class Carriers
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Carriers
|
||||
{
|
||||
/**
|
||||
* @param $idLang
|
||||
* @param $idCountry
|
||||
* @param \Product $psProduct
|
||||
* @return array
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function buildCarrierInformation($idLang, $idCountry, $psProduct)
|
||||
{
|
||||
$idZone = \Country::getIdZone($idCountry);
|
||||
|
||||
$carriers = $this->getAllCarriers($idLang, $idZone);
|
||||
|
||||
foreach ($carriers as $carrierKey => $carrier) {
|
||||
$carriers[$carrierKey]['price'] = $this->getShippingCost($idZone, $psProduct, $carrier);
|
||||
}
|
||||
|
||||
return $carriers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idLang
|
||||
* @param $idZone
|
||||
* @return array
|
||||
*/
|
||||
private function getAllCarriers($idLang, $idZone)
|
||||
{
|
||||
return \Carrier::getCarriers($idLang, true, false, $idZone, null, \Carrier::ALL_CARRIERS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idZone
|
||||
* @param \Product $psProduct
|
||||
* @param $carrier
|
||||
* @return bool|float
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
private function getShippingCost($idZone, $psProduct, $carrier)
|
||||
{
|
||||
$carrier = new \Carrier($carrier['id_carrier']);
|
||||
|
||||
$rangeTable = $carrier->getRangeTable();
|
||||
|
||||
if ($rangeTable == 'range_weight') {
|
||||
$costs = $this->getCostsByWeight($carrier, $psProduct->weight, $idZone, $carrier->range_behavior);
|
||||
}
|
||||
|
||||
if ($rangeTable == 'range_price') {
|
||||
$costs = $this->getCostsByPrice($carrier, $psProduct->price, $idZone, $carrier->range_behavior);
|
||||
}
|
||||
|
||||
if (empty($costs)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$address = \Address::initialize();
|
||||
$carrierTax = $carrier->getTaxesRate($address);
|
||||
|
||||
if (!empty($carrierTax)) {
|
||||
return $costs + ($costs * $carrierTax / 100);
|
||||
}
|
||||
|
||||
return $costs;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Carrier $carrier
|
||||
* @param $productWeight
|
||||
* @param $idZone
|
||||
* @param $rangeBehaviour
|
||||
* @return bool|float
|
||||
*/
|
||||
private function getCostsByWeight($carrier, $productWeight, $idZone, $rangeBehaviour)
|
||||
{
|
||||
$priceByWeightCheck = \Carrier::checkDeliveryPriceByWeight($carrier->id, $productWeight, $idZone);
|
||||
if ($priceByWeightCheck || $rangeBehaviour == 0) {
|
||||
return $carrier->getDeliveryPriceByWeight($productWeight, $idZone);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Carrier $carrier
|
||||
* @param $productPrice
|
||||
* @param $idZone
|
||||
* @param $rangeBehaviour
|
||||
* @return bool|float
|
||||
*/
|
||||
private function getCostsByPrice($carrier, $productPrice, $idZone, $rangeBehaviour)
|
||||
{
|
||||
$priceByPriceCheck = \Carrier::checkDeliveryPriceByPrice($carrier->id, $productPrice, $idZone);
|
||||
if ($priceByPriceCheck || $rangeBehaviour == 0) {
|
||||
return $carrier->getDeliveryPriceByPrice($productPrice, $idZone);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
52
modules/emarketing/classes/Service/Products/Features.php
Normal file
52
modules/emarketing/classes/Service/Products/Features.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service\Products;
|
||||
|
||||
/**
|
||||
* Class Features
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Features
|
||||
{
|
||||
/**
|
||||
* @param \Product $psProduct
|
||||
* @param $idLang
|
||||
* @return array
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function buildFeatureInformation($psProduct, $idLang)
|
||||
{
|
||||
$features = $psProduct->getFeatures();
|
||||
|
||||
$featureData = array();
|
||||
foreach ($features as $feature) {
|
||||
$featureData[] = $this->getValue($feature['id_feature_value'], $idLang);
|
||||
}
|
||||
|
||||
return $featureData;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idValue
|
||||
* @param $idLang
|
||||
* @return \FeatureValue
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
private function getValue($idValue, $idLang)
|
||||
{
|
||||
$featureValue = new \FeatureValue($idValue, $idLang);
|
||||
|
||||
return get_object_vars($featureValue);
|
||||
}
|
||||
}
|
||||
79
modules/emarketing/classes/Service/Products/Images.php
Normal file
79
modules/emarketing/classes/Service/Products/Images.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service\Products;
|
||||
|
||||
/**
|
||||
* Class Images
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Images
|
||||
{
|
||||
/**
|
||||
* @var \Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Images constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->context= \Context::getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Product $psProduct
|
||||
* @param $idLang
|
||||
* @return mixed
|
||||
*/
|
||||
public function buildImageInformation($psProduct, $idLang)
|
||||
{
|
||||
$images = array();
|
||||
|
||||
$productImages = $psProduct->getImages($idLang);
|
||||
$images['product'] = $this->addUrls($productImages, $psProduct->link_rewrite);
|
||||
|
||||
$images['variants'] = array();
|
||||
$variantImages = $psProduct->getCombinationImages($idLang);
|
||||
if (empty($variantImages)) {
|
||||
return $images;
|
||||
}
|
||||
foreach ($variantImages as $variantImage) {
|
||||
$images['variants'][] = $this->addUrls($variantImage, $psProduct->link_rewrite);
|
||||
}
|
||||
|
||||
return $images;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $images
|
||||
* @param $linkRewrite
|
||||
* @return array
|
||||
*/
|
||||
private function addUrls($images, $linkRewrite)
|
||||
{
|
||||
if (empty($images)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$completeImages = array();
|
||||
foreach ($images as $image) {
|
||||
$image['url'] = $this->context->link->getImageLink($linkRewrite, $image['id_image']);
|
||||
|
||||
$completeImages[] = $image;
|
||||
}
|
||||
|
||||
return $completeImages;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service\Products;
|
||||
|
||||
/**
|
||||
* Class PriceCalculation
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class PriceCalculation
|
||||
{
|
||||
/**
|
||||
* @var \Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Images constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->context= \Context::getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idCurrency
|
||||
* @param $idProduct
|
||||
* @param $saleIncluded
|
||||
* @param $idVariant
|
||||
* @return string
|
||||
*/
|
||||
public function getFinalPrice($idCurrency, $idProduct, $saleIncluded = false, $idVariant = false)
|
||||
{
|
||||
$specificPrice = \SpecificPrice::getSpecificPrice(
|
||||
$idProduct,
|
||||
$this->context->shop->id,
|
||||
$idCurrency,
|
||||
$this->context->country->id,
|
||||
1,
|
||||
1,
|
||||
$idVariant
|
||||
);
|
||||
|
||||
return \Product::priceCalculation(
|
||||
$this->context->shop->id,
|
||||
$idProduct,
|
||||
$idVariant,
|
||||
$this->context->country->id,
|
||||
0,
|
||||
0,
|
||||
$idCurrency,
|
||||
1,
|
||||
1,
|
||||
true,
|
||||
2,
|
||||
false,
|
||||
$saleIncluded,
|
||||
true,
|
||||
$specificPrice,
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
94
modules/emarketing/classes/Service/Products/Variants.php
Normal file
94
modules/emarketing/classes/Service/Products/Variants.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service\Products;
|
||||
|
||||
use Emarketing\Service\Products\PriceCalculation;
|
||||
|
||||
/**
|
||||
* Class Variants
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Variants
|
||||
{
|
||||
/**
|
||||
* @var PriceCalculation
|
||||
*/
|
||||
private $priceCalculation;
|
||||
|
||||
/**
|
||||
* @var \Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
/**
|
||||
* Variants constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->priceCalculation = new PriceCalculation();
|
||||
$this->context = \Context::getContext();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Product $psProduct
|
||||
* @param $idLang
|
||||
* @param $idCurrency
|
||||
* @return mixed
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
public function buildVariantInformation($psProduct, $idLang, $idCurrency)
|
||||
{
|
||||
$variants = $psProduct->getAttributesResume($idLang);
|
||||
|
||||
if (empty($variants)) {
|
||||
return array();
|
||||
}
|
||||
|
||||
foreach ($variants as $variantKey => $variant) {
|
||||
$variants[$variantKey]['url'] = $this->getUrl($psProduct->id, $idLang, $variant['id_product_attribute']);
|
||||
|
||||
$variants[$variantKey]['special_price'] = \SpecificPrice::getByProductId(
|
||||
$psProduct->id,
|
||||
$variant['id_product_attribute']
|
||||
);
|
||||
|
||||
$variants[$variantKey]['availability'] = $psProduct->checkQty(1);
|
||||
|
||||
$variants[$variantKey]['plugin_price'] = $this->priceCalculation->getFinalPrice($idCurrency, $psProduct->id, false, $variant['id_product_attribute']);
|
||||
$variants[$variantKey]['plugin_sale_price'] = $this->priceCalculation->getFinalPrice($idCurrency, $psProduct->id, true, $variant['id_product_attribute']);
|
||||
}
|
||||
|
||||
return $variants;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $idProduct
|
||||
* @param $idLang
|
||||
* @param $idVariant
|
||||
* @return string
|
||||
* @throws \PrestaShopException
|
||||
*/
|
||||
private function getUrl($idProduct, $idLang, $idVariant)
|
||||
{
|
||||
return $this->context->link->getProductLink(
|
||||
$idProduct,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$idLang,
|
||||
null,
|
||||
$idVariant
|
||||
);
|
||||
}
|
||||
}
|
||||
11
modules/emarketing/classes/Service/Products/index.php
Normal file
11
modules/emarketing/classes/Service/Products/index.php
Normal 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;
|
||||
55
modules/emarketing/classes/Service/Snippets/Snippets.php
Normal file
55
modules/emarketing/classes/Service/Snippets/Snippets.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service\Snippets;
|
||||
|
||||
/**
|
||||
* Class Snippets
|
||||
* @package Emarketing\Service\Snippets
|
||||
*/
|
||||
class Snippets
|
||||
{
|
||||
/**
|
||||
* @param $key
|
||||
* @param $code
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function saveInConfiguration($key, $code)
|
||||
{
|
||||
if (is_null($code) || !is_string($code)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$code = htmlentities($code, ENT_QUOTES);
|
||||
|
||||
$saved = \Configuration::updateValue('EMARKETING_' . $key, $code);
|
||||
|
||||
if (!$saved) {
|
||||
throw new \Exception('Error while saving ' . $key);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $key
|
||||
* @return string
|
||||
*/
|
||||
protected function getFromConfiguration($key)
|
||||
{
|
||||
$code = \Configuration::get('EMARKETING_' . $key);
|
||||
|
||||
return html_entity_decode($code, ENT_QUOTES);
|
||||
}
|
||||
}
|
||||
11
modules/emarketing/classes/Service/Snippets/index.php
Normal file
11
modules/emarketing/classes/Service/Snippets/index.php
Normal 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;
|
||||
62
modules/emarketing/classes/Service/Verification.php
Normal file
62
modules/emarketing/classes/Service/Verification.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* This file is licenced under the GNU General Public License, version 3 (GPL-3.0).
|
||||
* With the purchase or the installation of the software in your application
|
||||
* you accept the licence agreement.
|
||||
*
|
||||
* @author emarketing www.emarketing.com <integrations@emarketing.com>
|
||||
* @copyright 2020 emarketing AG
|
||||
* @license https://opensource.org/licenses/GPL-3.0 GNU General Public License version 3
|
||||
*/
|
||||
|
||||
namespace Emarketing\Service;
|
||||
|
||||
/**
|
||||
* Class Verification
|
||||
* @package Emarketing\Service
|
||||
*/
|
||||
class Verification
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $configName = 'EMARKETING_VERIFICATION_TAG';
|
||||
|
||||
/**
|
||||
* @param $tag
|
||||
* @return bool
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function saveTag($tag)
|
||||
{
|
||||
if (is_null($tag) || !is_string($tag)) {
|
||||
$tag = "";
|
||||
}
|
||||
|
||||
$tag = htmlentities($tag, ENT_QUOTES);
|
||||
|
||||
$saved = \Configuration::updateValue($this->configName, $tag);
|
||||
|
||||
if (!$saved) {
|
||||
throw new \Exception('Error while saving tag.');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTag()
|
||||
{
|
||||
$tag = \Configuration::get($this->configName);
|
||||
|
||||
if (empty($tag)) {
|
||||
return "";
|
||||
}
|
||||
|
||||
return html_entity_decode($tag);
|
||||
}
|
||||
}
|
||||
11
modules/emarketing/classes/Service/index.php
Normal file
11
modules/emarketing/classes/Service/index.php
Normal 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;
|
||||
Reference in New Issue
Block a user