Answer the question
In order to leave comments, you need to log in
Removing an item from the Bitrix cart?
Guys, how do I remove an item from the cart if two items have the same id?
For example:
three products with the same id were put in the cart, one needs to be removed from the cart, so that the rest would remain?
All three products are deleted by the standard method, how can I delete one product?
Answer the question
In order to leave comments, you need to log in
You do not need to delete this product, but only reduce its quantity, for example like this:
use Bitrix\Sale;
$productId = 1234; // id нашего товара
// получаем корзину пользователя
$basket = Sale\Basket::loadItemsForFUser(
Sale\Fuser::getId(),
Bitrix\Main\Context::getCurrent()->getSite()
);
/** @var Sale\BasketItem $basketItem */
foreach ($basket as $basketItem) {
if ($basketItem->getProductId() == $productId) {
$basketItem->setField('QUANTITY', $basketItem->getQuantity() - 1);
}
}
$basket->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question