2021-05-31 16:33:02 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Intaro\RetailCrm\Icml;
|
|
|
|
|
|
|
|
use Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo;
|
|
|
|
use Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class QueryParamsMolder
|
|
|
|
* @package Intaro\RetailCrm\Icml
|
|
|
|
*/
|
|
|
|
class QueryParamsMolder
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Формирует параметры товаров или офферов для запросов к БД на основе настроек экспорта
|
|
|
|
*
|
|
|
|
* @param array|null $userProps
|
|
|
|
* @param int $basePriceId
|
|
|
|
* @return \Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams
|
|
|
|
*/
|
|
|
|
public function getSelectParams(?array $userProps, int $basePriceId): SelectParams
|
|
|
|
{
|
|
|
|
$catalogFields = ['catalog_length', 'catalog_width', 'catalog_height', 'catalog_weight'];
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$params = new SelectParams();
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
foreach ($userProps as $key => $name) {
|
|
|
|
if ($name === '') {
|
|
|
|
unset($userProps[$key]);
|
|
|
|
continue;
|
|
|
|
}
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if (in_array($name, $catalogFields, true)) {
|
|
|
|
$userProps[$key] = strtoupper($userProps[$key]);
|
|
|
|
} else {
|
|
|
|
$userProps[$key] = 'PROPERTY_' . $userProps[$key];
|
|
|
|
}
|
|
|
|
}
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
$params->configurable = $userProps ?? [];
|
|
|
|
$params->main = [
|
2021-09-08 16:31:17 +03:00
|
|
|
'LANG_DIR',
|
|
|
|
'CODE',
|
2021-05-31 16:33:02 +03:00
|
|
|
'IBLOCK_ID',
|
2021-09-08 16:31:17 +03:00
|
|
|
'IBLOCK_CODE',
|
2021-05-31 16:33:02 +03:00
|
|
|
'IBLOCK_SECTION_ID',
|
2021-09-08 16:31:17 +03:00
|
|
|
'IBLOCK_EXTERNAL_ID',
|
2021-05-31 16:33:02 +03:00
|
|
|
'NAME',
|
|
|
|
'DETAIL_PICTURE',
|
|
|
|
'PREVIEW_PICTURE',
|
|
|
|
'DETAIL_PAGE_URL',
|
|
|
|
'CATALOG_QUANTITY',
|
2021-11-02 11:25:26 +03:00
|
|
|
'CATALOG_TYPE',
|
2021-05-31 16:33:02 +03:00
|
|
|
'CATALOG_PRICE_' . $basePriceId,
|
|
|
|
'CATALOG_PURCHASING_PRICE',
|
|
|
|
'EXTERNAL_ID',
|
|
|
|
'CATALOG_GROUP_' . $basePriceId,
|
|
|
|
'ID',
|
|
|
|
'LID',
|
2022-08-22 10:26:21 +03:00
|
|
|
'VAT_ID',
|
2023-04-13 13:50:18 +03:00
|
|
|
'ACTIVE'
|
2021-05-31 16:33:02 +03:00
|
|
|
];
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
return $params;
|
|
|
|
}
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
/**
|
|
|
|
* @param int|null $parentId
|
|
|
|
* @param \Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo $info
|
2023-04-13 13:50:18 +03:00
|
|
|
* @param boolean $loadNonActivity
|
2021-05-31 16:33:02 +03:00
|
|
|
* @return array
|
|
|
|
*/
|
2023-04-13 13:50:18 +03:00
|
|
|
public function getWhereForOfferPart(?int $parentId, CatalogIblockInfo $info, bool $loadNonActivity): array
|
2021-05-31 16:33:02 +03:00
|
|
|
{
|
2023-04-13 13:50:18 +03:00
|
|
|
$active = "";
|
|
|
|
|
|
|
|
if (!$loadNonActivity) {
|
|
|
|
$active = "Y";
|
|
|
|
}
|
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
if ($parentId === null) {
|
|
|
|
return [
|
|
|
|
'IBLOCK_ID' => $info->productIblockId,
|
2023-04-13 13:50:18 +03:00
|
|
|
'ACTIVE' => $active,
|
2021-05-31 16:33:02 +03:00
|
|
|
];
|
|
|
|
}
|
2021-09-08 16:31:17 +03:00
|
|
|
|
2021-05-31 16:33:02 +03:00
|
|
|
return [
|
|
|
|
'IBLOCK_ID' => $info->skuIblockId,
|
2023-04-13 13:50:18 +03:00
|
|
|
'ACTIVE' => $active,
|
2021-05-31 16:33:02 +03:00
|
|
|
'PROPERTY_' . $info->skuPropertyId => $parentId,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|