first commit

This commit is contained in:
2024-11-05 12:22:50 +01:00
commit e5682a3912
19641 changed files with 2948548 additions and 0 deletions

View File

@@ -0,0 +1,368 @@
<?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\PrestashopFacebook\Repository;
use Db;
use DbQuery;
use PrestaShop\Module\PrestashopFacebook\Adapter\ConfigurationAdapter;
use PrestaShop\Module\PrestashopFacebook\Config\Config;
use PrestaShopCollection;
class GoogleCategoryRepository
{
public const NO_CHILDREN = 0;
public const HAS_CHILDREN = 1;
/**
* @var int
*/
private $homeCategoryId;
public function __construct(ConfigurationAdapter $configurationAdapter)
{
$this->homeCategoryId = (int) $configurationAdapter->get('PS_HOME_CATEGORY');
}
/**
* @param int $categoryId
* @param int $googleCategoryId
* @param string $googleCategoryName
* @param int $googleCategoryParentId
* @param string $googleCategoryParentName
* @param int $shopId
* @param bool $isParentCategory
*
* @throws \PrestaShopDatabaseException
*/
public function updateCategoryMatch(
$categoryId,
$googleCategoryId,
$googleCategoryName,
$googleCategoryParentId,
$googleCategoryParentName,
$shopId,
$isParentCategory = false
) {
Db::getInstance()->insert(
'fb_category_match',
[
'id_category' => (int) $categoryId,
'google_category_id' => (int) $googleCategoryId,
'google_category_name' => pSQL($googleCategoryName),
'google_category_parent_id' => (int) $googleCategoryParentId,
'google_category_parent_name' => pSQL($googleCategoryParentName),
'is_parent_category' => $isParentCategory,
'id_shop' => (int) $shopId,
],
false,
true,
DB::REPLACE
);
}
/**
* @param PrestaShopCollection $childCategories
* @param int $googleCategoryId
* @param string $googleCategoryName
* @param int $googleCategoryParentId
* @param string $googleCategoryParentName
* @param int $shopId
*
* @throws \PrestaShopDatabaseException
*/
public function updateCategoryChildrenMatch(
PrestaShopCollection $childCategories,
$googleCategoryId,
$googleCategoryName,
$googleCategoryParentId,
$googleCategoryParentName,
$shopId
) {
$data = [];
foreach ($childCategories as $category) {
$data[] = [
'id_category' => (int) $category->id,
'google_category_id' => (int) $googleCategoryId,
'google_category_name' => pSQL($googleCategoryName),
'google_category_parent_id' => (int) $googleCategoryParentId,
'google_category_parent_name' => pSQL($googleCategoryParentName),
'is_parent_category' => 1,
'id_shop' => (int) $shopId,
];
}
Db::getInstance()->insert(
'fb_category_match',
$data,
false,
true,
DB::REPLACE
);
}
/**
* @param int $categoryId
* @param int $shopId
*
* @throws \PrestaShopDatabaseException
*/
public function unsetCategoryMatch(
$categoryId,
$shopId
) {
Db::getInstance()->delete(
'fb_category_match',
'`id_category` = ' . (int) $categoryId . ' AND `id_shop` = ' . (int) $shopId
);
}
/**
* @param PrestaShopCollection $childCategories
* @param int $shopId
*
* @throws \PrestaShopDatabaseException
*/
public function unsetCategoryChildrenMatch(
PrestaShopCollection $childCategories,
$shopId
) {
foreach ($childCategories as $category) {
$this->unsetCategoryMatch($category->id, $shopId);
}
}
/**
* @param int $categoryId
* @param int $shopId
*
* @return int
*/
public function getGoogleCategoryIdByCategoryId($categoryId, $shopId)
{
$sql = new DbQuery();
$sql->select('google_category_id');
$sql->from('fb_category_match');
$sql->where('`id_category` = "' . (int) $categoryId . '"');
$sql->where('id_shop = ' . (int) $shopId);
return (int) Db::getInstance()->getValue($sql);
}
/**
* @param int $categoryId
* @param int $shopId
*
* @return array|false
*/
public function getCategoryMatchByCategoryId($categoryId, $shopId)
{
$sql = new DbQuery();
$sql->select('id_category');
$sql->select('google_category_id');
$sql->select('google_category_name');
$sql->select('google_category_parent_id');
$sql->select('google_category_parent_name');
$sql->select('is_parent_category');
$sql->from('fb_category_match');
$sql->where('`id_category` = "' . (int) $categoryId . '"');
$sql->where('id_shop = ' . (int) $shopId);
return Db::getInstance()->getRow($sql);
}
/**
* @param array $categoryIds
* @param int $shopId
*
* @return array|false
*
* @throws \PrestaShopDatabaseException
*/
public function getGoogleCategoryIdsByCategoryIds(array $categoryIds, $shopId)
{
$sql = new DbQuery();
$sql->select('google_category_id');
$sql->from('fb_category_match');
$sql->where('`id_category` IN ("' . implode('", "', $categoryIds) . '")');
$sql->where('id_shop = ' . (int) $shopId);
return Db::getInstance()->executeS($sql);
}
/**
* @param array $categoryIds
* @param int $shopId
*
* @return array|false
*
* @throws \PrestaShopDatabaseException
*/
public function getCategoryMatchesByCategoryIds(array $categoryIds, $shopId)
{
$sql = new DbQuery();
$sql->select('id_category');
$sql->select('google_category_id');
$sql->select('google_category_parent_id');
$sql->select('is_parent_category');
$sql->from('fb_category_match');
$sql->where('`id_category` IN ("' . implode('", "', $categoryIds) . '")');
$sql->where('id_shop = ' . (int) $shopId);
return Db::getInstance()->executeS($sql);
}
public function getFilteredCategories($parentCategoryId, $langId, $offset, $limit, $shopId)
{
$sql = new DbQuery();
$sql->select('c.id_category as shopCategoryId');
$sql->select('cl.name as shopCategoryName');
$sql->select('cm.google_category_id as googleCategoryId');
$sql->select('cm.google_category_name as googleCategoryName');
$sql->select('cm.google_category_parent_id as googleCategoryParentId');
$sql->select('cm.google_category_parent_name as googleCategoryParentName');
$sql->select('cm.is_parent_category as isParentCategory');
$sql->select('case when c.nleft = c.nright -1 and c.`level_depth` = ' . Config::MAX_CATEGORY_DEPTH .
' then ' . self::NO_CHILDREN . ' else ' . self::HAS_CHILDREN . ' end deploy');
$sql->from('category', 'c');
$sql->innerJoin('category_shop', 'cs', 'cs.id_category = c.id_category');
$sql->innerJoin('category_lang', 'cl', 'c.id_category = cl.id_category AND cl.id_lang = ' . (int) $langId);
$sql->leftJoin(
'fb_category_match',
'cm',
'cm.id_category = c.id_category AND cm.id_shop = ' . (int) $shopId
);
$sql->where('cs.id_shop = ' . (int) $shopId);
$sql->where(
'c.`id_parent` = ' . (int) $parentCategoryId . ' OR
(
c.`nleft` > (SELECT pc.`nleft` from `' . _DB_PREFIX_ . 'category` as pc WHERE pc.id_category = '
. (int) $parentCategoryId . ' AND pc.`level_depth` >= ' . Config::MAX_CATEGORY_DEPTH . ') AND
c.`nright` < (SELECT pc.`nright` from `' . _DB_PREFIX_ . 'category` as pc WHERE pc.id_category = '
. (int) $parentCategoryId . ' AND pc.`level_depth` >= ' . Config::MAX_CATEGORY_DEPTH . ')
)'
);
$sql->groupBy('c.id_category');
$sql->limit($limit, $offset);
return Db::getInstance()->executeS($sql);
}
/**
* @param int $shopId
*
* @return bool
*
* @throws \PrestaShopDatabaseException
*/
public function areParentCategoriesMatched($shopId)
{
$sql = new DbQuery();
$sql->select('c.id_category');
$sql->from('category', 'c');
$sql->innerJoin('category_shop', 'cs', 'cs.id_category = c.id_category');
$sql->leftJoin('fb_category_match', 'cm', 'cm.id_category = c.id_category AND cm.id_shop = cs.id_shop');
$sql->where("c.id_parent = {$this->homeCategoryId} AND cm.google_category_id IS NULL");
$sql->where('cs.id_shop = ' . (int) $shopId);
return (bool) Db::getInstance()->executeS($sql);
}
/**
* @param int $langId
* @param int $shopId
*
* @return array
*
* @throws \PrestaShopDatabaseException
*/
public function getCategoriesWithParentInfo($langId, $shopId)
{
$query = new DbQuery();
$query->select('c.id_category, cl.name, c.id_parent')
->from('category', 'c')
->leftJoin(
'category_lang',
'cl',
'cl.id_category = c.id_category AND cl.id_shop = ' . (int) $shopId
)
->where('cl.id_lang = ' . (int) $langId)
->orderBy('cl.id_category');
$result = Db::getInstance()->executeS($query);
if ($result) {
return $result;
} else {
throw new \PrestaShopDatabaseException('No categories found');
}
}
/**
* @param int $shopId
*
* @return bool
*
* @throws \PrestaShopDatabaseException
*/
public function isMatchingDone($shopId)
{
$sql = new DbQuery();
$sql->select('cm.id_category');
$sql->from('fb_category_match', 'cm');
$sql->where('cm.id_shop = ' . (int) $shopId);
return (bool) Db::getInstance()->executeS($sql);
}
/**
* @param int $shopId
*
* @return int
*/
public function getNumberOfMatchedCategories($shopId)
{
$sql = new DbQuery();
$sql->select('cm.id_category');
$sql->from('fb_category_match', 'cm');
$sql->where('cm.id_shop = ' . (int) $shopId);
Db::getInstance()->execute($sql);
return Db::getInstance()->numRows();
}
/**
* @param int $shopId
*
* @return int
*/
public function getNumberOfTotalCategories($shopId)
{
$sql = new DbQuery();
$sql->select('c.id_category');
$sql->from('category', 'c');
$sql->innerJoin('category_shop', 'cp', 'cp.id_category = c.id_category');
$sql->where('cp.id_shop = ' . (int) $shopId . ' AND c.id_parent >=' . (int) $this->homeCategoryId);
Db::getInstance()->execute($sql);
return Db::getInstance()->numRows();
}
}

View File

@@ -0,0 +1,359 @@
<?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\PrestashopFacebook\Repository;
use Db;
use DbQuery;
use PrestaShop\Module\PrestashopFacebook\Config\Config;
use PrestaShop\Module\PrestashopFacebook\DTO\EventBusProduct;
use PrestaShop\Module\Ps_facebook\Utility\ProductCatalogUtility;
use PrestaShopException;
use Product;
class ProductRepository
{
/**
* @var \Language
*/
private $language;
public function __construct(\Language $language)
{
$this->language = $language;
}
/**
* Copy of prestashop Product::getIdProductAttributeByIdAttributes function
* because old PS versions are missing this function
*
* Get an id_product_attribute by an id_product and one or more
* id_attribute.
*
* e.g: id_product 8 with id_attribute 4 (size medium) and
* id_attribute 5 (color blue) returns id_product_attribute 9 which
* is the dress size medium and color blue.
*
* @param int $idProduct
* @param int|int[] $idAttributes
* @param bool $findBest
*
* @return int
*
* @throws PrestaShopException
*/
public function getIdProductAttributeByIdAttributes($idProduct, $idAttributes, $findBest = false)
{
$idProduct = (int) $idProduct;
if (!is_array($idAttributes) && is_numeric($idAttributes)) {
$idAttributes = [(int) $idAttributes];
}
if (!is_array($idAttributes) || empty($idAttributes)) {
throw new PrestaShopException(sprintf('Invalid parameter $idAttributes with value: "%s"', print_r($idAttributes, true)));
}
$idAttributesImploded = implode(',', array_map('intval', $idAttributes));
$idProductAttribute = Db::getInstance()->getValue(
'
SELECT
pac.`id_product_attribute`
FROM
`' . _DB_PREFIX_ . 'product_attribute_combination` pac
INNER JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
WHERE
pa.id_product = ' . $idProduct . '
AND pac.id_attribute IN (' . $idAttributesImploded . ')
GROUP BY
pac.`id_product_attribute`
HAVING
COUNT(pa.id_product) = ' . count($idAttributes)
);
if ($idProductAttribute === false && $findBest) {
//find the best possible combination
//first we order $idAttributes by the group position
$orderred = [];
$result = Db::getInstance()->executeS(
'
SELECT
a.`id_attribute`
FROM
`' . _DB_PREFIX_ . 'attribute` a
INNER JOIN `' . _DB_PREFIX_ . 'attribute_group` g ON a.`id_attribute_group` = g.`id_attribute_group`
WHERE
a.`id_attribute` IN (' . $idAttributesImploded . ')
ORDER BY
g.`position` ASC'
);
foreach ($result as $row) {
$orderred[] = $row['id_attribute'];
}
while ($idProductAttribute === false && count($orderred) > 0) {
array_pop($orderred);
$idProductAttribute = Db::getInstance()->getValue(
'
SELECT
pac.`id_product_attribute`
FROM
`' . _DB_PREFIX_ . 'product_attribute_combination` pac
INNER JOIN `' . _DB_PREFIX_ . 'product_attribute` pa ON pa.id_product_attribute = pac.id_product_attribute
WHERE
pa.id_product = ' . (int) $idProduct . '
AND pac.id_attribute IN (' . implode(',', array_map('intval', $orderred)) . ')
GROUP BY
pac.id_product_attribute
HAVING
COUNT(pa.id_product) = ' . count($orderred)
);
}
}
if (empty($idProductAttribute)) {
throw new PrestaShopException('Can not retrieve the id_product_attribute');
}
return (int) $idProductAttribute;
}
public function getProductsWithErrors($shopId, $page = -1)
{
$sql = new DbQuery();
$sql->select('ps.id_product');
$sql->select('IF(pas.id_product_attribute IS NULL, 0, id_product_attribute) as id_product_attribute');
$sql->from('product', 'p');
$sql->innerJoin('product_shop', 'ps', 'ps.id_product = p.id_product');
$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 . ' AND ps.active = 1');
$result = Db::getInstance()->executeS($sql);
$productIdsWithInvalidSalePrice = [0];
$productAttributeIdsWithInvalidSalePrice = [0];
foreach ($result as $product) {
$salePriceTaxExcluded = $this->getSalePriceTaxExcluded($product['id_product'], $product['id_product_attribute']);
if ($salePriceTaxExcluded <= 0) {
$productIdsWithInvalidSalePrice[] = $product['id_product'];
$productAttributeIdsWithInvalidSalePrice[] = $product['id_product_attribute'];
}
}
$sql = new DbQuery();
$sql->select('ps.id_product, pas.id_product_attribute, pl.name');
$sql->select('pl.id_lang, l.iso_code as language');
$sql->select('
IF((m.name = "" OR m.name IS NULL) AND p.ean13 = "" AND p.upc = "" AND p.isbn = "", false, true) as has_manufacturer_or_ean_or_upc_or_isbn
');
$sql->select('IF(is.id_image IS NOT NULL, true, false) as has_cover');
$sql->select('IF(pl.link_rewrite = "" OR pl.link_rewrite is NULL, false, true) as has_link');
$sql->select('IF(ps.price + IFNULL(pas.price, 0) > 0, true, false) as has_price_tax_excl');
$sql->select('IF((pl.description_short = "" OR pl.description_short IS NULL) AND (pl.description = "" OR pl.description IS NULL), false, true) as has_description_or_short_description');
$sql->select('true as correct_sales_price');
$sql->from('product', 'p');
$sql->innerJoin('product_shop', 'ps', 'ps.id_product = p.id_product');
$sql->innerJoin('product_lang', 'pl', 'pl.id_product = ps.id_product AND pl.id_shop = ps.id_shop');
$sql->innerJoin('lang', 'l', 'l.id_lang = pl.id_lang');
$sql->leftJoin('product_attribute_shop', 'pas', 'pas.id_product = ps.id_product AND pas.id_shop = ps.id_shop');
$sql->leftJoin('manufacturer', 'm', 'm.id_manufacturer = p.id_manufacturer');
$sql->leftJoin('image_shop', 'is', 'is.id_product = ps.id_product AND is.id_shop = ps.id_shop AND is.cover = 1');
$sql->where('ps.id_shop = ' . (int) $shopId . ' AND ps.active = 1');
$sql->where('
(m.name = "" OR m.name IS NULL) AND p.ean13 = "" AND p.upc = "" AND p.isbn = ""
OR ((pl.description_short = "" OR pl.description_short IS NULL) AND (pl.description = "" OR pl.description IS NULL))
OR is.id_image is NULL
OR pl.link_rewrite = "" OR pl.link_rewrite is NULL
OR ps.price + IFNULL(pas.price, 0) <= 0
OR pl.name = "" OR pl.name is NULL
OR
(
ps.id_product in (' . implode(',', $productIdsWithInvalidSalePrice) . ') AND
(
pas.id_product_attribute in (' . implode(',', $productAttributeIdsWithInvalidSalePrice) . ') OR
pas.id_product_attribute IS NULL
)
)
');
$sql->orderBy('p.id_product ASC, pas.id_product_attribute ASC, language ASC');
if ($page > -1) {
$sql->limit(Config::REPORTS_PER_PAGE, Config::REPORTS_PER_PAGE * ($page));
}
$result = Db::getInstance()->executeS($sql);
foreach ($result as $key => &$value) {
if (!in_array($value['id_product'], $productIdsWithInvalidSalePrice)) {
continue;
}
if (in_array($value['id_product_attribute'], $productAttributeIdsWithInvalidSalePrice)
|| $value['id_product_attribute'] === null) {
$value['correct_sales_price'] = false;
}
}
return $result;
}
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');
$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'];
}
/**
* @param EventBusProduct $eventBusProduct
* @param int $shopId
* @param string $isoCode
*
* @return array|bool|\mysqli_result|\PDOStatement|resource|null
*
* @throws \PrestaShopDatabaseException
*/
public function getInformationAboutEventBusProduct(EventBusProduct $eventBusProduct, $shopId, $isoCode)
{
$sql = new DbQuery();
$sql->select('pa.id_product, pa.id_product_attribute, pl.name');
$sql->select('l.iso_code');
$sql->from('product_attribute', 'pa');
$sql->innerJoin('lang', 'l', 'l.iso_code = "' . pSQL($isoCode) . '"');
$sql->innerJoin('product_lang', 'pl', 'pl.id_product = pa.id_product AND pl.id_lang = l.id_lang');
$sql->where('pa.id_product = ' . (int) $eventBusProduct->getProductId());
$sql->where('pa.id_product_attribute = ' . (int) $eventBusProduct->getProductAttributeId());
$sql->where('pl.id_shop = ' . (int) $shopId);
return Db::getInstance()->executeS($sql);
}
/**
* @param string $syncUpdateDate
* @param int $shopId
* @param array $productsWithErrors
* @param int|false $page
* @param string|null $status
* @param string|null $sortBy
* @param string $sortTo
* @param int|bool $searchById
* @param string|bool $searchByName
* @param string|bool $searchByMessage
*
* @return array|bool|\mysqli_result|\PDOStatement|resource|null
*
* @throws \PrestaShopDatabaseException
*/
public function getInformationAboutEventBusProducts(
$syncUpdateDate,
$shopId,
$productsWithErrors,
$page = false,
$status = null,
$sortBy = null,
$sortTo = 'ASC',
$searchById = false,
$searchByName = false,
$searchByMessage = false
) {
$sql = new DbQuery();
$sql->select('ps.id_product, pa.id_product_attribute, pl.name, ps.date_upd');
$sql->select('
IF(CONCAT_WS("-", ps.id_product, IFNULL(pa.id_product_attribute, "0")) IN ( "' . implode('","', $productsWithErrors) . '"), "disapproved",
IF(ps.date_upd <= "' . pSQL($syncUpdateDate) . '", "approved", "pending" )
) as status
');
$sql->from('product_shop', 'ps');
$sql->leftJoin('product_attribute', 'pa', 'pa.id_product = ps.id_product');
$sql->innerJoin('product_lang', 'pl', 'pl.id_product = ps.id_product');
$sql->where('pl.id_shop = ' . (int) $shopId);
$sql->where('CONCAT_WS("-", ps.id_product, IFNULL(pa.id_product_attribute, 0)) IN ( "' . implode('","', $productsWithErrors) . '")');
// GROUP BY Id product AND ID combination of attributes
$sql->groupBy('ps.id_product');
$sql->groupBy('pa.id_product_attribute');
if ($page !== false) {
$sql->limit(Config::REPORTS_PER_PAGE, Config::REPORTS_PER_PAGE * ($page - 1));
}
if ($sortBy) {
$sql->orderBy(pSQL($sortBy) . ' ' . pSQL($sortTo));
}
if ($searchById) {
$sql->where('ps.id_product LIKE "%' . (int) $searchById . '%"');
}
if ($searchByName) {
$sql->where('pl.name LIKE "%' . pSQL($searchByName) . '%"');
}
if ($searchByMessage) {
$sql->where('ps.id_product LIKE "%' . (int) $searchByMessage . '%"');
}
if ($status) {
$sql->having('ps.id_product LIKE "%' . pSQL($status) . '%"');
}
$result = Db::getInstance()->executeS($sql);
$products = [];
foreach ($result as $product) {
$eventBusProductId = ProductCatalogUtility::makeProductId(
$product['id_product'],
$product['id_product_attribute']
);
$products[$eventBusProductId] = $product;
}
return $products;
}
/**
* @param int $productId
* @param int $attributeId
*
* @return float
*/
public function getSalePriceTaxExcluded($productId, $attributeId)
{
return Product::getPriceStatic($productId, false, $attributeId, 6);
}
}

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\PrestashopFacebook\Repository;
use Exception;
use PrestaShop\Module\PrestashopFacebook\Config\Config;
use PrestaShop\PsAccountsInstaller\Installer\Facade\PsAccounts;
class ServerInformationRepository
{
/**
* @var bool
*/
private $isPsAccountsOnboarded;
public function __construct(PsAccounts $psAccountsFacade)
{
try {
$this->isPsAccountsOnboarded = (bool) $psAccountsFacade->getPsAccountsService()->getOrRefreshToken();
} catch (Exception $e) {
$this->isPsAccountsOnboarded = false;
}
}
/**
* @return array
*/
public function getHealthCheckData()
{
$isFacebookSystemTokenSet = false;
if (\Configuration::get(Config::PS_FACEBOOK_SYSTEM_ACCESS_TOKEN)) {
$isFacebookSystemTokenSet = true;
}
return [
'ps_accounts' => \Module::isInstalled('ps_accounts'),
'ps_accounts_onboarded' => $this->isPsAccountsOnboarded,
'ps_eventbus' => \Module::isInstalled('ps_eventbus'),
'ps_facebook_system_token_set' => $isFacebookSystemTokenSet,
'pixel_enabled' => (bool) \Configuration::get(Config::PS_FACEBOOK_PIXEL_ENABLED),
'pixel_id' => (bool) \Configuration::get(Config::PS_PIXEL_ID),
'profile_id' => (bool) \Configuration::get(Config::PS_FACEBOOK_PROFILES),
'page_id' => (bool) \Configuration::get(Config::PS_FACEBOOK_PAGES),
'business_manager_id' => (bool) \Configuration::get(Config::PS_FACEBOOK_BUSINESS_MANAGER_ID),
'ad_account_id' => (bool) \Configuration::get(Config::PS_FACEBOOK_AD_ACCOUNT_ID),
'catalog_id' => (bool) \Configuration::get(Config::PS_FACEBOOK_CATALOG_ID),
'env' => [
'PSX_FACEBOOK_API_URL' => isset($_ENV['PSX_FACEBOOK_API_URL']) ? $_ENV['PSX_FACEBOOK_API_URL'] : null,
'ACCOUNTS_SVC_API_URL' => isset($_ENV['ACCOUNTS_SVC_API_URL']) ? $_ENV['ACCOUNTS_SVC_API_URL'] : null,
'EVENT_BUS_PROXY_API_URL' => isset($_ENV['EVENT_BUS_PROXY_API_URL']) ? $_ENV['EVENT_BUS_PROXY_API_URL'] : null,
'EVENT_BUS_SYNC_API_URL' => isset($_ENV['EVENT_BUS_SYNC_API_URL']) ? $_ENV['EVENT_BUS_SYNC_API_URL'] : null,
],
];
}
}

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\PrestashopFacebook\Repository;
use Db;
use DbQuery;
use PrestaShop\Module\PrestashopFacebook\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::PS_FACEBOOK_USER_ACCESS_TOKEN . '"');
return Db::getInstance()->executeS($sql);
}
public function getDefaultCategoryShop()
{
$sql = new DbQuery();
$sql->select('id_category');
$sql->from('shop');
return Db::getInstance()->executeS($sql)[0];
}
}

View File

@@ -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\PrestashopFacebook\Repository;
use Db;
use DbQuery;
class TabRepository
{
public function hasChildren($tabId)
{
$sql = new DbQuery();
$sql->select('id_tab');
$sql->from('tab');
$sql->where('`id_parent` = "' . (int) $tabId . '"');
return (bool) Db::getInstance()->getValue($sql);
}
}

View File

@@ -0,0 +1,28 @@
<?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
*/
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;