As for Bitrix to check whether the product presents?

Dear tell me how can I make the item card check for gift the product to?

Does bitrix api ready methods?
June 14th 19 at 20:23
1 answer
June 14th 19 at 20:25
I once wrote a method that for product id returns the id array of gifts. Can use:
use Bitrix\Sale\Compatible\DiscountCompatibility;
use Bitrix\Sale\Basket;
use Bitrix\Sale\Discount\ \ Gift;
use Bitrix\Sale\Fuser;

class DiscountsHelper
{
/**
 * Returns an array of the IDs of all the available gifts for the item
*
 * @param int $productId - a product identifier
 * @return array array with id gifts for the item
*/
 public static function getGiftIds($productId)
{
 $giftProductIds = [];

 if (!$productId) {
 return $giftProductIds;
}

DiscountCompatibility::stopUsageCompatible();

 $giftManager = Gift\Manager::getInstance();

 $potentialBuy = [
 'ID' => $productId,
 'MODULE' => 'catalog',
 'PRODUCT_PROVIDER_CLASS' => 'CCatalogProductProvider',
 'QUANTITY' => 1,
];

 $basket = Basket::loadItemsForFUser(Fuser::getId(), SITE_ID);

 $basketPseudo = $basket->copy();

 foreach ($basketPseudo as $basketItem) {
$basketItem->delete();
}

 $collections = $giftManager->getCollectionsByProduct($basketPseudo, $potentialBuy);

 foreach ($collections as $collection) {
 /** @var \Bitrix\Sale\Discount\ \ Gift\Gift $gift */
 foreach ($collection as $gift) {
 $giftProductIds[] = $gift->getProductId();
}
}

DiscountCompatibility::revertUsageCompatible();

 return $giftProductIds;
}
}


The point is, we create an empty pseudococaine and based on it determine whether the passed item gifts.

Find more questions by tags 1C-Bitrix