1
0
mirror of synced 2024-11-23 05:46:09 +03:00
bitrix-module/intaro.retailcrm/lib/icml/xmlcategoryfactory.php

44 lines
1.4 KiB
PHP
Raw Normal View History

2021-05-31 16:33:02 +03:00
<?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;
}
}