Answer the question
In order to leave comments, you need to log in
Bitrix. Error on the OnBeforeBasketAdd event?
Good afternoon.
I add my properties to the product property when ordering.
I take the properties from another infoblock.
Properties I add on event OnBeforeBasketAdd
That I want to make.
Get all infoblock elements with properties and check if they are filled in when sending or not.
Why doesn't this code work?
<?
use Bitrix\Main\Context;
if (!CModule::IncludeModule('iblock')) return;
AddEventHandler(
"sale",
"OnBeforeBasketAdd",
'addProperty'
);
function addProperty(&$arFields) {
$request = Context::getCurrent()->getRequest();
// Выбираем опции
$arOrder = Array(
"SORT"=>"ASC"
);
$arSelect = Array(
"ID",
"IBLOCK_ID",
"CODE",
"NAME",
"PROPERTY_OPTION_TYPE",
);
$arFilter = Array(
"IBLOCK_ID" => '2',
);
$res = CIBlockElement::GetList(
$arOrder,
$arFilter,
false,
false,
$arSelect
);
while( $ob = $res->GetNextElement() ) {
$arFields[] = $ob->GetFields();
}
$arOptionsAddToBasket['OPTIONS'] = $arFields;
// Заполняем опции
foreach ( $arOptionsAddToBasket['OPTIONS'] as $value ) {
$arFields['PROPS'][$value['CODE']] = [
'CODE' => $value['CODE'],
'ID' => '',
'VALUE' => '1',
'SORT' => '',
'NAME' => $value['NAME'],
];
}
}
?>
Answer the question
In order to leave comments, you need to log in
while( $ob = $res->GetNextElement() ) {
$arFields[] = $ob->GetFields();//Тут ошибка. эта переменная используется в качестве параметра функции addProperty.
}
function addProperty(&$arFields)
{
// Выбираем опции
$arOrder = Array(
"SORT" => "ASC"
);
$arSelect = Array(
"ID",
"IBLOCK_ID",
"CODE",
"NAME",
"PROPERTY_OPTION_TYPE",
);
$arFilter = Array(
"IBLOCK_ID" => '19',
);
$res = CIBlockElement::GetList(
$arOrder,
$arFilter,
false,
false,
$arSelect
);
$counter = 0;
while ($ob = $res->GetNextElement()) {
$arItem = $ob->GetFields();
$arFields['PROPS'][$arItem['CODE']] = [
'CODE' => $arItem['CODE'],
'VALUE' => '1',
'SORT' => $counter += 100,//Про сортировку свойств не надо забывать. ID был лишним.
'NAME' => $arItem['NAME'],
];
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question