Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
elementcatalog.php
1<?php
8
10
11class ElementCatalog extends Base
12{
13 protected $price = null;
14 protected $sku = null;
15 protected $store = null;
16
20 public function __construct($id)
21 {
22 parent::__construct($id);
23 $this->fieldMap = array(
24 "weight" => "WEIGHT",
25 "measure" => "MEASURE",
26 "store" => "STORE",
27 );
28 }
29
37 public function resolve($entity)
38 {
39 if ($entity === "price")
40 {
41 if (!$this->price && $this->loadFromDatabase())
42 {
43 $this->price = new ElementPrice($this->id);
44 }
45
46 if ($this->price)
47 return $this->price;
48 }
49 elseif ($entity === "sku")
50 {
51 if (!$this->sku && $this->loadFromDatabase())
52 {
53 $this->sku = new ElementSku($this->id);
54 }
55
56 if ($this->sku)
57 return $this->sku;
58 }
59 elseif ($entity === "store")
60 {
61 if (!$this->store)
62 {
63 $this->store = new CatalogStore(0);
64 }
65
66 if ($this->store)
67 return $this->store;
68 }
69 return parent::resolve($entity);
70 }
71
79 public function setFields(array $fields)
80 {
81 parent::setFields($fields);
82 if (
83 is_array($this->fields)
84 && $this->fields["MEASURE"] > 0
85 )
86 {
87 $this->fields["MEASURE"] = new ElementCatalogMeasure($this->fields["MEASURE"]);
88 }
89 }
90
97 protected function loadFromDatabase()
98 {
99 if (!isset($this->fields))
100 {
101 $this->fields =Catalog\ProductTable::getRow([
102 'filter' => [
103 '=ID' => $this->id,
104 ],
105 ]);
106 if (is_array($this->fields))
107 {
108 if ($this->fields['MEASURE'] > 0)
109 {
110 $this->fields['MEASURE'] = new ElementCatalogMeasure($this->fields['MEASURE']);
111 }
112 $this->fields['STORE'] = new ElementCatalogStoreList(0);
113 }
114 else
115 {
116 $this->fields = [
117 'STORE' => new ElementCatalogStoreList(0),
118 ];
119 }
120 }
121
122 return true;
123 }
124}
125
127{
133 protected function load()
134 {
135 $measureList = \CCatalogMeasure::getList(array(), array(
136 "ID" => $this->key
137 ), false, false, array("MEASURE_TITLE"));
138 $measure = $measureList->fetch();
139 if ($measure)
140 return $measure['MEASURE_TITLE'];
141 else
142 return "";
143 }
144}
145
147{
153 protected function load()
154 {
155 $storeList = \CCatalogStore::getList(array(), array(
156 "ACTIVE" => "Y",
157 ), false, false, array("ID", "TITLE", "ACTIVE"));
158 $result = array();
159 while($ar = $storeList->fetch())
160 {
161 $result[] = $ar["TITLE"];
162 }
163 return $result;
164 }
165}