Answer the question
In order to leave comments, you need to log in
Bitrix. How to apply the function only to the product being added to the cart?
Good afternoon.
I change the price of the product when adding to the cart to my own.
In init.php, this code changes the item price to 2000 for all items in the cart.
How to change the price for only one added product?
class CCatalogProductProviderCustom extends CCatalogProductProvider {
public static function GetProductData($arParams) {
$arResult = parent::GetProductData($arParams);
$i++;
$arResult = [
'BASE_PRICE' => '2000', // ПРИМЕНЯЕТСЯ КО ВСЕМ ТОВАРАМ В КОРЗИНЕ
]
+
$arResult;
return $arResult;
}
}
addEventHandler(
'sale',
'OnSaleBasketItemRefreshData',
'BeforeBasketAddHandler'
);
function BeforeBasketAddHandler($BasketItem) {
$BasketItem->setField(
"PRODUCT_PROVIDER_CLASS",
"CCatalogProductProviderCustom"
);
}
Answer the question
In order to leave comments, you need to log in
I can offer several options for testing:
1) instead of setField, try setFieldNoDemand
2) after setField $basketItem->save();
3) the BasketItem class object has a setPrice method
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question