use \Bitrix\Main\Loader;
Loader::includeModule('sale');
$fuser = \Bitrix\Sale\FUser::getId();
$site = 's3';
$obBasket = \Bitrix\Sale\Basket::loadItemsForFUser(
$fuser,
$site
);
$items = $obBasket->getOrderableItems();
$bHasItem = false;
$thisItem = false;
$itemId = false;
foreach ($items as $item)
{
if ($item->getField('PRODUCT_ID') !== $id) continue;
$thisItem = $item;
$bHasItem = true;
$itemId = $item->getId();
}
if ($bHasItem)
{
$item2Delete = $obBasket->getItemById($itemId);
var_dump($item2Delete);
$rsDelete = $item2Delete->delete();
self::log($rsDelete->isSuccess(), 'logs/deleteitem.log');
if ($rsDelete->isSuccess())
{
$rsSaved = $obBasket->save();
if (!$rsSaved->isSuccess())
{
var_dump($rsSaved->getErrorMessages()); // Количество товара "Товар1" не может быть меньше или равным 0
}
}
}
Bitrix\Main\Loader::includeModule('sale');
$siteId = 's1';
$fUserId = \Bitrix\Sale\FUser::getId();
$productId = 139;
$productByBasketItem = null;
$bProductInBasket = false;
$basket = \Bitrix\Sale\Basket::loadItemsForFUser($fUserId, $siteId);
$basketItems = $basket->getBasketItems();
if($basketItems) {
foreach($basketItems as $basketItem) {
if($basketItem->getField('PRODUCT_ID') == $productId) {
$productByBasketItem = $basketItem;
$bProductInBasket = true;
break;
}
}
}
if($productByBasketItem) {
$productByBasketItem->delete();
$basket->save();
}
if ($rs-Delete->isSuccess())