1
0
mirror of synced 2024-11-22 13:26:10 +03:00
bitrix-module/intaro.retailcrm/lib/icml/xmlcategoryfactory.php
Сергей Чазов a4c06ed8ee
New ICML generator
2021-05-31 16:33:02 +03:00

44 lines
1.4 KiB
PHP

<?php
namespace Intaro\RetailCrm\Icml;
use Bitrix\Main\ArgumentException;
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\Repository\CatalogRepository;
use Intaro\RetailCrm\Repository\FileRepository;
use Intaro\RetailCrm\Repository\SiteRepository;
/**
* Отвечает за создание XmlCategory
*
* Class XmlCategoryFactory
* @package Intaro\RetailCrm\Icml
*/
class XmlCategoryFactory
{
/**
* @param \Bitrix\Main\ORM\Objectify\EntityObject $category
* @param string $picture
* @param int|null $categoryId
*
* @return \Intaro\RetailCrm\Model\Bitrix\Xml\XmlCategory|null
*/
public function create(EntityObject $category, string $picture, int $categoryId = null): ?XmlCategory
{
try {
$xmlCategory = new XmlCategory();
$xmlCategory->id = $categoryId ?? $category->get('ID');
$xmlCategory->name = $category->get('NAME');
$xmlCategory->parentId = $categoryId ? 0 : $category->get('IBLOCK_SECTION_ID');
$xmlCategory->picture = $picture;
} catch (ArgumentException | SystemException $exception) {
return null;
}
return $xmlCategory;
}
}