Last active
June 18, 2024 09:46
-
-
Save EscApp2/90a51b4784b405dab5c7e4214f524edf to your computer and use it in GitHub Desktop.
Нужно сделать так, чтобы в корзине выводилось наименование самого товара, а не ТП name sku
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/* | |
* Нужно сделать так, чтобы в корзине выводилось | |
* наименование самого товара, а не ТП | |
* */ | |
$eventManager = \Bitrix\Main\EventManager::getInstance(); //подписываем обработчик на событие | |
$eventManager->addEventHandler( | |
"sale", | |
'OnBeforeSaleBasketItemSetField', | |
"OnBeforeSaleBasketItemSetField" | |
); | |
function OnBeforeSaleBasketItemSetField(\Bitrix\Main\Event $event) | |
{ | |
$name = $event->getParameter('NAME'); | |
//$value = $event->getParameter('VALUE'); | |
$obBaskeItem = $event->getParameter('ENTITY'); | |
if ($name === 'NAME') { | |
\Bitrix\Main\Loader::includeModule('catalog'); | |
$PRODUCT_ID = $obBaskeItem->getField('PRODUCT_ID'); | |
$mxResult = CCatalogSku::GetProductInfo($PRODUCT_ID); | |
if ($mxResult) { | |
\Bitrix\Main\Loader::includeModule('iblock'); | |
$arResult = \Bitrix\Iblock\ElementTable::getList(array( | |
'select' => array('ID', 'NAME', 'IBLOCK_ID', 'CODE'), | |
'filter' => array('=ID' => $mxResult['ID'], 'IBLOCK_ID' => $mxResult['IBLOCK_ID']), | |
'cache' => array( // Кеш запроса. Сброс можно сделать методом \Bitrix\Iblock\ElementTable::getEntity()->cleanCache(); | |
'ttl' => 10, // Время жизни кеша | |
'cache_joins' => true // Кешировать ли выборки с JOIN | |
), | |
))->fetchAll(); | |
if ($arResult && is_array($arResult) && count($arResult) > 0) { | |
$event->addResult( | |
new \Bitrix\Main\EventResult( | |
\Bitrix\Main\EventResult::SUCCESS, array('VALUE' => $arResult[0]['NAME']) | |
) | |
); | |
} | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
/* | |
* Нужно сделать так, чтобы в корзину попадали товары | |
* в зависимости от группы пользователя | |
* */ | |
$eventManager = \Bitrix\Main\EventManager::getInstance(); //подписываем обработчик на событие | |
$eventManager->addEventHandler( | |
"sale", | |
'OnSaleBasketBeforeSaved', | |
"OnSaleBasketBeforeSaved_38945" | |
); | |
function OnSaleBasketBeforeSaved_38945(\Bitrix\Main\Event $event) | |
{ | |
$obBasket = $event->getParameter('ENTITY'); | |
$orderBasket = $obBasket->getBasketItems(); | |
$error = false; | |
foreach($orderBasket as $obBaskeItem){ | |
$PRODUCT_ID = $obBaskeItem->getField('PRODUCT_ID'); | |
\Bitrix\Main\Loader::includeModule('catalog'); | |
$PRODUCT_ID = $obBaskeItem->getField('PRODUCT_ID'); | |
$mxResult = CCatalogSku::GetProductInfo($PRODUCT_ID); | |
if ($mxResult) { | |
\Bitrix\Main\Loader::includeModule('iblock'); | |
$arResult = \Bitrix\Iblock\ElementTable::getList(array( | |
'select' => array('ID', 'NAME', 'IBLOCK_ID', 'CODE'), | |
'filter' => array('=ID' => $mxResult['ID'], 'IBLOCK_ID' => $mxResult['IBLOCK_ID']), | |
'cache' => array( // Кеш запроса. Сброс можно сделать методом \Bitrix\Iblock\ElementTable::getEntity()->cleanCache(); | |
'ttl' => 10, // Время жизни кеша | |
'cache_joins' => true // Кешировать ли выборки с JOIN | |
), | |
))->fetchAll(); | |
if ($arResult && is_array($arResult) && count($arResult) > 0) { | |
$PRODUCT_ID = $arResult[0]['ID']; | |
} | |
} | |
if($PRODUCT_ID){ | |
$can = canUserSeeThisElement($PRODUCT_ID); | |
if(!$can){ | |
$obBaskeItem->delete(); // Удаление | |
$obBasket->save(); | |
$error = true; | |
} | |
} | |
} | |
if($error){ | |
$event->addResult(new \Bitrix\Main\EventResult( | |
\Bitrix\Main\EventResult::ERROR, | |
new \Bitrix\Sale\ResultError('Вы не можете добавить этот товар в корзину', 'PRODUCT_GROUP_INVALID'), | |
'sale' | |
)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment