Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
pool.php
1<?php
3
5
6class Pool
7{
9 protected $quantities = array();
10
12 protected $items = array();
13
14 public function __construct()
15 {
16 }
17
24 public function get($code)
25 {
26 if (
27 isset($this->quantities[$code])
28 && is_array($this->quantities[$code])
29 )
30 {
31 return array_sum($this->quantities[$code]);
32 }
33
34 return null;
35 }
36
43 public function getByStore($code, $storeId)
44 {
45 if (isset($this->quantities[$code][$storeId]))
46 {
47 return $this->quantities[$code][$storeId];
48 }
49
50 return 0;
51 }
52
57 public function set($code, $quantity)
58 {
59 $storeId = Sale\Configuration::getDefaultStoreId();
60
61 if (!isset($this->quantities[$code][$storeId]))
62 {
63 $this->quantities[$code][$storeId] = 0;
64 }
65
66 $this->quantities[$code][$storeId] = $quantity;
67 }
68
73 public function setByStore($code, $storeId, $quantity)
74 {
75 if (!isset($this->quantities[$code][$storeId]))
76 {
77 $this->quantities[$code][$storeId] = 0;
78 }
79
80 $this->quantities[$code][$storeId] = $quantity;
81 }
82
86 public function delete($code)
87 {
88 if (isset($this->quantities[$code]))
89 {
90 unset($this->quantities[$code]);
91 }
92 }
93
97 public function deleteByStore($code, $storeId)
98 {
99 if (isset($this->quantities[$code][$storeId]))
100 {
101 unset($this->quantities[$code][$storeId]);
102 }
103 }
104
109 public function addItem($code, $item)
110 {
111 if (!array_key_exists($code, $this->items))
112 {
113 $this->items[$code] = $item;
114 }
115 }
116
120 public function getQuantities()
121 {
122 $result = [];
123 foreach ($this->quantities as $code => $item)
124 {
125 $result[$code] = array_sum($item);
126 }
127
128 return $result;
129 }
130
134 public function getQuantitiesWithStore()
135 {
136 return $this->quantities;
137 }
138
142 public function getItems()
143 {
144 return $this->items;
145 }
146}
deleteByStore($code, $storeId)
Definition pool.php:97
getByStore($code, $storeId)
Definition pool.php:43
addItem($code, $item)
Definition pool.php:109
setByStore($code, $storeId, $quantity)
Definition pool.php:73