Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
poolquantity.php
1<?php
2
3
5
6
8
14{
15 const POOL_RESERVE_TYPE = 'R';
16 const POOL_QUANTITY_TYPE = 'Q';
17
18 private static $poolList = array();
19 private $typeList = array();
20
26 public static function getInstance($key)
27 {
28 if (!isset(static::$poolList[$key]))
29 {
30 $pool = new static();
31 static::$poolList[$key] = $pool;
32 }
33
34 return static::$poolList[$key];
35 }
36
43 public function get($type, $code)
44 {
45 $pool = $this->getByType($type);
46 return $pool->get($code);
47 }
48
55 public function getByStore($type, $code, $storeId)
56 {
57 $pool = $this->getByType($type);
58 return $pool->getByStore($code, $storeId);
59 }
60
67 public function getByType($type)
68 {
69 if (empty($this->typeList[$type]))
70 {
71 $this->typeList[$type] = new Pool();
72 }
73
74 return $this->typeList[$type];
75 }
76
82 public function getQuantities($type)
83 {
85 $pool = $this->getByType($type);
86 return $pool->getQuantities();
87 }
88
94 public function getQuantitiesWithStore($type)
95 {
96 $pool = $this->getByType($type);
97 return $pool->getQuantitiesWithStore();
98 }
99
105 public function add($type, $code, $value)
106 {
107 $pool = $this->getByType($type);
108 $currentValue = floatval($pool->get($code));
109 $pool->set($code, $currentValue + $value);
110 }
111
117 public function addByStore($type, $code, $storeId, $value)
118 {
119 $pool = $this->getByType($type);
120 $currentValue = floatval($pool->getByStore($code, $storeId));
121 $pool->setByStore($code, $storeId, $currentValue + $value);
122 }
123
129 public function set($type, $code, $value)
130 {
131 $pool = $this->getByType($type);
132 $pool->set($code, $value);
133 }
134
140 public function setByStore($type, $code, $storeId, $value)
141 {
142 $pool = $this->getByType($type);
143 $pool->setByStore($code, $storeId, $value);
144 }
145
150 public function delete($type, $code)
151 {
152 $pool = $this->getByType($type);
153 $pool->delete($code);
154 }
155
159 public function reset($type)
160 {
161 $pool = $this->getByType($type);
162 $list = $pool->getQuantities();
163
164 foreach($list as $itemKey => $itemValue)
165 {
166 $pool->delete($itemKey);
167 }
168 }
169
170}
getByStore($type, $code, $storeId)
setByStore($type, $code, $storeId, $value)
addByStore($type, $code, $storeId, $value)