
1С-Битрикс
- 51 ответ
- 0 вопросов
29
Вклад в тег
use Bitrix\Sale\Compatible\DiscountCompatibility;
use Bitrix\Sale\Basket;
use Bitrix\Sale\Discount\Gift;
use Bitrix\Sale\Fuser;
class DiscountsHelper
{
/**
* Возвращает массив id всех доступных подарков для товара
*
* @param int $productId - идентификатор товара
* @return array - массив с id подарков для товара
*/
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;
}
}
AddEventHandler('main', 'OnBuildGlobalMenu', 'addMenuItem');
function addMenuItem(&$aGlobalMenu, &$aModuleMenu)
{
global $USER;
if ($USER->IsAdmin()) {
$aGlobalMenu['global_menu_custom'] = [
'menu_id' => 'custom',
'text' => 'Bitrix Studio',
'title' => 'Bitrix Studio',
'url' => 'settingss.php?lang=ru',
'sort' => 1000,
'items_id' => 'global_menu_custom',
'help_section' => 'custom',
'items' => [
[
'parent_menu' => 'global_menu_custom',
'sort' => 10,
'url' => 'your_new_page.php?lang=ru',
'text' => 'your_new_page',
'title' => 'your_new_page',
'icon' => 'fav_menu_icon',
'page_icon' => 'fav_menu_icon',
'items_id' => 'menu_custom',
],
[
'parent_menu' => 'global_menu_custom',
'sort' => 20,
'url' => 'your_new_page_2.php?lang=ru',
'text' => 'your_new_page_2',
'title' => 'your_new_page_2',
'icon' => 'fav_menu_icon_2',
'page_icon' => 'fav_menu_icon_2',
'items_id' => 'menu_custom',
],
],
];
}
}