2016-01-13 18:43:41 +03:00
|
|
|
|
<?php
|
2020-04-16 15:26:03 +03:00
|
|
|
|
/**
|
|
|
|
|
* MIT License
|
|
|
|
|
*
|
2021-12-06 14:37:43 +03:00
|
|
|
|
* Copyright (c) 2021 DIGITAL RETAIL TECHNOLOGIES SL
|
2020-04-16 15:26:03 +03:00
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
|
* SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
* DISCLAIMER
|
|
|
|
|
*
|
|
|
|
|
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
|
|
|
|
|
* versions in the future. If you wish to customize PrestaShop for your
|
|
|
|
|
* needs please refer to http://www.prestashop.com for more information.
|
|
|
|
|
*
|
2021-12-06 14:37:43 +03:00
|
|
|
|
* @author DIGITAL RETAIL TECHNOLOGIES SL <mail@simlachat.com>
|
|
|
|
|
* @copyright 2021 DIGITAL RETAIL TECHNOLOGIES SL
|
|
|
|
|
* @license https://opensource.org/licenses/MIT The MIT License
|
2020-04-16 15:26:03 +03:00
|
|
|
|
*
|
|
|
|
|
* Don't forget to prefix your containers with your own identifier
|
|
|
|
|
* to avoid any conflicts with others containers.
|
|
|
|
|
*/
|
2021-12-06 14:37:43 +03:00
|
|
|
|
|
2016-01-13 18:43:41 +03:00
|
|
|
|
class RetailcrmCatalog
|
|
|
|
|
{
|
2018-05-28 17:09:31 +03:00
|
|
|
|
public $default_lang;
|
|
|
|
|
public $default_currency;
|
|
|
|
|
public $default_country;
|
2020-12-28 14:51:01 +03:00
|
|
|
|
public $protocol;
|
|
|
|
|
public $version;
|
|
|
|
|
public $link;
|
|
|
|
|
public $home_category;
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$this->default_lang = (int) Configuration::get('PS_LANG_DEFAULT');
|
|
|
|
|
$this->default_currency = (int) Configuration::get('PS_CURRENCY_DEFAULT');
|
|
|
|
|
$this->default_country = (int) Configuration::get('PS_COUNTRY_DEFAULT');
|
2020-12-28 14:51:01 +03:00
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$this->protocol = (Configuration::get('PS_SSL_ENABLED')) ? 'https://' : 'http://';
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$this->version = substr(_PS_VERSION_, 0, 3);
|
|
|
|
|
$this->link = new Link();
|
|
|
|
|
$this->home_category = Configuration::get('PS_HOME_CATEGORY');
|
2021-12-22 11:45:31 +03:00
|
|
|
|
|
|
|
|
|
if (null === Context::getContext()->currency) {
|
|
|
|
|
if ($this->default_currency) {
|
|
|
|
|
$currency = new Currency($this->default_currency);
|
|
|
|
|
Context::getContext()->currency = $currency;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getData()
|
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
|
return [$this->getCategories(), $this->getOffers()];
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getCategories()
|
|
|
|
|
{
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$categories = [];
|
|
|
|
|
$categoriesIds = [];
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$types = Category::getCategories($this->default_lang, true, false);
|
2018-12-25 13:31:07 +03:00
|
|
|
|
|
|
|
|
|
foreach ($types as $category) {
|
2020-04-20 15:29:38 +03:00
|
|
|
|
$categoryId = (empty($category['id_category']) && isset($category['id']))
|
|
|
|
|
? $category['id'] : $category['id_category'];
|
|
|
|
|
|
|
|
|
|
if (!self::isCategoryActive(new Category($categoryId))) {
|
2020-04-16 15:26:03 +03:00
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$picture = $this->link->getCatImageLink($category['link_rewrite'], $categoryId, 'category_default');
|
2018-12-25 13:31:07 +03:00
|
|
|
|
|
2020-04-20 15:29:38 +03:00
|
|
|
|
$categoriesIds[] = $categoryId;
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$categories[] = [
|
2020-04-20 15:29:38 +03:00
|
|
|
|
'id' => $categoryId,
|
2020-11-12 13:57:54 +03:00
|
|
|
|
'parentId' => self::getParentCategoryId($categoryId, $category['id_parent']),
|
2020-12-28 14:51:01 +03:00
|
|
|
|
'name' => htmlspecialchars($category['name']),
|
2021-11-03 16:19:39 +07:00
|
|
|
|
'picture' => $picture ? $this->protocol . $picture : '',
|
|
|
|
|
];
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-20 15:29:38 +03:00
|
|
|
|
foreach ($categories as $key => $innerCategory) {
|
|
|
|
|
if (isset($innerCategory['parentId'])
|
|
|
|
|
&& !empty($innerCategory['parentId'])
|
|
|
|
|
&& !in_array($innerCategory['parentId'], $categoriesIds)
|
|
|
|
|
) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$innerCategory['parentId'] = $this->home_category;
|
2020-04-20 15:29:38 +03:00
|
|
|
|
$categories[$key] = $innerCategory;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
return $categories;
|
|
|
|
|
}
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
public function getOffers()
|
|
|
|
|
{
|
2021-07-27 13:25:44 +03:00
|
|
|
|
$productsCount = 0;
|
|
|
|
|
$offersCount = 0;
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$id_lang = $this->default_lang;
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2021-07-29 20:37:35 +07:00
|
|
|
|
$inactiveCategories = [];
|
|
|
|
|
$categoriesIds = [];
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$types = Category::getCategories($id_lang, true, false);
|
2020-04-16 15:26:03 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
foreach ($types as $category) {
|
|
|
|
|
$categoryId = (empty($category['id_category']) && isset($category['id']))
|
|
|
|
|
? $category['id'] : $category['id_category'];
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (!self::isCategoryActive(new Category($categoryId))) {
|
|
|
|
|
if (!in_array($categoryId, $inactiveCategories)) {
|
|
|
|
|
$inactiveCategories[] = $categoryId;
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 15:26:03 +03:00
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-12-25 13:31:07 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$categoriesIds[] = $categoryId;
|
|
|
|
|
}
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$limit = 2000;
|
|
|
|
|
$start = 0;
|
|
|
|
|
$count = self::getProductsCount($id_lang);
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if (0 < $count) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
do {
|
|
|
|
|
$products = Product::getProducts($id_lang, $start, $limit, 'name', 'asc');
|
2016-01-13 18:43:41 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
foreach ($products as $product) {
|
|
|
|
|
$currentProductCategories = Product::getProductCategories($product['id_product']);
|
|
|
|
|
$categoriesLeft = array_filter(
|
|
|
|
|
$currentProductCategories,
|
2022-06-17 11:29:53 +03:00
|
|
|
|
function ($val) use ($inactiveCategories, $categoriesIds) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (in_array($val, $inactiveCategories)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-08-29 15:59:19 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
return in_array($val, $categoriesIds);
|
|
|
|
|
}
|
|
|
|
|
);
|
2018-10-05 17:50:20 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (empty($categoriesLeft)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2021-11-03 16:19:39 +07:00
|
|
|
|
++$productsCount;
|
2018-12-25 13:31:07 +03:00
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if ('1.3' == $this->version) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$available_for_order = $product['active'] && $product['quantity'];
|
|
|
|
|
} else {
|
|
|
|
|
$available_for_order = $product['active'] && $product['available_for_order'];
|
2017-03-21 12:46:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$crewrite = Category::getLinkRewrite($product['id_category_default'], $id_lang);
|
|
|
|
|
$url = $this->link->getProductLink($product['id_product'], $product['link_rewrite'], $crewrite);
|
2018-12-25 13:31:07 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (!empty($product['wholesale_price'])) {
|
|
|
|
|
$purchasePrice = round($product['wholesale_price'], 2);
|
|
|
|
|
} else {
|
|
|
|
|
$purchasePrice = null;
|
2016-08-29 15:59:19 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$price = !empty($product['rate'])
|
|
|
|
|
? round($product['price'], 2) + (round($product['price'], 2) * $product['rate'] / 100)
|
|
|
|
|
: round($product['price'], 2);
|
2018-12-25 13:31:07 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (!empty($product['manufacturer_name'])) {
|
|
|
|
|
$vendor = $product['manufacturer_name'];
|
2016-01-13 18:43:41 +03:00
|
|
|
|
} else {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$vendor = null;
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
2016-08-29 15:59:19 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (!empty($product['reference'])) {
|
|
|
|
|
$article = htmlspecialchars($product['reference']);
|
|
|
|
|
} else {
|
|
|
|
|
$article = null;
|
|
|
|
|
}
|
2019-08-21 15:02:23 +03:00
|
|
|
|
|
2022-09-30 12:35:55 +03:00
|
|
|
|
$productName = htmlspecialchars(strip_tags($product['name']));
|
|
|
|
|
|
2021-11-23 20:54:55 +07:00
|
|
|
|
$weight = $this->getWeightInKg($product['weight']);
|
2020-05-20 13:39:18 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$width = round($product['width'], 3);
|
|
|
|
|
$height = round($product['height'], 3);
|
|
|
|
|
$depth = round($product['depth'], 3);
|
2016-08-29 15:59:19 +03:00
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if (0.0 !== $width && 0.0 !== $height) {
|
|
|
|
|
$dimensions = implode('/', [$depth, $width, $height]);
|
2019-08-21 15:02:23 +03:00
|
|
|
|
} else {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$dimensions = null;
|
2019-08-21 15:02:23 +03:00
|
|
|
|
}
|
|
|
|
|
|
2024-05-13 09:36:16 +03:00
|
|
|
|
$useServices = RetailcrmTools::isIcmlServicesEnabled()
|
|
|
|
|
&& !empty($product['is_virtual'])
|
|
|
|
|
&& empty($product['uploadable_files']);
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$offers = Product::getProductAttributesIds($product['id_product']);
|
2023-09-01 17:17:24 +03:00
|
|
|
|
$features = Product::getFrontFeaturesStatic($id_lang, $product['id_product']);
|
2020-12-28 14:51:01 +03:00
|
|
|
|
|
|
|
|
|
if (!empty($offers)) {
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$offersCount += count($offers);
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$productForCombination = new Product($product['id_product']);
|
|
|
|
|
|
|
|
|
|
foreach ($offers as $offer) {
|
|
|
|
|
$combinations = $productForCombination->getAttributeCombinationsById($offer['id_product_attribute'], $id_lang);
|
|
|
|
|
|
|
|
|
|
if (!empty($combinations)) {
|
|
|
|
|
foreach ($combinations as $combination) {
|
2021-07-29 20:37:35 +07:00
|
|
|
|
$arSet = [
|
2020-12-28 14:51:01 +03:00
|
|
|
|
'group_name' => $combination['group_name'],
|
2021-10-18 17:52:16 +03:00
|
|
|
|
'id_attribute_group' => $combination['id_attribute_group'],
|
|
|
|
|
'attribute_name' => $combination['attribute_name'],
|
2021-07-29 20:37:35 +07:00
|
|
|
|
];
|
2020-12-28 14:51:01 +03:00
|
|
|
|
|
|
|
|
|
$arComb[] = $arSet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$covers = Image::getImages($id_lang, $product['id_product'], $offer['id_product_attribute']);
|
2021-07-29 20:37:35 +07:00
|
|
|
|
$pictures = $this->getPictures($covers, $product, true);
|
2020-12-28 14:51:01 +03:00
|
|
|
|
|
|
|
|
|
if (!$pictures) {
|
|
|
|
|
$image = Image::getCover($product['id_product']);
|
2022-06-09 13:21:53 +03:00
|
|
|
|
|
|
|
|
|
if (isset($image['id_image'])) {
|
|
|
|
|
$picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $image['id_image'], 'large_default');
|
|
|
|
|
$pictures[] = $picture;
|
|
|
|
|
}
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if ('1.3' == $this->version) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$quantity = $product['quantity'];
|
|
|
|
|
} else {
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$quantity = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product'], $offer['id_product_attribute']);
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$offerCombination = new Combination($offer['id_product_attribute']);
|
|
|
|
|
|
|
|
|
|
$offerCombinationPrice = !empty($product['rate'])
|
|
|
|
|
? round($offerCombination->price, 2) + (round($offerCombination->price, 2) * $product['rate'] / 100)
|
|
|
|
|
: round($offerCombination->price, 2);
|
|
|
|
|
|
|
|
|
|
$offerPrice = round($offerCombinationPrice, 2) + $price;
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$offerPrice = 0 < $offerPrice ? $offerPrice : $price;
|
2020-12-28 14:51:01 +03:00
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if (0 < $offerCombination->wholesale_price) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$offerPurchasePrice = round($offerCombination->wholesale_price, 2);
|
|
|
|
|
} else {
|
|
|
|
|
$offerPurchasePrice = $purchasePrice;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($offerCombination->reference)) {
|
|
|
|
|
$offerArticle = htmlspecialchars($offerCombination->reference);
|
|
|
|
|
} else {
|
|
|
|
|
$offerArticle = $article;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 12:35:55 +03:00
|
|
|
|
$name = htmlspecialchars(
|
|
|
|
|
strip_tags(
|
|
|
|
|
Product::getProductName($product['id_product'], $offer['id_product_attribute'])
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
2021-07-29 20:37:35 +07:00
|
|
|
|
$item = [
|
2020-12-28 14:51:01 +03:00
|
|
|
|
'id' => $product['id_product'] . '#' . $offer['id_product_attribute'],
|
2024-05-13 09:36:16 +03:00
|
|
|
|
'type' => $useServices ? 'service' : 'product',
|
2020-12-28 14:51:01 +03:00
|
|
|
|
'productId' => $product['id_product'],
|
|
|
|
|
'productActivity' => ($available_for_order) ? 'Y' : 'N',
|
2022-09-30 12:35:55 +03:00
|
|
|
|
'name' => ('' === $name) ? $productName : $name,
|
|
|
|
|
'productName' => $productName,
|
2021-02-26 15:42:08 +03:00
|
|
|
|
'categoryId' => $categoriesLeft,
|
2020-12-28 14:51:01 +03:00
|
|
|
|
'picture' => $pictures,
|
|
|
|
|
'url' => $url,
|
2022-09-30 12:35:55 +03:00
|
|
|
|
'quantity' => (0 < $quantity) ? $quantity : 0,
|
2020-12-28 14:51:01 +03:00
|
|
|
|
'purchasePrice' => $offerPurchasePrice,
|
|
|
|
|
'price' => round($offerPrice, 2),
|
|
|
|
|
'vendor' => $vendor,
|
|
|
|
|
'article' => $offerArticle,
|
|
|
|
|
'weight' => $weight,
|
2021-06-04 10:33:55 +03:00
|
|
|
|
'dimensions' => $dimensions,
|
|
|
|
|
'vatRate' => $product['rate'],
|
2023-09-01 17:17:24 +03:00
|
|
|
|
'features' => $features,
|
2021-07-29 20:37:35 +07:00
|
|
|
|
];
|
2020-12-28 14:51:01 +03:00
|
|
|
|
|
|
|
|
|
if (!empty($combinations)) {
|
|
|
|
|
foreach ($arComb as $itemComb) {
|
2021-10-18 17:52:16 +03:00
|
|
|
|
$item['combination'][$itemComb['id_attribute_group']] = [
|
|
|
|
|
'group_name' => mb_strtolower($itemComb['group_name']),
|
|
|
|
|
'attribute_name' => htmlspecialchars($itemComb['attribute_name']),
|
|
|
|
|
];
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-18 17:52:16 +03:00
|
|
|
|
unset($arComb);
|
|
|
|
|
|
2022-09-09 10:59:25 +03:00
|
|
|
|
$item = RetailcrmTools::filter(
|
2021-05-28 15:51:15 +03:00
|
|
|
|
'RetailcrmFilterProcessOffer',
|
|
|
|
|
$item,
|
2021-07-29 20:37:35 +07:00
|
|
|
|
[
|
2021-05-28 15:51:15 +03:00
|
|
|
|
'product' => $product,
|
2021-11-03 16:19:39 +07:00
|
|
|
|
'offer' => $offer,
|
2021-07-29 20:37:35 +07:00
|
|
|
|
]
|
2021-05-28 15:51:15 +03:00
|
|
|
|
);
|
2022-09-09 10:59:25 +03:00
|
|
|
|
|
|
|
|
|
if ([] !== $item) {
|
|
|
|
|
yield $item;
|
|
|
|
|
}
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
2019-08-21 15:02:23 +03:00
|
|
|
|
} else {
|
2021-11-03 16:19:39 +07:00
|
|
|
|
++$offersCount;
|
2019-08-21 15:02:23 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$covers = Image::getImages($id_lang, $product['id_product'], null);
|
2021-07-29 20:37:35 +07:00
|
|
|
|
$pictures = $this->getPictures($covers, $product);
|
2016-08-29 15:59:19 +03:00
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if ('1.3' == $this->version) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$quantity = $product['quantity'];
|
|
|
|
|
} else {
|
2021-11-03 16:19:39 +07:00
|
|
|
|
$quantity = (int) StockAvailable::getQuantityAvailableByProduct($product['id_product']);
|
2017-03-21 12:46:37 +04:00
|
|
|
|
}
|
2018-10-05 17:50:20 +03:00
|
|
|
|
|
2022-09-09 10:59:25 +03:00
|
|
|
|
$item = RetailcrmTools::filter(
|
2021-05-28 15:51:15 +03:00
|
|
|
|
'RetailcrmFilterProcessOffer',
|
2022-09-09 10:59:25 +03:00
|
|
|
|
[
|
|
|
|
|
'id' => $product['id_product'],
|
2024-05-13 09:36:16 +03:00
|
|
|
|
'type' => $useServices ? 'service' : 'product',
|
2022-09-09 10:59:25 +03:00
|
|
|
|
'productId' => $product['id_product'],
|
|
|
|
|
'productActivity' => ($available_for_order) ? 'Y' : 'N',
|
2022-09-30 12:35:55 +03:00
|
|
|
|
'name' => $productName,
|
|
|
|
|
'productName' => $productName,
|
2022-09-09 10:59:25 +03:00
|
|
|
|
'categoryId' => $categoriesLeft,
|
|
|
|
|
'picture' => $pictures,
|
|
|
|
|
'url' => $url,
|
|
|
|
|
'quantity' => 0 < $quantity ? $quantity : 0,
|
|
|
|
|
'purchasePrice' => round($purchasePrice, 2),
|
|
|
|
|
'price' => $price,
|
|
|
|
|
'vendor' => $vendor,
|
|
|
|
|
'article' => $article,
|
|
|
|
|
'weight' => $weight,
|
|
|
|
|
'dimensions' => $dimensions,
|
|
|
|
|
'vatRate' => $product['rate'],
|
2023-09-01 17:17:24 +03:00
|
|
|
|
'features' => $features,
|
2022-09-09 10:59:25 +03:00
|
|
|
|
],
|
2021-07-29 20:37:35 +07:00
|
|
|
|
[
|
2021-11-03 16:19:39 +07:00
|
|
|
|
'product' => $product,
|
2021-07-29 20:37:35 +07:00
|
|
|
|
]
|
2021-05-28 15:51:15 +03:00
|
|
|
|
);
|
2022-09-09 10:59:25 +03:00
|
|
|
|
|
|
|
|
|
if ([] !== $item) {
|
|
|
|
|
yield $item;
|
|
|
|
|
}
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
2016-08-29 15:59:19 +03:00
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$start += $limit;
|
2021-11-03 16:19:39 +07:00
|
|
|
|
} while ($start < $count && 0 < count($products));
|
|
|
|
|
}
|
2021-07-27 13:25:44 +03:00
|
|
|
|
|
|
|
|
|
RetailcrmCatalogHelper::setIcmlFileInfo($productsCount, $offersCount);
|
2020-12-28 14:51:01 +03:00
|
|
|
|
}
|
2016-08-29 15:59:19 +03:00
|
|
|
|
|
2021-07-29 20:37:35 +07:00
|
|
|
|
private function getPictures(array $covers, array $product, $offers = false)
|
|
|
|
|
{
|
|
|
|
|
$pictures = [];
|
|
|
|
|
foreach ($covers as $cover) {
|
|
|
|
|
$picture = $this->protocol . $this->link->getImageLink($product['link_rewrite'], $product['id_product'] . '-' . $cover['id_image'], 'large_default');
|
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if (false === $offers && $cover['cover']) {
|
2021-07-29 20:37:35 +07:00
|
|
|
|
array_unshift($pictures, $picture);
|
|
|
|
|
} else {
|
|
|
|
|
$pictures[] = $picture;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-11-03 16:19:39 +07:00
|
|
|
|
|
2021-07-29 20:37:35 +07:00
|
|
|
|
return $pictures;
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-23 20:54:55 +07:00
|
|
|
|
private static function getProductsCount($id_lang, Context $context = null)
|
|
|
|
|
{
|
2020-12-28 14:51:01 +03:00
|
|
|
|
if (!$context) {
|
|
|
|
|
$context = Context::getContext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$front = true;
|
2021-11-03 16:19:39 +07:00
|
|
|
|
if (!in_array($context->controller->controller_type, ['front', 'modulefront'])) {
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$front = false;
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-28 14:51:01 +03:00
|
|
|
|
$sql = 'SELECT COUNT(product_shop.`id_product`) AS nb
|
|
|
|
|
FROM `' . _DB_PREFIX_ . 'product` p
|
|
|
|
|
' . Shop::addSqlAssociation('product', 'p') . '
|
|
|
|
|
LEFT JOIN `' . _DB_PREFIX_ . 'product_lang` pl ON (p.`id_product` = pl.`id_product` ' . Shop::addSqlRestrictionOnLang('pl') . ')
|
2021-11-03 16:19:39 +07:00
|
|
|
|
WHERE pl.`id_lang` = ' . (int) $id_lang .
|
2020-12-28 14:51:01 +03:00
|
|
|
|
($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '');
|
|
|
|
|
|
2021-11-03 16:19:39 +07:00
|
|
|
|
return (int) Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|
2020-04-16 15:26:03 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Category|\CategoryCore $category
|
|
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
private static function isCategoryActive($category)
|
|
|
|
|
{
|
|
|
|
|
if ($category->id == Configuration::get('PS_HOME_CATEGORY')) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$category->active) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!empty($category->id_parent)) {
|
|
|
|
|
$parent = new Category($category->id_parent);
|
|
|
|
|
|
|
|
|
|
if (!$parent->active) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return self::isCategoryActive($parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $category->active;
|
|
|
|
|
}
|
2020-04-20 15:29:38 +03:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns active parent category
|
|
|
|
|
*
|
2020-11-12 13:57:54 +03:00
|
|
|
|
* @param int $categoryId
|
2020-04-20 15:29:38 +03:00
|
|
|
|
* @param int $parentId
|
|
|
|
|
*
|
|
|
|
|
* @return null
|
|
|
|
|
*/
|
2020-11-12 13:57:54 +03:00
|
|
|
|
private static function getParentCategoryId($categoryId, $parentId)
|
2020-04-20 15:29:38 +03:00
|
|
|
|
{
|
|
|
|
|
$home = Configuration::get('PS_HOME_CATEGORY');
|
|
|
|
|
|
|
|
|
|
if (empty($parentId)) {
|
2020-11-12 13:57:54 +03:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($categoryId == $home) {
|
|
|
|
|
return null;
|
2020-04-20 15:29:38 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($parentId == $home) {
|
|
|
|
|
return $home;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @var \Category|\CategoryCore $category */
|
|
|
|
|
$category = new Category($parentId);
|
|
|
|
|
|
|
|
|
|
if (empty($category->id) || !$category->active) {
|
|
|
|
|
return $home;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $parentId;
|
|
|
|
|
}
|
2021-11-23 20:54:55 +07:00
|
|
|
|
|
|
|
|
|
private function getWeightInKg($weight)
|
|
|
|
|
{
|
|
|
|
|
if (0 == $weight) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$mg = 1 / 1000 / 1000;
|
|
|
|
|
$g = 1 / 1000;
|
|
|
|
|
$ton = 1 * 1000;
|
|
|
|
|
$oz = 1 / 35.3;
|
|
|
|
|
$pd = 1 * 2.2;
|
|
|
|
|
$st = 1 * 6.35;
|
|
|
|
|
|
|
|
|
|
$weightUnits = [
|
|
|
|
|
'mg' => $mg,
|
|
|
|
|
'мг' => $mg,
|
|
|
|
|
'miligramo' => $mg,
|
|
|
|
|
'миллиграмм' => $mg,
|
|
|
|
|
'milligram' => $mg,
|
|
|
|
|
|
|
|
|
|
'g' => $g,
|
|
|
|
|
'gram' => $g,
|
|
|
|
|
'grammo' => $g,
|
|
|
|
|
'г' => $g,
|
|
|
|
|
'гр' => $g,
|
|
|
|
|
'грамм' => $g,
|
|
|
|
|
|
|
|
|
|
'kg' => 1,
|
|
|
|
|
'kilogram' => 1,
|
|
|
|
|
'kilogramme' => 1,
|
|
|
|
|
'kilo' => 1,
|
|
|
|
|
'kilogramo' => 1,
|
|
|
|
|
|
|
|
|
|
'ton' => $ton,
|
|
|
|
|
'т' => $ton,
|
|
|
|
|
'тонна' => $ton,
|
|
|
|
|
'tonelada' => $ton,
|
|
|
|
|
'toneladas' => $ton,
|
|
|
|
|
|
|
|
|
|
'oz' => $oz,
|
|
|
|
|
'унция' => $oz,
|
|
|
|
|
'ounce' => $oz,
|
|
|
|
|
'onza' => $oz,
|
|
|
|
|
|
|
|
|
|
'pd' => $pd,
|
|
|
|
|
'фунт' => $pd,
|
|
|
|
|
'pound' => $pd,
|
|
|
|
|
'lb' => $pd,
|
|
|
|
|
'libra' => $pd,
|
|
|
|
|
'paladio' => $pd,
|
|
|
|
|
|
|
|
|
|
'st' => $st,
|
|
|
|
|
'стоун' => $st,
|
|
|
|
|
'stone' => $st,
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
$weightUnits = RetailcrmTools::filter('RetailcrmFilterWeight', $weightUnits);
|
|
|
|
|
|
|
|
|
|
$weightUnit = Configuration::get('PS_WEIGHT_UNIT');
|
|
|
|
|
|
|
|
|
|
if (isset($weightUnits[$weightUnit])) {
|
|
|
|
|
return $weight * $weightUnits[$weightUnit];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $weight;
|
|
|
|
|
}
|
2016-01-13 18:43:41 +03:00
|
|
|
|
}
|