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:
parent
380e1f0081
commit
3e5a04af62
@ -25,7 +25,7 @@ CModule::IncludeModule('intaro.retailcrm');
|
||||
|
||||
//TODO заменить вызов на сервис-локатор, когда он приедет
|
||||
$settingsService = SettingsService::getInstance(
|
||||
$arOldSetupVars,
|
||||
$arOldSetupVars ?? [],
|
||||
$ACTION
|
||||
);
|
||||
|
||||
|
@ -2,8 +2,7 @@
|
||||
|
||||
namespace Intaro\RetailCrm\Icml;
|
||||
|
||||
use COption;
|
||||
use Intaro\RetailCrm\Icml\Utils\IcmlUtils;
|
||||
use Bitrix\Catalog\ProductTable;
|
||||
use Intaro\RetailCrm\Model\Bitrix\Orm\CatalogIblockInfo;
|
||||
use Intaro\RetailCrm\Model\Bitrix\Xml\SelectParams;
|
||||
use Intaro\RetailCrm\Model\Bitrix\Xml\XmlData;
|
||||
@ -178,6 +177,7 @@ class IcmlDirector
|
||||
$this->setup->properties->products->names[$productIblockId],
|
||||
$this->setup->basePriceId
|
||||
);
|
||||
|
||||
$paramsForOffer
|
||||
= $this->queryBuilder->getSelectParams(
|
||||
$this->setup->properties->sku->names[$productIblockId],
|
||||
@ -249,6 +249,12 @@ class IcmlDirector
|
||||
$paramsForOffer->allParams = array_merge($paramsForOffer->configurable, $paramsForOffer->main);
|
||||
|
||||
do {
|
||||
//Если каталог проиндексирован, у товара есть Тип и это простой товар, то просто записываем его
|
||||
if ($product->productType = ProductTable::TYPE_PRODUCT) {
|
||||
$this->icmlWriter->writeOffers([$product]);
|
||||
break;
|
||||
}
|
||||
|
||||
$xmlOffersPart
|
||||
= $this->xmlOfferDirector->getXmlOffersBySingleProduct($paramsForOffer, $catalogIblockInfo, $product);
|
||||
|
||||
|
@ -18,23 +18,30 @@ class IcmlWriter
|
||||
{
|
||||
public const INFO = 'INFO';
|
||||
public const CATEGORY_PART = 1000;
|
||||
|
||||
|
||||
/**
|
||||
* @var \XMLWriter
|
||||
*/
|
||||
private $writer;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $filePath;
|
||||
|
||||
/**
|
||||
* 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->openURI($_SERVER['DOCUMENT_ROOT'] . $filePath);
|
||||
$this->writer->setIndent(true);
|
||||
$this->writer->openMemory();
|
||||
$this->writer->setIndent(false);
|
||||
$this->writer->startDocument('1.0', LANG_CHARSET);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlData $data
|
||||
*/
|
||||
@ -42,51 +49,52 @@ class IcmlWriter
|
||||
{
|
||||
$this->writer->startElement('yml_catalog');
|
||||
$this->writeSimpleAttribute('date', Date('Y-m-d H:i:s'));
|
||||
|
||||
|
||||
$this->writer->startElement('shop');
|
||||
$this->writeSimpleElement('name', $data->shopName);
|
||||
$this->writeSimpleElement('company', $data->company);
|
||||
}
|
||||
|
||||
|
||||
public function writeToXmlBottom(): void
|
||||
{
|
||||
$this->writer->endElement();
|
||||
$this->writer->endElement();
|
||||
$this->writer->flush();
|
||||
file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
|
||||
$this->writer->endDocument();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlData $data
|
||||
*/
|
||||
public function writeToXmlHeaderAndCategories(XmlData $data): void
|
||||
{
|
||||
$this->writer->startElement('categories');
|
||||
|
||||
|
||||
foreach ($data->categories as $key => $category) {
|
||||
$this->writeCategory($category);
|
||||
|
||||
|
||||
if (
|
||||
count($data->categories) === $key + 1
|
||||
|| 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->flush();
|
||||
file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
|
||||
}
|
||||
|
||||
|
||||
public function startOffersBlock(): void
|
||||
{
|
||||
$this->writer->startElement('offers');
|
||||
}
|
||||
|
||||
|
||||
public function endBlock(): void
|
||||
{
|
||||
$this->writer->endElement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param XmlOffer[] $offers
|
||||
*/
|
||||
@ -95,10 +103,10 @@ class IcmlWriter
|
||||
foreach ($offers as $offer) {
|
||||
$this->writeOffer($offer);
|
||||
}
|
||||
|
||||
$this->writer->flush();
|
||||
|
||||
file_put_contents($this->filePath, $this->writer->flush(true), FILE_APPEND);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlOffer $offer
|
||||
*/
|
||||
@ -108,15 +116,15 @@ class IcmlWriter
|
||||
$this->writeSimpleAttribute('id', $offer->id);
|
||||
$this->writeSimpleAttribute('productId', $offer->productId);
|
||||
$this->writeSimpleAttribute('quantity', $offer->quantity);
|
||||
|
||||
|
||||
foreach ($offer->categoryIds as $categoryId) {
|
||||
$this->writeSimpleElement('categoryId', $categoryId);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($offer->picture)) {
|
||||
$this->writeSimpleElement('picture', $offer->picture);
|
||||
}
|
||||
|
||||
|
||||
if (!empty($offer->unitCode->code)) {
|
||||
$this->writer->startElement('unit');
|
||||
$this->writeSimpleAttribute('code', $offer->unitCode->code);
|
||||
@ -124,11 +132,11 @@ class IcmlWriter
|
||||
$this->writeSimpleAttribute('sym', $offer->unitCode->sym);
|
||||
$this->writer->endElement();
|
||||
}
|
||||
|
||||
|
||||
foreach ($offer->params as $param) {
|
||||
$this->writeParam($param);
|
||||
}
|
||||
|
||||
|
||||
$this->writeSimpleElement('url', $offer->url);
|
||||
$this->writeSimpleElement('price', $offer->price);
|
||||
$this->writeSimpleElement('name', $offer->name);
|
||||
@ -142,7 +150,7 @@ class IcmlWriter
|
||||
$this->writeOptionalSimpleElement('purchasePrice', $offer->purchasePrice);
|
||||
$this->writer->endElement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Создает ноду, если значение не пустое
|
||||
*
|
||||
@ -155,7 +163,7 @@ class IcmlWriter
|
||||
$this->writeSimpleElement($name, $value);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $value
|
||||
@ -166,7 +174,7 @@ class IcmlWriter
|
||||
$this->writer->text($this->prepareValue($value));
|
||||
$this->writer->endElement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @param $value
|
||||
@ -177,7 +185,7 @@ class IcmlWriter
|
||||
$this->writer->text($this->prepareValue($value));
|
||||
$this->writer->endAttribute();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $text
|
||||
*
|
||||
@ -189,7 +197,7 @@ class IcmlWriter
|
||||
|
||||
return strip_tags($APPLICATION->ConvertCharset($text, 'utf-8', 'utf-8'));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory $category
|
||||
*/
|
||||
@ -202,7 +210,7 @@ class IcmlWriter
|
||||
$this->writeSimpleElement('picture', $category->picture);
|
||||
$this->writer->endElement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param \Intaro\RetailCrm\Model\Bitrix\Xml\OfferParam $param
|
||||
*/
|
||||
@ -214,7 +222,7 @@ class IcmlWriter
|
||||
$this->writer->text($this->prepareValue($param->value));
|
||||
$this->writer->endElement();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $parentId
|
||||
*/
|
||||
|
@ -50,6 +50,7 @@ class QueryParamsMolder
|
||||
'PREVIEW_PICTURE',
|
||||
'DETAIL_PAGE_URL',
|
||||
'CATALOG_QUANTITY',
|
||||
'CATALOG_TYPE',
|
||||
'CATALOG_PRICE_' . $basePriceId,
|
||||
'CATALOG_PURCHASING_PRICE',
|
||||
'EXTERNAL_ID',
|
||||
|
@ -225,6 +225,7 @@ class XmlOfferBuilder
|
||||
{
|
||||
$this->xmlOffer->id = $item['ID'];
|
||||
$this->xmlOffer->productId = $item['ID'];
|
||||
$this->xmlOffer->productType = $item['CATALOG_TYPE'];
|
||||
$this->xmlOffer->quantity = $item['CATALOG_QUANTITY'] ?? '';
|
||||
$this->xmlOffer->url = $item['DETAIL_PAGE_URL']
|
||||
? $this->defaultServerName . $item['DETAIL_PAGE_URL']
|
||||
|
@ -21,104 +21,114 @@ class XmlOffer
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $productId;
|
||||
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $quantity;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $picture;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $url;
|
||||
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
public $price;
|
||||
|
||||
|
||||
/**
|
||||
* Категории, к которым относится товар
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $categoryIds;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $xmlId;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $productName;
|
||||
|
||||
|
||||
/**
|
||||
* @var OfferParam[]
|
||||
*/
|
||||
public $params;
|
||||
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $vendor;
|
||||
|
||||
|
||||
/**
|
||||
* @var Unit
|
||||
*/
|
||||
public $unitCode;
|
||||
|
||||
|
||||
/**
|
||||
* ставка налога (НДС)
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $vatRate;
|
||||
|
||||
|
||||
/**
|
||||
* штрих-код
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $barcode;
|
||||
|
||||
|
||||
/**
|
||||
* Закупочная цена
|
||||
*
|
||||
* @var mixed|null
|
||||
*/
|
||||
public $purchasePrice;
|
||||
|
||||
|
||||
/**
|
||||
* Вес товара
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
public $weight;
|
||||
|
||||
|
||||
/**
|
||||
* Габариты товара
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $dimensions;
|
||||
|
||||
|
||||
/**
|
||||
* Тип каталога
|
||||
* \Bitrix\Catalog\ProductTable::TYPE_PRODUCT - простой товар
|
||||
* \Bitrix\Catalog\ProductTable::TYPE_SKU – товар с торговыми предложениями
|
||||
* \Bitrix\Catalog\ProductTable::TYPE_OFFER – торговое предложение
|
||||
*
|
||||
* @var mixed
|
||||
*/
|
||||
public $productType;
|
||||
|
||||
/**
|
||||
* @param $productValue
|
||||
* @param $offerValue
|
||||
|
@ -93,7 +93,7 @@ class CatalogRepository
|
||||
public function getProductPage(SelectParams $param, CatalogIblockInfo $catalogIblockInfo)
|
||||
{
|
||||
return CIBlockElement::GetList(
|
||||
[],
|
||||
['ID' => 'ASC'],
|
||||
$this->builder->getWhereForOfferPart($param->parentId, $catalogIblockInfo),
|
||||
false,
|
||||
['nPageSize' => $param->nPageSize, 'iNumPage' => $param->pageNumber, 'checkOutOfRange' => true],
|
||||
|
Loading…
Reference in New Issue
Block a user