Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
product.php
1<?php
2
3
5
7use Bitrix\Main\Entity\DataManager;
10
11class Product extends Entity
12{
13 public function getFieldsByExternalId($code)
14 {
15 $result = array();
16
17 Loader::includeModule('iblock');
18 Loader::includeModule('catalog');
19
20 $iblockIds = [];
21 $row = \Bitrix\Catalog\CatalogIblockTable::getList([
22 'select' => ['IBLOCK_ID'],
23 'filter' => ['=IBLOCK.ACTIVE'=>'Y']
24 ]);
25 while ($res = $row->fetch())
26 $iblockIds[] = $res['IBLOCK_ID'];
27
28 //TODO: , product_xml_id .
29 if (empty($iblockIds))
30 {
31 // nothing here
32 }
33 else
34 {
35 $r = \CIBlockElement::GetList(array(),
36 array("=XML_ID" => $code, "ACTIVE" => "Y", "CHECK_PERMISSIONS" => "Y", "IBLOCK_ID"=>$iblockIds),
37 false,
38 false,
39 array("ID", "IBLOCK_ID", "XML_ID", "NAME", "DETAIL_PAGE_URL")
40 );
41 if($ar = $r->GetNext())
42 {
43 $result = $ar;
44 $product = \CCatalogProduct::GetByID($ar["ID"]);
45
46 $result["WEIGHT"] = $product["WEIGHT"];
47 $result["CATALOG_GROUP_NAME"] = $product["CATALOG_GROUP_NAME"];
48
49 $productIBlock = static::getIBlockProduct($ar["IBLOCK_ID"]);
50 $result["IBLOCK_XML_ID"] = $productIBlock[$ar["IBLOCK_ID"]]["XML_ID"];
51 }
52 }
53
54 return $result;
55 }
56
57 public function getCodeAfterDelimiter($code)
58 {
59 $result = '';
60
61 if(mb_strpos($code, '#') !== false)
62 {
63 $code = explode('#', $code);
64 $result = $code[1];
65 }
66 return $result;
67 }
68
69 private static function getIBlockProduct($iblockId)
70 {
71 static $iblock_fields = null;
72
73 if($iblock_fields[$iblockId] == null)
74 {
75 $r = \CIBlock::GetList(array(), array("ID" => $iblockId));
76 if ($ar = $r->Fetch())
77 $iblock_fields[$iblockId] = $ar;
78 }
79 return $iblock_fields;
80 }
81}