first commit
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Context;
|
||||
|
||||
class AttributesRepository
|
||||
{
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
public function __construct(Context $context)
|
||||
{
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all custom and product attributes.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllAttributes(): array
|
||||
{
|
||||
$attributes = [];
|
||||
$customAttributes = \AttributeGroupCore::getAttributesGroups($this->context->language->id);
|
||||
$features = \FeatureCore::getFeatures($this->context->language->id);
|
||||
|
||||
foreach ($customAttributes as $attr) {
|
||||
$attributes[] = [
|
||||
// Not the best way in terms of permances, but avoid being responsible of a whole SQL query.
|
||||
'name' => array_values(array_unique((array) (new \AttributeGroupCore($attr['id_attribute_group']))->name)),
|
||||
'type' => 'custom',
|
||||
];
|
||||
}
|
||||
|
||||
foreach ($features as $feature) {
|
||||
$attributes[] = [
|
||||
// Not the best way in terms of permances, but avoid being responsible of a whole SQL query.
|
||||
'name' => array_values(array_unique((array) (new \FeatureCore($feature['id_feature']))->name)),
|
||||
'type' => 'feature',
|
||||
];
|
||||
}
|
||||
|
||||
return $attributes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Carrier;
|
||||
use Context;
|
||||
use Db;
|
||||
use RangePrice;
|
||||
use RangeWeight;
|
||||
|
||||
class CarrierRepository
|
||||
{
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
public function __construct(Db $db, Context $context)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
public function getCarriers(int $langId): array
|
||||
{
|
||||
$carriers = Carrier::getCarriers($langId, false, false, false, null, Carrier::ALL_CARRIERS);
|
||||
|
||||
$data = [];
|
||||
foreach ($carriers as $key => $carrier) {
|
||||
$carrierObj = new Carrier($carrier['id_carrier']);
|
||||
|
||||
$data[$key]['collection'] = 'carriers';
|
||||
$data[$key]['id'] = $carrierObj->id;
|
||||
$data[$key]['properties'] = $carrier;
|
||||
|
||||
$deliveryPriceByRanges = self::getDeliveryPriceByRange($carrierObj);
|
||||
foreach ($deliveryPriceByRanges as $deliveryPriceByRange) {
|
||||
$data[$key]['collection'] = 'carriers_details';
|
||||
$data[$key]['id'] = $deliveryPriceByRange['id_range_weight'];
|
||||
$data[$key]['properties'] = $deliveryPriceByRange;
|
||||
}
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getDeliveryPriceByRange(Carrier $carrierObj): array
|
||||
{
|
||||
$rangeTable = $carrierObj->getRangeTable();
|
||||
switch ($rangeTable) {
|
||||
case 'range_weight':
|
||||
return self::getCarrierByWeightRange($carrierObj);
|
||||
case 'range_price':
|
||||
return self::getCarrierByPriceRange($carrierObj);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
private function getCarrierByPriceRange(Carrier $carrierObj): array
|
||||
{
|
||||
$deliveryPriceByRange = Carrier::getDeliveryPriceByRanges('range_price', (int) $carrierObj->id);
|
||||
|
||||
$filteredRanges = [];
|
||||
foreach ($deliveryPriceByRange as $range) {
|
||||
$filteredRanges[$range['id_range_price']]['id_range_price'] = $range['id_range_price'];
|
||||
$filteredRanges[$range['id_range_price']]['id_carrier'] = $range['id_carrier'];
|
||||
$filteredRanges[$range['id_range_price']]['zones'][$range['id_zone']]['id_zone'] = $range['id_zone'];
|
||||
$filteredRanges[$range['id_range_price']]['zones'][$range['id_zone']]['price'] = $range['price'];
|
||||
}
|
||||
|
||||
return $filteredRanges;
|
||||
}
|
||||
|
||||
private function getCarrierByWeightRange(Carrier $carrierObj): array
|
||||
{
|
||||
$deliveryPriceByRange = Carrier::getDeliveryPriceByRanges('range_weight', (int) $carrierObj->id);
|
||||
|
||||
$filteredRanges = [];
|
||||
foreach ($deliveryPriceByRange as $range) {
|
||||
$filteredRanges[$range['id_range_weight']]['id_range_weight'] = $range['id_range_weight'];
|
||||
$filteredRanges[$range['id_range_weight']]['id_carrier'] = $range['id_carrier'];
|
||||
$filteredRanges[$range['id_range_weight']]['zones'][$range['id_zone']]['id_zone'] = $range['id_zone'];
|
||||
$filteredRanges[$range['id_range_weight']]['zones'][$range['id_zone']]['price'] = $range['price'];
|
||||
}
|
||||
|
||||
return $filteredRanges;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Context;
|
||||
use Country;
|
||||
use Db;
|
||||
use DbQuery;
|
||||
use PrestaShop\Module\PsxMarketingWithGoogle\Adapter\ConfigurationAdapter;
|
||||
|
||||
class CountryRepository
|
||||
{
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
private $countryIsoCodeCache = [];
|
||||
|
||||
/**
|
||||
* @var ConfigurationAdapter
|
||||
*/
|
||||
private $configurationAdapter;
|
||||
|
||||
private $country;
|
||||
|
||||
public function __construct(Db $db, Context $context, Country $country, ConfigurationAdapter $configAdapter)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->context = $context;
|
||||
$this->country = $country;
|
||||
$this->configurationAdapter = $configAdapter;
|
||||
}
|
||||
|
||||
private function getBaseQuery(): DbQuery
|
||||
{
|
||||
$query = new DbQuery();
|
||||
|
||||
$query->from('country', 'c')
|
||||
->innerJoin('country_shop', 'cs', 'cs.id_country = c.id_country')
|
||||
->innerJoin('country_lang', 'cl', 'cl.id_country = c.id_country')
|
||||
->where('cs.id_shop = ' . (int) $this->context->shop->id)
|
||||
->where('cl.id_lang = ' . (int) $this->context->language->id);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getCountryIsoCodesByZoneId(int $zoneId, bool $active = true): array
|
||||
{
|
||||
$cacheKey = $zoneId . '-' . (int) $active;
|
||||
|
||||
if (!isset($this->countryIsoCodeCache[$cacheKey])) {
|
||||
$query = $this->getBaseQuery();
|
||||
|
||||
$query->select('iso_code');
|
||||
$query->where('id_zone = ' . (int) $zoneId);
|
||||
$query->where('active = ' . (bool) $active);
|
||||
|
||||
$isoCodes = [];
|
||||
foreach ($this->db->executeS($query) as $country) {
|
||||
$isoCodes[] = $country['iso_code'];
|
||||
}
|
||||
$this->countryIsoCodeCache[$cacheKey] = $isoCodes;
|
||||
}
|
||||
|
||||
return $this->countryIsoCodeCache[$cacheKey];
|
||||
}
|
||||
|
||||
public function getActiveCountries(): array
|
||||
{
|
||||
$query = $this->getBaseQuery();
|
||||
|
||||
$query->select('iso_code');
|
||||
$query->where('active = ' . true);
|
||||
|
||||
$isoCodes = [];
|
||||
foreach ($this->db->executeS($query) as $country) {
|
||||
$isoCodes[] = $country['iso_code'];
|
||||
}
|
||||
|
||||
return $isoCodes;
|
||||
}
|
||||
|
||||
public function getShopDefaultCountry(): array
|
||||
{
|
||||
return [
|
||||
'name' => Country::getNameById($this->context->language->id, $this->configurationAdapter->get('PS_COUNTRY_DEFAULT')),
|
||||
'iso_code' => Country::getIsoById($this->configurationAdapter->get('PS_COUNTRY_DEFAULT')),
|
||||
];
|
||||
}
|
||||
|
||||
public function getIsoById(int $countryId)
|
||||
{
|
||||
return Country::getIsoById($countryId);
|
||||
}
|
||||
|
||||
public function getShopContactCountry(): array
|
||||
{
|
||||
if (empty($this->configurationAdapter->get('PS_SHOP_COUNTRY_ID'))) {
|
||||
return [
|
||||
'name' => null,
|
||||
'iso_code' => null,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'name' => Country::getNameById($this->context->language->id, $this->configurationAdapter->get('PS_SHOP_COUNTRY_ID')),
|
||||
'iso_code' => Country::getIsoById($this->configurationAdapter->get('PS_SHOP_COUNTRY_ID')),
|
||||
];
|
||||
}
|
||||
|
||||
public function countryNeedState(int $countryId): bool
|
||||
{
|
||||
return Country::containsStates($this->configurationAdapter->get($countryId));
|
||||
}
|
||||
|
||||
/**
|
||||
* isCompatibleForCSS
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isCompatibleForCSS()
|
||||
{
|
||||
$availableCountries = [
|
||||
'BG',
|
||||
'BE',
|
||||
'CZ',
|
||||
'DK',
|
||||
'CY',
|
||||
'LV',
|
||||
'LT',
|
||||
'LU',
|
||||
'ES',
|
||||
'FR',
|
||||
'HR',
|
||||
'IT',
|
||||
'PL',
|
||||
'PT',
|
||||
'RO',
|
||||
'SI',
|
||||
'HU',
|
||||
'MT',
|
||||
'NL',
|
||||
'AT',
|
||||
'IS',
|
||||
'LI',
|
||||
'NO',
|
||||
'SK',
|
||||
'FI',
|
||||
'SE',
|
||||
'DE',
|
||||
'IE',
|
||||
'EL',
|
||||
'CH',
|
||||
'GB',
|
||||
];
|
||||
|
||||
return in_array($this->country->iso_code, $availableCountries);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Currency;
|
||||
|
||||
class CurrencyRepository
|
||||
{
|
||||
/**
|
||||
* @var Currency
|
||||
*/
|
||||
private $currency;
|
||||
|
||||
public function __construct(Currency $currency)
|
||||
{
|
||||
$this->currency = $currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get details about the currency associated to the shop context.
|
||||
* Don't return all the details about the currency, as they should be
|
||||
* available from another source (i.e CLDR json).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getShopCurrency(): array
|
||||
{
|
||||
return [
|
||||
'isoCode' => $this->currency->iso_code,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Language;
|
||||
|
||||
class LanguageRepository
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
public function getIsoById(int $id)
|
||||
{
|
||||
return Language::getIsoById($id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Context;
|
||||
use Module;
|
||||
use PrestaShop\Module\PsxMarketingWithGoogle\Config\Config;
|
||||
use PrestaShop\PrestaShop\Adapter\SymfonyContainer;
|
||||
|
||||
class ModuleRepository
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $moduleName;
|
||||
|
||||
public function __construct(string $moduleName)
|
||||
{
|
||||
$this->moduleName = $moduleName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getModuleVersion()
|
||||
{
|
||||
/** @var Module $module */
|
||||
$module = Module::getInstanceByName($this->moduleName);
|
||||
|
||||
if (!empty($module)) {
|
||||
return $module->version;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getUpgradeLink()
|
||||
{
|
||||
$router = SymfonyContainer::getInstance()->get('router');
|
||||
|
||||
return \Tools::getHttpHost(true) . $router->generate('admin_module_manage_action', [
|
||||
'action' => 'upgrade',
|
||||
'module_name' => $this->moduleName,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEnableLink()
|
||||
{
|
||||
$router = SymfonyContainer::getInstance()->get('router');
|
||||
|
||||
return \Tools::getHttpHost(true) . $router->generate('admin_module_manage_action', [
|
||||
'action' => 'enable',
|
||||
'module_name' => $this->moduleName,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getInformationsAboutModule(): array
|
||||
{
|
||||
return [
|
||||
'version' => $this->getModuleVersion(),
|
||||
'upgradeLink' => $this->getUpgradeLink(),
|
||||
'hooks' => $this->getActiveHooks(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function moduleIsEnabled(): bool
|
||||
{
|
||||
return Module::isEnabled($this->moduleName);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getActiveHooks(): array
|
||||
{
|
||||
$context = Context::getContext();
|
||||
$hooks = [];
|
||||
/** @var Module $moduleInstance */
|
||||
$moduleInstance = Module::getInstanceByName($this->moduleName);
|
||||
|
||||
if (empty($moduleInstance)) {
|
||||
return $hooks;
|
||||
}
|
||||
|
||||
foreach (Config::HOOK_LIST as $hook) {
|
||||
$hooks[$hook] = \Hook::isModuleRegisteredOnHook($moduleInstance, $hook, $context->shop->id);
|
||||
}
|
||||
|
||||
return $hooks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Db;
|
||||
use DbQuery;
|
||||
|
||||
class ProductRepository
|
||||
{
|
||||
public function getProductsTotal($shopId, array $options = [])
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
|
||||
$sql->select('COUNT(1) as total');
|
||||
$sql->from('product', 'p');
|
||||
|
||||
$sql->innerJoin('product_shop', 'ps', 'ps.id_product = p.id_product');
|
||||
if (isset($options['splitPerLangAndCombination'])) {
|
||||
$sql->innerJoin('product_lang', 'pl', 'pl.id_product = ps.id_product AND pl.id_shop = ps.id_shop');
|
||||
$sql->leftJoin('product_attribute_shop', 'pas', 'pas.id_product = ps.id_product AND pas.id_shop = ps.id_shop');
|
||||
}
|
||||
|
||||
$sql->where('ps.id_shop = ' . (int) $shopId);
|
||||
if (isset($options['onlyActive'])) {
|
||||
$sql->where('ps.active = 1');
|
||||
}
|
||||
|
||||
$res = Db::getInstance()->executeS($sql);
|
||||
|
||||
return $res[0]['total'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Db;
|
||||
use DbQuery;
|
||||
use PrestaShop\Module\PsxMarketingWithGoogle\Config\Config;
|
||||
|
||||
class ShopRepository
|
||||
{
|
||||
public function getShopDomainsAndConfiguration()
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
|
||||
$sql->select('su.`id_shop`, `domain`, `domain_ssl`, c.`value` as acces_token_value');
|
||||
|
||||
$sql->from('shop_url', 'su');
|
||||
$sql->leftJoin('configuration', 'c', 'su.id_shop = c.id_shop');
|
||||
|
||||
$sql->where('c.name LIKE "' . Config::PSX_MKTG_WITH_GOOGLE_ACCOUNT_IS_LINKED . '"');
|
||||
|
||||
return Db::getInstance()->executeS($sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Context;
|
||||
use Db;
|
||||
use DbQuery;
|
||||
|
||||
class StateRepository
|
||||
{
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
private $stateIsoCodeCache = [];
|
||||
|
||||
public function __construct(Db $db, Context $context)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
private function getBaseQuery(): DbQuery
|
||||
{
|
||||
$query = new DbQuery();
|
||||
|
||||
$query->from('state', 's');
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getStateIsoCodesByZoneId(int $zoneId, bool $active = true): array
|
||||
{
|
||||
$cacheKey = $zoneId . '-' . (int) $active;
|
||||
|
||||
if (!isset($this->stateIsoCodeCache[$cacheKey])) {
|
||||
$query = $this->getBaseQuery();
|
||||
|
||||
$query->select('s.iso_code');
|
||||
$query->innerJoin('country', 'c', 'c.id_country = s.id_country');
|
||||
$query->where('s.id_zone = ' . (int) $zoneId);
|
||||
$query->where('s.active = ' . (bool) $active);
|
||||
$query->where('c.active = ' . (bool) $active);
|
||||
|
||||
$isoCodes = [];
|
||||
foreach ($this->db->executeS($query) as $state) {
|
||||
$isoCodes[] = $state['iso_code'];
|
||||
}
|
||||
$this->stateIsoCodeCache[$cacheKey] = $isoCodes;
|
||||
}
|
||||
|
||||
return $this->stateIsoCodeCache[$cacheKey];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Db;
|
||||
use DbQuery;
|
||||
|
||||
class TabRepository
|
||||
{
|
||||
public function hasChildren(int $tabId): bool
|
||||
{
|
||||
$sql = new DbQuery();
|
||||
$sql->select('id_tab');
|
||||
$sql->from('tab');
|
||||
$sql->where('`id_parent` = "' . (int) $tabId . '"');
|
||||
|
||||
return (bool) Db::getInstance()->getValue($sql);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?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\Repository;
|
||||
|
||||
use Context;
|
||||
use Db;
|
||||
use DbQuery;
|
||||
|
||||
class TaxRepository
|
||||
{
|
||||
/**
|
||||
* @var Db
|
||||
*/
|
||||
private $db;
|
||||
|
||||
/**
|
||||
* @var Context
|
||||
*/
|
||||
private $context;
|
||||
|
||||
private $countryIsoCodeCache = [];
|
||||
|
||||
public function __construct(Db $db, Context $context)
|
||||
{
|
||||
$this->db = $db;
|
||||
$this->context = $context;
|
||||
}
|
||||
|
||||
private function getBaseQuery(): DbQuery
|
||||
{
|
||||
$query = new DbQuery();
|
||||
|
||||
$query->from('tax', 't')
|
||||
->innerJoin('tax_rule', 'tr', 'tr.id_tax = t.id_tax')
|
||||
->innerJoin('tax_rules_group', 'trg', 'trg.id_tax_rules_group = tr.id_tax_rules_group')
|
||||
->innerJoin('tax_rules_group_shop', 'trgs', 'trgs.id_tax_rules_group = tr.id_tax_rules_group')
|
||||
->innerJoin('tax_lang', 'tl', 'tl.id_tax = t.id_tax')
|
||||
->where('trgs.id_shop = ' . (int) $this->context->shop->id)
|
||||
->where('tl.id_lang = ' . (int) $this->context->language->id);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getCarrierTaxesByTaxRulesGroupId(int $taxRulesGroupId, bool $active = true): array
|
||||
{
|
||||
$cacheKey = (int) $taxRulesGroupId . '-' . (int) $active;
|
||||
|
||||
if (!isset($this->countryIsoCodeCache[$cacheKey])) {
|
||||
$query = $this->getBaseQuery();
|
||||
|
||||
$query->select('rate, c.iso_code as country_iso_code, GROUP_CONCAT(s.iso_code SEPARATOR ",") as state_iso_code');
|
||||
$query->leftJoin('country', 'c', 'c.id_country = tr.id_country');
|
||||
$query->leftJoin('state', 's', 's.id_state = tr.id_state');
|
||||
$query->where('tr.id_tax_rules_group = ' . (int) $taxRulesGroupId);
|
||||
$query->where('c.active = ' . (bool) $active);
|
||||
$query->where('s.active = ' . (bool) $active . ' OR s.active IS NULL');
|
||||
$query->where('t.active = ' . (bool) $active);
|
||||
$query->where('c.iso_code IS NOT NULL');
|
||||
|
||||
$this->countryIsoCodeCache[$cacheKey] = $this->db->executeS($query);
|
||||
}
|
||||
|
||||
return $this->countryIsoCodeCache[$cacheKey];
|
||||
}
|
||||
}
|
||||
11
modules/psxmarketingwithgoogle/classes/Repository/index.php
Normal file
11
modules/psxmarketingwithgoogle/classes/Repository/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