76 $fields = self::consistentFields($fields);
78 $priceExclusive = $fields[
'priceExclusive'] ?? $fields[
'price'] ?? 0;
79 $basePrice = $fields[
'basePrice'] ?? 0;
82 'QUANTITY' => (float)$fields[
'quantity'] > 0 ? (
float)$fields[
'quantity'] : 1,
83 'PRODUCT_PROVIDER_CLASS' =>
'',
84 'BASKET_CODE' => $fields[
'code'] ??
'',
85 'PRODUCT_ID' => $fields[
'skuId'] ?? $fields[
'productId'] ?? 0,
86 'BASE_PRICE' => $basePrice,
87 'PRICE' => $priceExclusive,
88 'DISCOUNT_PRICE' => 0,
89 'ORIGIN_BASKET_ID' => (int)($fields[
'additionalFields'][
'originBasketId'] ?? 0),
90 'ORIGIN_PRODUCT_ID' => (int)($fields[
'additionalFields'][
'originProductId'] ?? 0),
91 'MANUALLY_EDITED' =>
'Y',
92 'XML_ID' => $fields[
'innerId'],
96 if (isset($fields[
'type']))
98 $type = (int)$fields[
'type'];
100 $item[
'TYPE'] = Internals\Catalog\ProductTypeMapper::getType($type);
103 if (isset($fields[
'name']))
105 $item[
'NAME'] = $fields[
'name'];
108 if (isset($fields[
'sort']))
110 $item[
'SORT'] = (int)$fields[
'sort'];
113 if (isset($fields[
'isCustomPrice']))
115 $item[
'CUSTOM_PRICE'] = $fields[
'isCustomPrice'] ===
'Y' ?
'Y' :
'N';
118 if (isset($fields[
'measureName']))
120 $item[
'MEASURE_NAME'] = $fields[
'measureName'];
123 if (isset($fields[
'measureCode']))
125 $item[
'MEASURE_CODE'] = (int)$fields[
'measureCode'];
128 if (isset($fields[
'weight']))
130 $item[
'WEIGHT'] = $fields[
'weight'];
133 if (isset($fields[
'dimensions']))
135 $item[
'DIMENSIONS'] = $fields[
'dimensions'];
139 isset($fields[
'taxIncluded'], $fields[
'taxId'])
140 && Main\Loader::includeModule(
'catalog')
143 $rateRow = VatTable::getRowById((
int)$fields[
'taxId']);
147 isset($rateRow[
'RATE'])
148 ? (float)$rateRow[
'RATE'] / 100
153 $item[
'VAT_INCLUDED'] = $fields[
'taxIncluded'] ===
'N' ?
'N' :
'Y';
156 if (isset($fields[
'skuId']) && $fields[
'skuId'])
158 $item[
'PRODUCT_ID'] = $fields[
'skuId'];
162 isset($fields[
'module'])
163 && $fields[
'module'] ===
'catalog'
164 && Main\Loader::includeModule(
'catalog')
167 $item[
'MODULE'] =
'catalog';
168 $item[
'PRODUCT_PROVIDER_CLASS'] = Product\Basket::getDefaultProviderName();
172 (
int)$fields[
'discount'] === 0
173 && abs($priceExclusive - $basePrice) > 1e-10
174 && (
float)$basePrice > 0
177 $fields[
'discount'] = (int)(100 - ($priceExclusive / $basePrice) * 100);
180 if ($fields[
'discount'] > 0)
182 $item[
'DISCOUNT_PRICE'] = $fields[
'discount'];
183 $item[
'CUSTOM_PRICE'] =
'Y';
184 $item[
'PRICE'] = $item[
'BASE_PRICE'] - $item[
'DISCOUNT_PRICE'];
187 if (isset($fields[
'properties']))
191 foreach ($fields[
'properties'] as $property)
193 if (!in_array($property[
'CODE'], $allowedProps))
201 !empty($property[
'PROPERTY_VALUES'])
202 && is_array($property[
'PROPERTY_VALUES'])
205 $value = current($property[
'PROPERTY_VALUES']);
206 $value = $value[
'DISPLAY_VALUE'] ??
'';
210 'NAME' => $property[
'NAME'],
211 'SORT' => $property[
'SORT'],
212 'CODE' => $property[
'CODE'],
218 $item[
'FIELDS_VALUES'] = Main\Web\Json::encode($item);
229 if (!Main\Loader::includeModule(
'catalog') || !Main\Loader::includeModule(
'iblock'))
234 $product = \CIBlockElement::GetList([], [
'=ID' => $productId],
false,
false, [
'IBLOCK_ID'])->Fetch();
236 if (is_array($product) && isset($product[
'IBLOCK_ID']))
238 $iblockId = (int)$product[
'IBLOCK_ID'];
246 static $allowedPropertyCodes = [];
247 if (!array_key_exists($iblockId, $allowedPropertyCodes))
249 $propertyCodes = Product\PropertyCatalogFeature::getBasketPropertyCodes($iblockId, [
'CODE' =>
'Y']);
250 $allowedPropertyCodes[$iblockId] = is_array($propertyCodes) ? $propertyCodes : [];
253 return $allowedPropertyCodes[$iblockId];