Server IP : 80.87.202.40 / Your IP : 216.73.216.169 Web Server : Apache System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64 User : bitrix ( 600) PHP Version : 8.2.27 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /home/bitrix/ext_www/ilovecveti.ru/bitrix/modules/sproduction.datasync/lib/ |
Upload File : |
<?php /** * Synchronization of sections * * @mail support@s-production.online * @link s-production.online */ namespace SProduction\Datasync; use Bitrix\Main, Bitrix\Main\Entity, Bitrix\Main\Type, Bitrix\Main\Localization\Loc; Loc::loadMessages(__FILE__); class PortalSections { const SEARCH_FIELD_DEFAULT = 'code'; /** * Get product values by compare table */ public static function getValuesByProfile($store_sect_id, $crm_sect_id=false) { $values = []; // Store section data $store_prod = StoreSections::getById($store_sect_id); // Values if ($store_prod) { $values['active'] = $store_prod['ACTIVE']; $values['name'] = $store_prod['NAME']; $values['code'] = $store_prod['CODE'] ? : $store_prod['ID']; $values['xmlId'] = $store_prod['XML_ID'] ? : $store_prod['CODE']; $values['description'] = $store_prod['DESCRIPTION']; $values['descriptionType'] = $store_prod['DESCRIPTION_TYPE']; $values['sort'] = $store_prod['SORT']; // if ($store_prod['PICTURE']) { // $path = \CFile::GetPath($store_prod['PICTURE']); // if ($path) { // $values['picture'] = Utilities::getImageFieldForCrm($_SERVER['DOCUMENT_ROOT'] . $path); // } // } } // Convert encoding foreach ($values as $k => $value) { $values[$k] = Utilities::convEncForDeal($value); } return $values; } /** * Create new section */ public static function add($iblock_id, $values, $search_value=false, $search_field=false, $parent_section_id = false) { $section_id = false; if ($search_field === false) { $search_field = self::SEARCH_FIELD_DEFAULT; } if ($iblock_id) { $values['iblockId'] = $iblock_id; } $values['iblockSectionId'] = $parent_section_id; if ($search_value) { $values[$search_field] = $search_value; } FileLog::put('(PortalSections::add) fields ' . print_r($values, true)); $resp = Rest::execute('catalog.section.add', [ 'fields' => $values, ]); if (isset($resp['section'])) { $section_id = $resp['section']['id']; } return $section_id; } /** * Update section */ public static function update($section_id, $iblock_id, $values, $parent_section_id = false) { $result = false; if ($iblock_id) { $values['iblockId'] = $iblock_id; } $values['iblockSectionId'] = $parent_section_id; FileLog::put('(PortalSections::update) fields ' . print_r($values, true)); $resp = Rest::execute('catalog.section.update', [ 'id' => $section_id, 'fields' => $values, ]); if (isset($resp['section'])) { $result = true; } return $result; } /** * Delete section */ public static function delete($section_id) { FileLog::put('(PortalSections::delete) id ' . $section_id); Rest::execute('catalog.section.delete', [ 'id' => $section_id, ]); } /** * Get count */ public static function getCount($iblock_id) { $count = 0; $resp = Rest::execute('catalog.section.list', [ 'order' => ['id' => 'asc'], 'filter' => ['iblockId' => $iblock_id], 'select' => ['id'], ], false, true, false); if (isset($resp['total'])) { $count = $resp['total']; } return $count; } /** * Get list */ public static function getList($iblock_id, int $after_id=0, array $select=['id'], $limit=0) { $sections = []; $filter = [ 'iblockId' => $iblock_id, ]; if ($after_id) { $filter['>id'] = $after_id; } $resp = Rest::execute('catalog.section.list', [ 'order' => ['id' => 'asc'], 'filter' => $filter, 'select' => $select, ]); if (isset($resp['sections']) && ! empty($resp['sections'])) { $sections = $resp['sections']; } if ($limit) { $sections = array_slice($sections, 0, $limit); } return $sections; } /** * Find section */ public static function find($iblock_id, $search_value, $search_field=false) { $section_id = false; if ($search_field === false) { $search_field = self::SEARCH_FIELD_DEFAULT; } $filter = [ 'iblockId' => $iblock_id, $search_field => $search_value, ]; $resp = Rest::execute('catalog.section.list', [ 'filter' => $filter, ]); if (isset($resp['sections']) && ! empty($resp['sections'])) { $section_id = $resp['sections'][0]['id']; } return $section_id; } /** * Find section by store section */ public static function findByStore($store_section_id) { $section_id = false; if ($store_section_id) { $store_section = StoreSections::getById($store_section_id); if ($store_section) { $iblock_id = SettingsIblocksProfiles::getCrmIblockId($store_section['IBLOCK_ID']); $crm_search_value = StoreSections::getSearchValue($store_section_id); $section_id = self::find($iblock_id, $crm_search_value); } } return $section_id; } /** * Find section of order */ public static function getById($section_id) { $result = false; $resp = Rest::execute('catalog.section.get', [ 'id' => $section_id, ]); if (isset($resp['section'])) { $result = $resp['section']; } return $result; } }