1
0
mirror of synced 2024-11-25 14:56:09 +03:00

Catalog fix

* add empty array Instead of  and add xml-header with charsets
* fix catalog purchasePrice
* use file_put_contents for flush
This commit is contained in:
Сергей Чазов 2021-11-02 11:25:26 +03:00 committed by GitHub
parent 380e1f0081
commit 3e5a04af62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 82 additions and 56 deletions

View File

@ -25,7 +25,7 @@ CModule::IncludeModule('intaro.retailcrm');
//TODO заменить вызов на сервис-локатор, когда он приедет //TODO заменить вызов на сервис-локатор, когда он приедет
$settingsService = SettingsService::getInstance( $settingsService = SettingsService::getInstance(
$arOldSetupVars, $arOldSetupVars ?? [],
$ACTION $ACTION
); );

View File

@ -2,8 +2,7 @@
namespace Intaro\RetailCrm\Icml; namespace Intaro\RetailCrm\Icml;
use COption; use Bitrix\Catalog\ProductTable;
use Intaro\RetailCrm\Icml\Utils\IcmlUtils;
use Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo; use Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo;
use Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams; use Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams;
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlData; use Intaro\RetailCrm\Model\Bitrix\Xml\XmlData;
@ -178,6 +177,7 @@ class IcmlDirector
$this->setup->properties->products->names[$productIblockId], $this->setup->properties->products->names[$productIblockId],
$this->setup->basePriceId $this->setup->basePriceId
); );
$paramsForOffer $paramsForOffer
= $this->queryBuilder->getSelectParams( = $this->queryBuilder->getSelectParams(
$this->setup->properties->sku->names[$productIblockId], $this->setup->properties->sku->names[$productIblockId],
@ -249,6 +249,12 @@ class IcmlDirector
$paramsForOffer->allParams = array_merge($paramsForOffer->configurable, $paramsForOffer->main); $paramsForOffer->allParams = array_merge($paramsForOffer->configurable, $paramsForOffer->main);
do { do {
//Если каталог проиндексирован, у товара есть Тип и это простой товар, то просто записываем его
if ($product->productType = ProductTable::TYPE_PRODUCT) {
$this->icmlWriter->writeOffers([$product]);
break;
}
$xmlOffersPart $xmlOffersPart
= $this->xmlOfferDirector->getXmlOffersBySingleProduct($paramsForOffer, $catalogIblockInfo, $product); = $this->xmlOfferDirector->getXmlOffersBySingleProduct($paramsForOffer, $catalogIblockInfo, $product);

View File

@ -23,16 +23,23 @@ class IcmlWriter
* @var \XMLWriter * @var \XMLWriter
*/ */
private $writer; private $writer;
/**
* @var string
*/
private $filePath;
/** /**
* IcmlWriter constructor. * IcmlWriter constructor.
* @param $filePath *
* @param string $filePath
*/ */
public function __construct($filePath) public function __construct(string $filePath)
{ {
$this->filePath = $filePath;
$this->writer = new XMLWriter(); $this->writer = new XMLWriter();
$this->writer->openURI($_SERVER['DOCUMENT_ROOT'] . $filePath); $this->writer->openMemory();
$this->writer->setIndent(true); $this->writer->setIndent(false);
$this->writer->startDocument('1.0', LANG_CHARSET);
} }
/** /**
@ -52,7 +59,8 @@ class IcmlWriter
{ {
$this->writer->endElement(); $this->writer->endElement();
$this->writer->endElement(); $this->writer->endElement();
$this->writer->flush(); file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
$this->writer->endDocument();
} }
/** /**
@ -69,12 +77,12 @@ class IcmlWriter
count($data->categories) === $key + 1 count($data->categories) === $key + 1
|| is_int(count($data->categories) / self::CATEGORY_PART) || is_int(count($data->categories) / self::CATEGORY_PART)
) { ) {
$this->writer->flush(); file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
} }
} }
$this->writer->endElement(); $this->writer->endElement();
$this->writer->flush(); file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
} }
public function startOffersBlock(): void public function startOffersBlock(): void
@ -96,7 +104,7 @@ class IcmlWriter
$this->writeOffer($offer); $this->writeOffer($offer);
} }
$this->writer->flush(); file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
} }
/** /**

View File

@ -50,6 +50,7 @@ class QueryParamsMolder
'PREVIEW_PICTURE', 'PREVIEW_PICTURE',
'DETAIL_PAGE_URL', 'DETAIL_PAGE_URL',
'CATALOG_QUANTITY', 'CATALOG_QUANTITY',
'CATALOG_TYPE',
'CATALOG_PRICE_' . $basePriceId, 'CATALOG_PRICE_' . $basePriceId,
'CATALOG_PURCHASING_PRICE', 'CATALOG_PURCHASING_PRICE',
'EXTERNAL_ID', 'EXTERNAL_ID',

View File

@ -225,6 +225,7 @@ class XmlOfferBuilder
{ {
$this->xmlOffer->id = $item['ID']; $this->xmlOffer->id = $item['ID'];
$this->xmlOffer->productId = $item['ID']; $this->xmlOffer->productId = $item['ID'];
$this->xmlOffer->productType = $item['CATALOG_TYPE'];
$this->xmlOffer->quantity = $item['CATALOG_QUANTITY'] ?? ''; $this->xmlOffer->quantity = $item['CATALOG_QUANTITY'] ?? '';
$this->xmlOffer->url = $item['DETAIL_PAGE_URL'] $this->xmlOffer->url = $item['DETAIL_PAGE_URL']
? $this->defaultServerName . $item['DETAIL_PAGE_URL'] ? $this->defaultServerName . $item['DETAIL_PAGE_URL']

View File

@ -119,6 +119,16 @@ class XmlOffer
*/ */
public $dimensions; public $dimensions;
/**
* Тип каталога
* \Bitrix\Catalog\ProductTable::TYPE_PRODUCT - простой товар
* \Bitrix\Catalog\ProductTable::TYPE_SKU товар с торговыми предложениями
* \Bitrix\Catalog\ProductTable::TYPE_OFFER торговое предложение
*
* @var mixed
*/
public $productType;
/** /**
* @param $productValue * @param $productValue
* @param $offerValue * @param $offerValue

View File

@ -93,7 +93,7 @@ class CatalogRepository
public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo) public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo)
{ {
return CIBlockElement::GetList( return CIBlockElement::GetList(
[], ['ID' => 'ASC'],
$this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo), $this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo),
false, false,
['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true], ['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true],