diff --git a/CHANGELOG.md b/CHANGELOG.md index be938883..90e755d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## 2024-04-23 v.6.5.15 +- Добавлена передача услуг через ICML каталог + ## 2024-04-18 v.6.5.14 - Исправление работы кнопки "Выгрузка служб доставок" diff --git a/intaro.retailcrm/description.ru b/intaro.retailcrm/description.ru index 5400e042..a958b07e 100644 --- a/intaro.retailcrm/description.ru +++ b/intaro.retailcrm/description.ru @@ -1 +1 @@ -- Исправление работы кнопки "Выгрузка служб доставок" \ No newline at end of file +- Добавлена передача услуг через ICML каталог diff --git a/intaro.retailcrm/install/version.php b/intaro.retailcrm/install/version.php index 48c0da66..8b0af8c4 100644 --- a/intaro.retailcrm/install/version.php +++ b/intaro.retailcrm/install/version.php @@ -1,6 +1,6 @@ '6.5.14', - 'VERSION_DATE' => '2024-04-18 11:15:00' + 'VERSION' => '6.5.15', + 'VERSION_DATE' => '2024-04-23 10:30:00' ]; diff --git a/intaro.retailcrm/lang/en/icml_export_setup.php b/intaro.retailcrm/lang/en/icml_export_setup.php index 64a41ca9..adf89e88 100644 --- a/intaro.retailcrm/lang/en/icml_export_setup.php +++ b/intaro.retailcrm/lang/en/icml_export_setup.php @@ -46,3 +46,4 @@ $MESS["UNIT_MEASUREMENT_KG"] = "kg"; $MESS['BASE_PRICE'] = 'Base price'; $MESS['WAIT'] = 'Loading...'; $MESS["OFFERS_VALUE"] = "Maximum number of trade offers for a product"; +$MESS["LOAD_NON_ACTIVITY"] = "Unload inactive products, services and trade offers"; diff --git a/intaro.retailcrm/lang/ru/icml_export_setup.php b/intaro.retailcrm/lang/ru/icml_export_setup.php index 703c893b..73c8dd25 100644 --- a/intaro.retailcrm/lang/ru/icml_export_setup.php +++ b/intaro.retailcrm/lang/ru/icml_export_setup.php @@ -7,7 +7,7 @@ $MESS["CATALOG"] = "Каталог"; $MESS["EXPORT2INTAROCML"] = "Выгрузить в ICML"; $MESS["FILENAME"] = "Укажите имя файла данных:"; $MESS["LOAD_PURCHASE_PRICE"] = "Выгружать закупочную цену"; -$MESS["LOAD_NON_ACTIVITY"] = "Выгружать неактивные товары и торговые предложения"; +$MESS["LOAD_NON_ACTIVITY"] = "Выгружать неактивные товары, услуги и торговые предложения"; $MESS["PROPERTY"] = "Свойство, содержащее артикул товара"; $MESS["ALL_CATALOG"] = "Все каталоги"; $MESS["EXPORT"] = "Экспортировать"; diff --git a/intaro.retailcrm/lib/icml/icmldirector.php b/intaro.retailcrm/lib/icml/icmldirector.php index 8ded832f..9365b0bd 100644 --- a/intaro.retailcrm/lib/icml/icmldirector.php +++ b/intaro.retailcrm/lib/icml/icmldirector.php @@ -78,13 +78,15 @@ class IcmlDirector { $this->setup = $setup; $this->shopName = RetailcrmConfigProvider::getSiteName(); - $this->catalogRepository = new CatalogRepository(); $this->icmlWriter = new IcmlWriter($this->setup->filePath); $this->xmlOfferDirector = new XmlOfferDirector($this->setup); - $this->xmlCategoryDirector = new XmlCategoryDirector($this->setup->iblocksForExport); + $this->xmlCategoryDirector = new XmlCategoryDirector($this->setup); $this->queryBuilder = new QueryParamsMolder(); $this->xmlData = new XmlData(); $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); while ($xmlOffers = $this->xmlOfferDirector->getXmlOffersPart($selectParams, $catalogIblockInfo)) { - $this->icmlWriter->writeOffers($xmlOffers, $xmlOffers->activity === 'N'); + $this->icmlWriter->writeOffers($xmlOffers); $selectParams->pageNumber++; } @@ -249,15 +251,9 @@ 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], $isNotActiveProduct); + $this->icmlWriter->writeOffers([$product]); break; } @@ -266,7 +262,7 @@ class IcmlDirector // если это "простой товар", у которого нет ТП, то просто записываем его if ($paramsForOffer->pageNumber === 1 && count($xmlOffersPart) === 0) { - $this->icmlWriter->writeOffers([$product], $isNotActiveProduct); + $this->icmlWriter->writeOffers([$product]); break; } @@ -274,7 +270,7 @@ class IcmlDirector $xmlOffersPart = $this->trimOffersList($writingOffersCount, $xmlOffersPart); - $this->icmlWriter->writeOffers($xmlOffersPart, $isNotActiveProduct); + $this->icmlWriter->writeOffers($xmlOffersPart); $writingOffersCount += count($xmlOffersPart); $paramsForOffer->pageNumber++; diff --git a/intaro.retailcrm/lib/icml/icmlwriter.php b/intaro.retailcrm/lib/icml/icmlwriter.php index 3bee9e82..6db3d810 100644 --- a/intaro.retailcrm/lib/icml/icmlwriter.php +++ b/intaro.retailcrm/lib/icml/icmlwriter.php @@ -7,6 +7,7 @@ use Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlData; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer; use XMLWriter; +use Bitrix\Catalog\ProductTable; /** * Отвечает за запись данных каталога в файл @@ -23,6 +24,7 @@ class IcmlWriter * @var \XMLWriter */ private $writer; + /** * @var string */ @@ -99,10 +101,10 @@ class IcmlWriter * @param XmlOffer[] $offers * @param bool $isNotActiveProduct */ - public function writeOffers(array $offers, $isNotActiveProduct = false): void + public function writeOffers(array $offers): void { foreach ($offers as $offer) { - $this->writeOffer($offer, $isNotActiveProduct); + $this->writeOffer($offer); } 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 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->writeSimpleAttribute('id', $offer->id); + $this->writeSimpleAttribute('type', $productType); $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); } @@ -145,6 +144,14 @@ class IcmlWriter $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('price', $offer->price); $this->writeSimpleElement('name', $offer->name); diff --git a/intaro.retailcrm/lib/icml/xmlcategorydirector.php b/intaro.retailcrm/lib/icml/xmlcategorydirector.php index 709b7dd1..e0ba6c33 100644 --- a/intaro.retailcrm/lib/icml/xmlcategorydirector.php +++ b/intaro.retailcrm/lib/icml/xmlcategorydirector.php @@ -8,6 +8,7 @@ use Bitrix\Main\ORM\Objectify\Collection; use Bitrix\Main\ORM\Objectify\EntityObject; use Bitrix\Main\SystemException; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory; +use Intaro\RetailCrm\Model\Bitrix\Xml\XmlSetup; use Intaro\RetailCrm\Repository\CatalogRepository; use Intaro\RetailCrm\Repository\FileRepository; use Intaro\RetailCrm\Repository\SiteRepository; @@ -40,12 +41,14 @@ class XmlCategoryDirector */ private $fileRepository; - public function __construct(array $iblocksForExport) + public function __construct(XmlSetup $setup) { - $this->iblocksForExport = $iblocksForExport; - $this->catalogRepository = new CatalogRepository(); + $this->iblocksForExport = $setup->iblocksForExport; $this->xmlCategoryFactory = new XmlCategoryFactory(); $this->fileRepository = new FileRepository(SiteRepository::getDefaultServerName()); + $this->catalogRepository = new CatalogRepository(); + + $this->catalogRepository->setLoadNotActive($setup->loadNonActivity); } /** diff --git a/intaro.retailcrm/lib/icml/xmlofferdirector.php b/intaro.retailcrm/lib/icml/xmlofferdirector.php index ef175f39..4c7abff1 100644 --- a/intaro.retailcrm/lib/icml/xmlofferdirector.php +++ b/intaro.retailcrm/lib/icml/xmlofferdirector.php @@ -53,12 +53,14 @@ class XmlOfferDirector { $this->setup = $setup; $this->fileRepository = new FileRepository(SiteRepository::getDefaultServerName()); - $this->catalogRepository = new CatalogRepository(); $this->xmlOfferBuilder = new XmlOfferBuilder( $setup, MeasureRepository::getMeasures(), SiteRepository::getDefaultServerName() ); + $this->catalogRepository = new CatalogRepository(); + + $this->catalogRepository->setLoadNotActive($this->setup->loadNonActivity); $this->barcodes = $this->catalogRepository->getBarcodes(); } @@ -71,7 +73,7 @@ class XmlOfferDirector */ public function getXmlOffersPart(SelectParams $param, CatalogIblockInfo $catalogIblockInfo): array { - $ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo, $this->setup->loadNonActivity); + $ciBlockResult = $this->catalogRepository->getProductPage($param, $catalogIblockInfo); $offers = []; $this->xmlOfferBuilder->setServerName($this->fileRepository->getServerName($catalogIblockInfo->productIblockId)); @@ -130,6 +132,7 @@ class XmlOfferDirector $offer->categoryIds = $product->categoryIds; $offer->productName = $product->productName; $offer->url = $this->mergeUrls($product->url, $offer->url); + $offer->activityProduct = $product->activity; } return $xmlOffers; diff --git a/intaro.retailcrm/lib/model/bitrix/xml/xmloffer.php b/intaro.retailcrm/lib/model/bitrix/xml/xmloffer.php index b1e312bd..04390b7a 100644 --- a/intaro.retailcrm/lib/model/bitrix/xml/xmloffer.php +++ b/intaro.retailcrm/lib/model/bitrix/xml/xmloffer.php @@ -28,7 +28,7 @@ class XmlOffer public $productId; /** - * @var int + * @var string */ public $quantity; @@ -136,6 +136,12 @@ class XmlOffer */ public $activity; + /** + * Признак активности товара при наличии торговых предложений + * @var string | null + */ + public ?string $activityProduct = null; + /** * @param $productValue * @param $offerValue diff --git a/intaro.retailcrm/lib/repository/catalogrepository.php b/intaro.retailcrm/lib/repository/catalogrepository.php index 0f7223f1..621a63e2 100644 --- a/intaro.retailcrm/lib/repository/catalogrepository.php +++ b/intaro.retailcrm/lib/repository/catalogrepository.php @@ -31,6 +31,11 @@ class CatalogRepository */ private $builder; + /** + * @var bool + */ + private $isLoadNotActive = false; + /** * CatalogRepository constructor. */ @@ -39,6 +44,11 @@ class CatalogRepository $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\Orm\CatalogIblockInfo $catalogIblockInfo - * @param boolean $loadNonActivity * @return \CIBlockResult|int */ - public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo, bool $loadNonActivity) + public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo) { return CIBlockElement::GetList( ['ID' => 'ASC'], - $this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo, $loadNonActivity), + $this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo, $this->isLoadNotActive), false, ['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true], $param->allParams