1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
store_product.php
См. документацию.
1<?php
3
5
7{
8 protected static function CheckFields($action, &$arFields)
9 {
11 global $APPLICATION;
12 if ((($action == 'ADD') || isset($arFields["STORE_ID"])) && (int)$arFields["STORE_ID"] <= 0)
13 {
14 $APPLICATION->ThrowException(GetMessage("CP_EMPTY_STORE"));
15 return false;
16 }
17 if ((($action == 'ADD') || isset($arFields["PRODUCT_ID"])) && (int)$arFields["PRODUCT_ID"] <= 0)
18 {
19 $APPLICATION->ThrowException(GetMessage("CP_EMPTY_PRODUCT"));
20 return false;
21 }
22 if (!isset($arFields["AMOUNT"]) || !is_numeric($arFields["AMOUNT"]))
23 {
24 $APPLICATION->ThrowException(GetMessage("CP_FALSE_AMOUNT"));
25 return false;
26 }
27
28 return true;
29 }
30
35 public static function UpdateFromForm($arFields)
36 {
38 'select' => ['ID'],
39 'filter' => [
40 '=PRODUCT_ID' => (int)$arFields['PRODUCT_ID'],
41 '=STORE_ID' => (int)$arFields['STORE_ID'],
42 ],
43 ]);
44 $row = $iterator->fetch();
45 unset($iterator);
46 if (!empty($row))
47 {
48 return static::Update($row['ID'], $arFields);
49 }
50 else
51 {
52 return static::Add($arFields);
53 }
54 }
55
56 public static function Update($id, $arFields)
57 {
58 $id = (int)$id;
59
60 foreach(GetModuleEvents("catalog", "OnBeforeStoreProductUpdate", true) as $arEvent)
61 {
62 if (ExecuteModuleEventEx($arEvent, [$id, &$arFields]) === false)
63 {
64 return false;
65 }
66 }
67
68 if ($id < 0 || !static::CheckFields('UPDATE', $arFields))
69 {
70 return false;
71 }
72
73 global $DB;
74
75 $strUpdate = $DB->PrepareUpdate("b_catalog_store_product", $arFields);
76 if ($strUpdate !== '')
77 {
78 $strSql = "UPDATE b_catalog_store_product SET " . $strUpdate . " WHERE ID = " . $id;
79 $DB->Query($strSql);
80 }
81
82 foreach (GetModuleEvents("catalog", "OnStoreProductUpdate", true) as $arEvent)
83 {
84 ExecuteModuleEventEx($arEvent, [$id, $arFields]);
85 }
86
87 return true;
88 }
89
97 public static function OnIBlockElementDelete($productId) {}
98
99 public static function Delete($id)
100 {
101 global $DB;
102 $id = (int)$id;
103 if($id > 0)
104 {
105 foreach(GetModuleEvents("catalog", "OnBeforeStoreProductDelete", true) as $arEvent)
106 {
107 if (ExecuteModuleEventEx($arEvent, [$id]) === false)
108 {
109 return false;
110 }
111 }
112
113 $DB->Query("DELETE FROM b_catalog_store_product WHERE ID = ".$id." ", true);
114
115 foreach(GetModuleEvents("catalog", "OnStoreProductDelete", true) as $arEvent)
116 {
117 ExecuteModuleEventEx($arEvent, [$id]);
118 }
119
120 return true;
121 }
122
123 return false;
124 }
125
126 public static function addToBalanceOfStore($storeId, $productId, $amount)
127 {
128 $productId = (int)$productId;
129 $storeId = (int)$storeId;
130 $amount = (float)$amount;
131 if ($productId <= 0 || $storeId <= 0)
132 {
133 return false;
134 }
136 'select' => [
137 'ID',
138 'AMOUNT',
139 ],
140 'filter' => [
141 '=PRODUCT_ID' => $productId,
142 '=STORE_ID' => $storeId,
143 ],
144 ]);
145 $row = $iterator->fetch();
146 unset($iterator);
147 if (!empty($row))
148 {
149 return static::Update(
150 $row['ID'],
151 [
152 'AMOUNT' => (float)$row['AMOUNT'] + $amount,
153 'PRODUCT_ID' => $productId,
154 'STORE_ID' => $storeId,
155 ]
156 );
157 }
158 else
159 {
160 return static::Add([
161 'PRODUCT_ID' => $productId,
162 'STORE_ID' => $storeId,
163 'AMOUNT' => $amount,
164 ]);
165 }
166 }
167}
global $APPLICATION
Определения include.php:80
static getList(array $parameters=array())
Определения datamanager.php:431
static Delete($id)
Определения store_product.php:99
static addToBalanceOfStore($storeId, $productId, $amount)
Определения store_product.php:126
static UpdateFromForm($arFields)
Определения store_product.php:35
static OnIBlockElementDelete($productId)
Определения store_product.php:97
static CheckFields($action, &$arFields)
Определения store_product.php:8
static Update($id, $arFields)
Определения store_product.php:56
$arFields
Определения dblapprove.php:5
global $DB
Определения cron_frame.php:29
ExecuteModuleEventEx($arEvent, $arParams=[])
Определения tools.php:5214
GetModuleEvents($MODULE_ID, $MESSAGE_ID, $bReturnArray=false)
Определения tools.php:5177
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
GetMessage($name, $aReplace=null)
Определения tools.php:3397
if(!function_exists("bx_hmac")) $amount
Определения payment.php:30
$action
Определения file_dialog.php:21
$iterator
Определения yandex_run.php:610