Answer the question
In order to leave comments, you need to log in
How do I change the product name when adding a product to the cart?
Hey!
I add a product (by trading application ID) using the code:
$Cart = Sale\Basket::loadItemsForFUser(Sale\Fuser::getId(), Bitrix\Main\Context::getCurrent()->getSite());
$item = $Cart->createItem('catalog', 6667);
$item->setFields(array(
'NAME' => 'Новое название - '.$Price,
'CURRENCY' => 'RUB',
'NOTES' => $Price,
'QUANTITY' => 1,
'LID' => Bitrix\Main\Context::getCurrent()->getSite(),
'PRICE' => -(int)$Price,
'CUSTOM_PRICE' => 'Y',
));
$Cart->save();
Answer the question
In order to leave comments, you need to log in
Solution: Forget about Bitrix as a mountain of development by shit developers from Russia and use normal frameworks like Laravel!
\Bitrix\Main\EventManager::getInstance()->addEventHandler(
'sale',
'OnSaleBasketItemBeforeSaved',
'OnSaleBasketItemBeforeSavedHandler'
);
function OnSaleBasketItemBeforeSavedHandler(\Bitrix\Main\Event $event) {
$basketItem = $event->getParameter('ENTITY');
$oldValues = $event->getParameter("VALUES");
//пересохраняем название товара если оно было изменено обработчиком при добавлении в корзину
if (!empty($oldValues["NAME"])) {
$basketItem->setField('NAME', $oldValues["NAME"]);
}
return new \Bitrix\Main\EventResult(\Bitrix\Main\EventResult::SUCCESS);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question