1
0
mirror of synced 2024-11-21 21:06:09 +03:00

ref #85233 Добавление в генерацию каталога свойства активности товара (#286)

This commit is contained in:
Kocmonavtik 2023-04-13 13:50:18 +03:00 committed by GitHub
parent be1447c6ec
commit 0ca2527c5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 69 additions and 18 deletions

View File

@ -1,3 +1,6 @@
## 2023-04-10 v.6.3.2
- Добавлена возможность экспорта неактивных товаров и торговых предложений
## 2023-04-10 v.6.3.1
- Добавлена валидация свойств товаров и торговых предложений в настройках экспорта

View File

@ -1 +1 @@
- Добавлена валидация свойств товаров и торговых предложений в настройках экспорта
- Добавлена возможность экспорта неактивных товаров и торговых предложений

View File

@ -159,6 +159,7 @@ if (file_exists($_SERVER['DOCUMENT_ROOT'] . '/bitrix/php_interface/retailcrm/exp
$fileSetup->maxOffersValue = $maxOffersValue ?? null;
$fileSetup->filePath = $SETUP_FILE_NAME;
$fileSetup->loadPurchasePrice = $loadPurchasePrice === 'Y';
$fileSetup->loadNonActivity = $loadNonActivity === 'Y';
$fileSetup->basePriceId = CatalogRepository::getBasePriceId($fileSetup->profileId);
if (!is_array($fileSetup->iblocksForExport) || count($fileSetup->iblocksForExport) === 0) {

View File

@ -66,6 +66,7 @@ if (($ACTION === 'EXPORT' || $ACTION === 'EXPORT_EDIT' || $ACTION === 'EXPORT_CO
$iblockProperties = $settingsService->getIblockPropsPreset();
$loadPurchasePrice = $settingsService->loadPurchasePrice;
$iblockExport = $settingsService->iblockExport;
$loadNonActivity = $settingsService->loadNonActivity;
if ($iblockExport) {
$maxOffersValue = $settingsService->getSingleSetting('maxOffersValue');
@ -491,6 +492,9 @@ if ($STEP === 1) {
$SETUP_FILE_NAME : $settingsService->setupFileName); ?>" size="50"><br><br>
<span class="text"><?=GetMessage('LOAD_PURCHASE_PRICE')?>&nbsp;</span>
<input type="checkbox" name="loadPurchasePrice" value="Y" <?=$loadPurchasePrice === 'Y' ? 'checked' : ''?>>
<br>
<span class="text"><?=GetMessage('LOAD_NON_ACTIVITY')?>&nbsp;</span>
<input type="checkbox" name="loadNonActivity" value="Y" <?=$loadNonActivity === 'Y' ? 'checked' : ''?>>
<br><br><br>
<?php
if ($isSetupModulePage) { ?>

View File

@ -1,6 +1,6 @@
<?php
$arModuleVersion = [
'VERSION' => '6.3.1',
'VERSION_DATE' => '2023-04-10 10:00:00'
'VERSION' => '6.3.2',
'VERSION_DATE' => '2023-04-10 18:00:00'
];

View File

@ -7,6 +7,7 @@ $MESS["CATALOG"] = "Каталог";
$MESS["EXPORT2INTAROCML"] = "Выгрузить в ICML";
$MESS["FILENAME"] = "Укажите имя файла данных:";
$MESS["LOAD_PURCHASE_PRICE"] = "Выгружать закупочную цену";
$MESS["LOAD_NON_ACTIVITY"] = "Выгружать неактивные товары и торговые предложения";
$MESS["PROPERTY"] = "Свойство, содержащее артикул товара";
$MESS["ALL_CATALOG"] = "Все каталоги";
$MESS["EXPORT"] = "Экспортировать";

View File

@ -164,8 +164,7 @@ class IcmlDirector
$selectParams->allParams = array_merge($selectParams->configurable, $selectParams->main);
while ($xmlOffers = $this->xmlOfferDirector->getXmlOffersPart($selectParams, $catalogIblockInfo)) {
$this->icmlWriter->writeOffers($xmlOffers);
$this->icmlWriter->writeOffers($xmlOffers, $xmlOffers->activity === 'N');
$selectParams->pageNumber++;
}
@ -250,9 +249,15 @@ class IcmlDirector
$paramsForOffer->allParams = array_merge($paramsForOffer->configurable, $paramsForOffer->main);
do {
$isNotActiveProduct = false;
if ($product->activity === 'N') {
$isNotActiveProduct = true;
}
//Если каталог проиндексирован, у товара есть Тип и это простой товар, то просто записываем его
if ($product->productType === ProductTable::TYPE_PRODUCT) {
$this->icmlWriter->writeOffers([$product]);
$this->icmlWriter->writeOffers([$product], $isNotActiveProduct);
break;
}
@ -261,7 +266,7 @@ class IcmlDirector
// если это "простой товар", у которого нет ТП, то просто записываем его
if ($paramsForOffer->pageNumber === 1 && count($xmlOffersPart) === 0) {
$this->icmlWriter->writeOffers([$product]);
$this->icmlWriter->writeOffers([$product], $isNotActiveProduct);
break;
}
@ -269,7 +274,7 @@ class IcmlDirector
$xmlOffersPart
= $this->trimOffersList($writingOffersCount, $xmlOffersPart);
$this->icmlWriter->writeOffers($xmlOffersPart);
$this->icmlWriter->writeOffers($xmlOffersPart, $isNotActiveProduct);
$writingOffersCount += count($xmlOffersPart);
$paramsForOffer->pageNumber++;

View File

@ -97,11 +97,12 @@ class IcmlWriter
/**
* @param XmlOffer[] $offers
* @param bool $isNotActiveProduct
*/
public function writeOffers(array $offers): void
public function writeOffers(array $offers, $isNotActiveProduct = false): void
{
foreach ($offers as $offer) {
$this->writeOffer($offer);
$this->writeOffer($offer, $isNotActiveProduct);
}
file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
@ -109,14 +110,21 @@ class IcmlWriter
/**
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer $offer
* @param bool $isNotActiveProduct
*/
private function writeOffer(XmlOffer $offer): void
private function writeOffer(XmlOffer $offer, $isNotActiveProduct): void
{
$this->writer->startElement('offer');
$this->writeSimpleAttribute('id', $offer->id);
$this->writeSimpleAttribute('productId', $offer->productId);
$this->writeSimpleAttribute('quantity', $offer->quantity);
if ($isNotActiveProduct) {
$this->writeSimpleElement('productActivity', 'N');
} else {
$this->writeSimpleElement('activity', $offer->activity);
}
foreach ($offer->categoryIds as $categoryId) {
$this->writeSimpleElement('categoryId', $categoryId);
}

View File

@ -58,6 +58,7 @@ class QueryParamsMolder
'ID',
'LID',
'VAT_ID',
'ACTIVE'
];
return $params;
@ -66,20 +67,27 @@ class QueryParamsMolder
/**
* @param int|null $parentId
* @param \Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo $info
* @param boolean $loadNonActivity
* @return array
*/
public function getWhereForOfferPart(?int $parentId, CatalogIblockInfo $info): array
public function getWhereForOfferPart(?int $parentId, CatalogIblockInfo $info, bool $loadNonActivity): array
{
$active = "";
if (!$loadNonActivity) {
$active = "Y";
}
if ($parentId === null) {
return [
'IBLOCK_ID' => $info->productIblockId,
'ACTIVE' => 'Y',
'ACTIVE' => $active,
];
}
return [
'IBLOCK_ID' => $info->skuIblockId,
'ACTIVE' => 'Y',
'ACTIVE' => $active,
'PROPERTY_' . $info->skuPropertyId => $parentId,
];
}

View File

@ -92,6 +92,11 @@ class SettingsService
*/
public $vatRates = [];
/**
* @var mixed|string|null
*/
public $loadNonActivity;
/**
* @var \Intaro\RetailCrm\Icml\SettingsService|null
*/
@ -109,6 +114,7 @@ class SettingsService
$this->action = $action;
$this->iblockExport = $this->getSingleSetting('iblockExport');
$this->loadPurchasePrice = $this->getSingleSetting('loadPurchasePrice');
$this->loadNonActivity = $this->getSingleSetting('loadNonActivity');
$oldSetup = $this->getSingleSetting('SETUP_FILE_NAME');
$defaultFilePath = RetailcrmConfigProvider::getDefaultIcmlPath();
$this->setupFileName = htmlspecialcharsbx($oldSetup ?? $defaultFilePath);
@ -419,7 +425,7 @@ class SettingsService
*/
public function getSetupFieldsString(array $iblockProperties, bool $hlblockModule, array $hlBlockList): string
{
$values = 'loadPurchasePrice,SETUP_FILE_NAME,iblockExport,maxOffersValue';
$values = 'loadPurchasePrice,SETUP_FILE_NAME,iblockExport,maxOffersValue,loadNonActivity';
foreach ($iblockProperties as $val) {
$values .= ',iblockPropertySku_' . $val

View File

@ -252,6 +252,7 @@ class XmlOfferBuilder
$this->xmlOffer->productName = $item['NAME'];
$this->xmlOffer->vatRate = $this->getVatRate($item);
$this->xmlOffer->unitCode = $this->getUnitCode($item['CATALOG_MEASURE'], $item['ID']);
$this->xmlOffer->activity = $item['ACTIVE'];
}
/**

View File

@ -71,7 +71,7 @@ class XmlOfferDirector
*/
public function getXmlOffersPart(SelectParams $param, CatalogIblockInfo $catalogIblockInfo): array
{
$ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo);
$ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo, $this->setup->loadNonActivity);
$offers = [];
while ($offer = $ciBlockResult->Fetch()) {

View File

@ -129,6 +129,13 @@ class XmlOffer
*/
public $productType;
/**
* Активность товара/торгового предложения (N|Y)
*
* @var string
*/
public $activity;
/**
* @param $productValue
* @param $offerValue

View File

@ -71,4 +71,10 @@ class XmlSetup
* @var int|null
*/
public $basePriceId;
/**
*
* @var bool
*/
public $loadNonActivity;
}

View File

@ -88,13 +88,14 @@ class CatalogRepository
/**
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams $param
* @param \Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo $catalogIblockInfo
* @param boolean $loadNonActivity
* @return \CIBlockResult|int
*/
public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo)
public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo, bool $loadNonActivity)
{
return CIBlockElement::GetList(
['ID' => 'ASC'],
$this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo),
$this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo, $loadNonActivity),
false,
['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true],
$param->allParams