1
0
mirror of synced 2024-11-23 22:06:11 +03:00

ref #95225 Добавлена передача услуг через ICML каталог (#345)

This commit is contained in:
Kocmonavtik 2024-04-24 09:48:51 +03:00 committed by GitHub
parent c1f59ead7f
commit 1eabbe323b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
11 changed files with 62 additions and 34 deletions

View File

@ -1,3 +1,6 @@
## 2024-04-23 v.6.5.15
- Добавлена передача услуг через ICML каталог
## 2024-04-18 v.6.5.14 ## 2024-04-18 v.6.5.14
- Исправление работы кнопки "Выгрузка служб доставок" - Исправление работы кнопки "Выгрузка служб доставок"

View File

@ -1 +1 @@
- Исправление работы кнопки "Выгрузка служб доставок" - Добавлена передача услуг через ICML каталог

View File

@ -1,6 +1,6 @@
<?php <?php
$arModuleVersion = [ $arModuleVersion = [
'VERSION' => '6.5.14', 'VERSION' => '6.5.15',
'VERSION_DATE' => '2024-04-18 11:15:00' 'VERSION_DATE' => '2024-04-23 10:30:00'
]; ];

View File

@ -46,3 +46,4 @@ $MESS["UNIT_MEASUREMENT_KG"] = "kg";
$MESS['BASE_PRICE'] = 'Base price'; $MESS['BASE_PRICE'] = 'Base price';
$MESS['WAIT'] = 'Loading...'; $MESS['WAIT'] = 'Loading...';
$MESS["OFFERS_VALUE"] = "Maximum number of trade offers for a product"; $MESS["OFFERS_VALUE"] = "Maximum number of trade offers for a product";
$MESS["LOAD_NON_ACTIVITY"] = "Unload inactive products, services and trade offers";

View File

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

View File

@ -78,13 +78,15 @@ class IcmlDirector
{ {
$this->setup = $setup; $this->setup = $setup;
$this->shopName = RetailcrmConfigProvider::getSiteName(); $this->shopName = RetailcrmConfigProvider::getSiteName();
$this->catalogRepository = new CatalogRepository();
$this->icmlWriter = new IcmlWriter($this->setup->filePath); $this->icmlWriter = new IcmlWriter($this->setup->filePath);
$this->xmlOfferDirector = new XmlOfferDirector($this->setup); $this->xmlOfferDirector = new XmlOfferDirector($this->setup);
$this->xmlCategoryDirector = new XmlCategoryDirector($this->setup->iblocksForExport); $this->xmlCategoryDirector = new XmlCategoryDirector($this->setup);
$this->queryBuilder = new QueryParamsMolder(); $this->queryBuilder = new QueryParamsMolder();
$this->xmlData = new XmlData(); $this->xmlData = new XmlData();
$this->logger = $logger; $this->logger = $logger;
$this->catalogRepository = new CatalogRepository();
$this->catalogRepository->setLoadNotActive($this->setup->loadNonActivity);
} }
/** /**
@ -164,7 +166,7 @@ class IcmlDirector
$selectParams->allParams = array_merge($selectParams->configurable, $selectParams->main); $selectParams->allParams = array_merge($selectParams->configurable, $selectParams->main);
while ($xmlOffers = $this->xmlOfferDirector->getXmlOffersPart($selectParams, $catalogIblockInfo)) { while ($xmlOffers = $this->xmlOfferDirector->getXmlOffersPart($selectParams, $catalogIblockInfo)) {
$this->icmlWriter->writeOffers($xmlOffers, $xmlOffers->activity === 'N'); $this->icmlWriter->writeOffers($xmlOffers);
$selectParams->pageNumber++; $selectParams->pageNumber++;
} }
@ -249,15 +251,9 @@ class IcmlDirector
$paramsForOffer->allParams = array_merge($paramsForOffer->configurable, $paramsForOffer->main); $paramsForOffer->allParams = array_merge($paramsForOffer->configurable, $paramsForOffer->main);
do { do {
$isNotActiveProduct = false;
if ($product->activity === 'N') {
$isNotActiveProduct = true;
}
//Если каталог проиндексирован, у товара есть Тип и это простой товар, то просто записываем его //Если каталог проиндексирован, у товара есть Тип и это простой товар, то просто записываем его
if ($product->productType === ProductTable::TYPE_PRODUCT) { if ($product->productType === ProductTable::TYPE_PRODUCT) {
$this->icmlWriter->writeOffers([$product], $isNotActiveProduct); $this->icmlWriter->writeOffers([$product]);
break; break;
} }
@ -266,7 +262,7 @@ class IcmlDirector
// если это "простой товар", у которого нет ТП, то просто записываем его // если это "простой товар", у которого нет ТП, то просто записываем его
if ($paramsForOffer->pageNumber === 1 && count($xmlOffersPart) === 0) { if ($paramsForOffer->pageNumber === 1 && count($xmlOffersPart) === 0) {
$this->icmlWriter->writeOffers([$product], $isNotActiveProduct); $this->icmlWriter->writeOffers([$product]);
break; break;
} }
@ -274,7 +270,7 @@ class IcmlDirector
$xmlOffersPart $xmlOffersPart
= $this->trimOffersList($writingOffersCount, $xmlOffersPart); = $this->trimOffersList($writingOffersCount, $xmlOffersPart);
$this->icmlWriter->writeOffers($xmlOffersPart, $isNotActiveProduct); $this->icmlWriter->writeOffers($xmlOffersPart);
$writingOffersCount += count($xmlOffersPart); $writingOffersCount += count($xmlOffersPart);
$paramsForOffer->pageNumber++; $paramsForOffer->pageNumber++;

View File

@ -7,6 +7,7 @@ use Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlData; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlData;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer;
use XMLWriter; use XMLWriter;
use Bitrix\Catalog\ProductTable;
/** /**
* Отвечает за запись данных каталога в файл * Отвечает за запись данных каталога в файл
@ -23,6 +24,7 @@ class IcmlWriter
* @var \XMLWriter * @var \XMLWriter
*/ */
private $writer; private $writer;
/** /**
* @var string * @var string
*/ */
@ -99,10 +101,10 @@ class IcmlWriter
* @param XmlOffer[] $offers * @param XmlOffer[] $offers
* @param bool $isNotActiveProduct * @param bool $isNotActiveProduct
*/ */
public function writeOffers(array $offers, $isNotActiveProduct = false): void public function writeOffers(array $offers): void
{ {
foreach ($offers as $offer) { foreach ($offers as $offer) {
$this->writeOffer($offer, $isNotActiveProduct); $this->writeOffer($offer);
} }
file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND); file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
@ -112,19 +114,16 @@ class IcmlWriter
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer $offer * @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer $offer
* @param bool $isNotActiveProduct * @param bool $isNotActiveProduct
*/ */
private function writeOffer(XmlOffer $offer, $isNotActiveProduct): void private function writeOffer(XmlOffer $offer): void
{ {
$productType = $offer->productType === ProductTable::TYPE_SERVICE ? 'service' : 'product';
$this->writer->startElement('offer'); $this->writer->startElement('offer');
$this->writeSimpleAttribute('id', $offer->id); $this->writeSimpleAttribute('id', $offer->id);
$this->writeSimpleAttribute('type', $productType);
$this->writeSimpleAttribute('productId', $offer->productId); $this->writeSimpleAttribute('productId', $offer->productId);
$this->writeSimpleAttribute('quantity', $offer->quantity); $this->writeSimpleAttribute('quantity', $offer->quantity);
if ($isNotActiveProduct) {
$this->writeSimpleElement('productActivity', 'N');
} else {
$this->writeSimpleElement('activity', $offer->activity);
}
foreach ($offer->categoryIds as $categoryId) { foreach ($offer->categoryIds as $categoryId) {
$this->writeSimpleElement('categoryId', $categoryId); $this->writeSimpleElement('categoryId', $categoryId);
} }
@ -145,6 +144,14 @@ class IcmlWriter
$this->writeParam($param); $this->writeParam($param);
} }
$activity = $offer->activity;
null === $offer->activityProduct ?
$this->writeSimpleElement('productActivity', $activity) :
$this->writeSimpleElement('productActivity', $offer->activityProduct)
;
$this->writeSimpleElement('activity', $activity);
$this->writeSimpleElement('url', $offer->url); $this->writeSimpleElement('url', $offer->url);
$this->writeSimpleElement('price', $offer->price); $this->writeSimpleElement('price', $offer->price);
$this->writeSimpleElement('name', $offer->name); $this->writeSimpleElement('name', $offer->name);

View File

@ -8,6 +8,7 @@ use Bitrix\Main\ORM\Objectify\Collection;
use Bitrix\Main\ORM\Objectify\EntityObject; use Bitrix\Main\ORM\Objectify\EntityObject;
use Bitrix\Main\SystemException; use Bitrix\Main\SystemException;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetup;
use Intaro\RetailCrm\Repository\CatalogRepository; use Intaro\RetailCrm\Repository\CatalogRepository;
use Intaro\RetailCrm\Repository\FileRepository; use Intaro\RetailCrm\Repository\FileRepository;
use Intaro\RetailCrm\Repository\SiteRepository; use Intaro\RetailCrm\Repository\SiteRepository;
@ -40,12 +41,14 @@ class XmlCategoryDirector
*/ */
private $fileRepository; private $fileRepository;
public function __construct(array $iblocksForExport) public function __construct(XmlSetup $setup)
{ {
$this->iblocksForExport = $iblocksForExport; $this->iblocksForExport = $setup->iblocksForExport;
$this->catalogRepository = new CatalogRepository();
$this->xmlCategoryFactory = new XmlCategoryFactory(); $this->xmlCategoryFactory = new XmlCategoryFactory();
$this->fileRepository = new FileRepository(SiteRepository::getDefaultServerName()); $this->fileRepository = new FileRepository(SiteRepository::getDefaultServerName());
$this->catalogRepository = new CatalogRepository();
$this->catalogRepository->setLoadNotActive($setup->loadNonActivity);
} }
/** /**

View File

@ -53,12 +53,14 @@ class XmlOfferDirector
{ {
$this->setup = $setup; $this->setup = $setup;
$this->fileRepository = new FileRepository(SiteRepository::getDefaultServerName()); $this->fileRepository = new FileRepository(SiteRepository::getDefaultServerName());
$this->catalogRepository = new CatalogRepository();
$this->xmlOfferBuilder = new XmlOfferBuilder( $this->xmlOfferBuilder = new XmlOfferBuilder(
$setup, $setup,
MeasureRepository::getMeasures(), MeasureRepository::getMeasures(),
SiteRepository::getDefaultServerName() SiteRepository::getDefaultServerName()
); );
$this->catalogRepository = new CatalogRepository();
$this->catalogRepository->setLoadNotActive($this->setup->loadNonActivity);
$this->barcodes = $this->catalogRepository->getBarcodes(); $this->barcodes = $this->catalogRepository->getBarcodes();
} }
@ -71,7 +73,7 @@ class XmlOfferDirector
*/ */
public function getXmlOffersPart(SelectParams $param, CatalogIblockInfo $catalogIblockInfo): array public function getXmlOffersPart(SelectParams $param, CatalogIblockInfo $catalogIblockInfo): array
{ {
$ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo, $this->setup->loadNonActivity); $ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo);
$offers = []; $offers = [];
$this->xmlOfferBuilder->setServerName($this->fileRepository->getServerName($catalogIblockInfo->productIblockId)); $this->xmlOfferBuilder->setServerName($this->fileRepository->getServerName($catalogIblockInfo->productIblockId));
@ -130,6 +132,7 @@ class XmlOfferDirector
$offer->categoryIds = $product->categoryIds; $offer->categoryIds = $product->categoryIds;
$offer->productName = $product->productName; $offer->productName = $product->productName;
$offer->url = $this->mergeUrls($product->url, $offer->url); $offer->url = $this->mergeUrls($product->url, $offer->url);
$offer->activityProduct = $product->activity;
} }
return $xmlOffers; return $xmlOffers;

View File

@ -28,7 +28,7 @@ class XmlOffer
public $productId; public $productId;
/** /**
* @var int * @var string
*/ */
public $quantity; public $quantity;
@ -136,6 +136,12 @@ class XmlOffer
*/ */
public $activity; public $activity;
/**
* Признак активности товара при наличии торговых предложений
* @var string | null
*/
public ?string $activityProduct = null;
/** /**
* @param $productValue * @param $productValue
* @param $offerValue * @param $offerValue

View File

@ -31,6 +31,11 @@ class CatalogRepository
*/ */
private $builder; private $builder;
/**
* @var bool
*/
private $isLoadNotActive = false;
/** /**
* CatalogRepository constructor. * CatalogRepository constructor.
*/ */
@ -39,6 +44,11 @@ class CatalogRepository
$this->builder = new QueryParamsMolder(); $this->builder = new QueryParamsMolder();
} }
public function setLoadNotActive(bool $isLoad)
{
$this->isLoadNotActive = $isLoad;
}
/** /**
* Получение категорий, к которым относится товар * Получение категорий, к которым относится товар
* *
@ -88,14 +98,13 @@ class CatalogRepository
/** /**
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams $param * @param \Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams $param
* @param \Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo $catalogIblockInfo * @param \Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo $catalogIblockInfo
* @param boolean $loadNonActivity
* @return \CIBlockResult|int * @return \CIBlockResult|int
*/ */
public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo, bool $loadNonActivity) public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo)
{ {
return CIBlockElement::GetList( return CIBlockElement::GetList(
['ID' => 'ASC'], ['ID' => 'ASC'],
$this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo, $loadNonActivity), $this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo, $this->isLoadNotActive),
false, false,
['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true], ['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true],
$param->allParams $param->allParams