1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
basket_helper.php
См. документацию.
1<?
3
5{
6 /*
7 * Checks if basket item belongs to set (is parent or item of the set)
8 *
9 * @param $arItem - basket item fields array with SET_PARENT_ID and TYPE fields
10 * @return bool
11 */
12 public static function isInSet($arItem)
13 {
14 if (!empty($arItem["SET_PARENT_ID"]))
15 return true;
16
17 return false;
18 }
19
20 /*
21 * Checks if basket item is set item (belongs to set, but not parent)
22 *
23 * @param $arItem - basket item fields array with SET_PARENT_ID and TYPE fields
24 * @return bool
25 */
26 public static function isSetItem($arItem)
27 {
28 $adminSection = (defined('ADMIN_SECTION') && ADMIN_SECTION === true);
29
30 if (isset($arItem["SET_PARENT_ID"]) && empty($arItem["TYPE"]))
31 {
32 if (
33 ($adminSection && $arItem["SET_PARENT_ID"] != '' && $arItem["SET_PARENT_ID"] != 0)
34 ||
35 intval($arItem["SET_PARENT_ID"]) > 0
36 )
37 return true;
38 }
39
40 return false;
41 }
42
43 /*
44 * Checks if basket item is parent of the set
45 *
46 * @param $arItem - basket item fields array with SET_PARENT_ID and TYPE fields
47 * @return bool
48 */
49 public static function isSetParent($arItem)
50 {
51 return (isset($arItem["TYPE"]) && (int)$arItem["TYPE"] == CSaleBasket::TYPE_SET);
52 }
53
54 /*
55 * Checks if ALL set items are deducted (to update DEDUCTED = Y of the set parent)
56 *
57 * @param int $setParentID - set parent id
58 * @return bool
59 */
60 public static function isSetDeducted($setParentID)
61 {
62 global $DB;
63
64 $setParentID = intval($setParentID);
65 $bItemFound = false;
66
67 if ($setParentID <= 0)
68 return false;
69
70 $dbres = $DB->Query("SELECT ID, DEDUCTED FROM b_sale_basket WHERE SET_PARENT_ID = ".$setParentID." AND (TYPE IS NULL OR TYPE = '0')", true);
71
72 while ($arItem = $dbres->GetNext())
73 {
74 $bItemFound = true;
75 if ($arItem["DEDUCTED"] == "N")
76 return false;
77 }
78
79 if ($bItemFound)
80 return true;
81 else
82 return false;
83 }
84
91 public static function cmpSetData($arBasketItemA, $arBasketItemB)
92 {
93 if ($arBasketItemA["SET_PARENT_ID"] == "")
94 return 0;
95
96 if ($arBasketItemA["TYPE"] == CSaleBasket::TYPE_SET)
97 return -1;
98 else
99 return 1;
100 }
101
102
103 public static function cmpBySort($array1, $array2)
104 {
105 if (!isset($array1["SORT"])
106 || !isset($array2["SORT"])
107 || ($array1["SORT"] < $array2["SORT"]))
108 return -1;
109
110 if ($array1["SORT"] > $array2["SORT"])
111 return 1;
112
113 if ($array1["SORT"] == $array2["SORT"])
114 return 0;
115 }
116
117
118
119 public static function filterFields($field)
120 {
121 if ($field === false || $field === null)
122 {
123 return false;
124 }
125
126 return true;
127 }
128
135 public static function reSortItems($basketItems, $setIndexAsId = false)
136 {
137 $basketItemsTmp = $basketItems;
138 $parentItems = array();
139 $parentItemFound = false;
140 foreach ($basketItemsTmp as $basketItemKey => $basketItem)
141 {
142 if (CSaleBasketHelper::isSetParent($basketItem) || CSaleBasketHelper::isSetItem($basketItem))
143 {
144 $parentItemFound = true;
145 if (!array_key_exists($basketItem['SET_PARENT_ID'], $parentItems))
146 {
147 $parentItems[$basketItem['SET_PARENT_ID']] = array();
148 }
149
150 if (CSaleBasketHelper::isSetItem($basketItem))
151 {
152 $parentItems[$basketItem['SET_PARENT_ID']][] = $basketItem;
153 unset($basketItemsTmp[$basketItemKey]);
154 }
155 }
156 }
157
158 if ($parentItemFound === true && !empty($basketItemsTmp) && is_array($basketItemsTmp)
159 && !empty($parentItems) && is_array($parentItems))
160 {
161 $basketItems = array();
162 foreach ($basketItemsTmp as $basketItem)
163 {
164 if ($setIndexAsId === true)
165 {
166 $basketItems[$basketItem['ID']] = $basketItem;
167 }
168 else
169 {
170 $basketItems[] = $basketItem;
171 }
172
173 if (array_key_exists($basketItem['ID'], $parentItems))
174 {
175 foreach ($parentItems[$basketItem['ID']] as $childItem)
176 {
177 if ($setIndexAsId === true)
178 {
179 $basketItems[$childItem['ID']] = $childItem;
180 }
181 else
182 {
183 $basketItems[] = $childItem;
184 }
185 }
186 }
187 }
188 }
189
190 return $basketItems;
191 }
192
193
199 public static function getVat(array $basketItemData)
200 {
201 if (empty($basketItemData['VAT_RATE']) || $basketItemData['VAT_RATE'] == 0)
202 return 0;
203
204 if (isset($basketItemData['VAT_INCLUDED']) && $basketItemData['VAT_INCLUDED'] === 'N')
205 {
206 $vat = \Bitrix\Sale\PriceMaths::roundPrecision(($basketItemData['PRICE'] * $basketItemData['QUANTITY'] * $basketItemData['VAT_RATE']));
207 }
208 else
209 {
210 $vat = \Bitrix\Sale\PriceMaths::roundPrecision(($basketItemData['PRICE'] * $basketItemData['QUANTITY'] * $basketItemData['VAT_RATE'] / ($basketItemData['VAT_RATE'] + 1)));
211 }
212
213 return $vat;
214 }
215
216 public static function getPriceTypeName(array $basketItemData): string
217 {
218 static $priceTypeList = null;
219
220 if ($priceTypeList === null)
221 {
222 $priceTypeList = [];
223 if (Loader::includeModule('catalog'))
224 {
226 }
227 }
228
229 $result = '';
230 if (isset($basketItemData['NOTES']) && $basketItemData['NOTES'] !== '')
231 {
232 $result = $basketItemData['NOTES'];
233 }
234 elseif (isset($basketItemData['PRICE_TYPE_ID']))
235 {
236 $typeid = (int)$basketItemData['PRICE_TYPE_ID'];
237 if (isset($priceTypeList[$typeid]))
238 {
239 $result = $priceTypeList[$typeid]['NAME_LANG'] ?: $priceTypeList[$typeid]['NAME'];
240 }
241 }
242
243 return $result;
244 }
245
251 public static function getFinalPrice(array $basketItemData)
252 {
253 $price = \Bitrix\Sale\PriceMaths::roundPrecision($basketItemData['PRICE'] * $basketItemData['QUANTITY']);
254 if (isset($basketItemData['VAT_INCLUDED']) && $basketItemData['VAT_INCLUDED'] === 'N')
255 {
256 $price += static::getVat($basketItemData);
257 }
258 return $price;
259 }
260
267 public static function formatQuantity($quantity)
268 {
269 $isOrderConverted = \Bitrix\Main\Config\Option::get("main", "~sale_converted_15", 'Y');
270
271 if ($isOrderConverted != 'N')
272 {
273 return \Bitrix\Sale\BasketItem::formatQuantity($quantity);
274 }
275
276 return roundEx($quantity, SALE_VALUE_PRECISION);
277 }
278
279}
static get($moduleId, $name, $default="", $siteId=false)
Определения option.php:30
Определения loader.php:13
static roundPrecision($value)
Определения pricemaths.php:16
static GetListArray()
Определения cataloggroup.php:291
const TYPE_SET
Определения basket.php:13
static getVat(array $basketItemData)
Определения basket_helper.php:199
static reSortItems($basketItems, $setIndexAsId=false)
Определения basket_helper.php:135
static isSetParent($arItem)
Определения basket_helper.php:49
static isSetDeducted($setParentID)
Определения basket_helper.php:60
static isInSet($arItem)
Определения basket_helper.php:12
static isSetItem($arItem)
Определения basket_helper.php:26
static getFinalPrice(array $basketItemData)
Определения basket_helper.php:251
static getPriceTypeName(array $basketItemData)
Определения basket_helper.php:216
static formatQuantity($quantity)
Определения basket_helper.php:267
static filterFields($field)
Определения basket_helper.php:119
static cmpBySort($array1, $array2)
Определения basket_helper.php:103
static cmpSetData($arBasketItemA, $arBasketItemB)
Определения basket_helper.php:91
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $DB
Определения cron_frame.php:29
roundEx($value, $prec=0)
Определения tools.php:4635
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
const ADMIN_SECTION
Определения rss.php:2
$vat
Определения template.php:273
const SALE_VALUE_PRECISION
Определения include.php:46
if(!empty($XML_DATA['PRICE'])) $priceTypeList
Определения yandex_run.php:872