Answer the question
In order to leave comments, you need to log in
How to add an element to an infoblock through an agent?
Good!
I imagine the process of adding an element using api to the infoblock
code
if(CModule::IncludeModule("iblock")){
$el = new CIBlockElement;
$IBLOCK_ID_CATALOG = 53;
$arLoadProductArray = Array(
"IBLOCK_ID" => $IBLOCK_ID_CATALOG,
"NAME" => "тест1",
"ACTIVE" => "Y",
"PREVIEW_TEXT" => "Позиция успешно добавлена",
);
if($newElement = $el->Add($arLoadProductArray)) {
echo "Позиция добавлена"; }
else {
echo "Error: ".$el->LAST_ERROR;
}
}
CModule::IncludeModule("iblock")
function addAgent()
{
include $_SERVER['DOCUMENT_ROOT']."/api/element.php";
mailAgent(); // в файле /api/element.php находится еще функция отправки теста на почту и она работает
return "addAgent();";
}
Answer the question
In order to leave comments, you need to log in
shortened the code
added to init.php - the agent adds 1 element and falls off.
function testAgent()
{
if(CModule::IncludeModule("iblock")){
$el = new CIBlockElement;
$IBLOCK_ID_CATALOG = 53;
$arLoadProductArray = Array(
"IBLOCK_ID" => $IBLOCK_ID_CATALOG,
"NAME" => "тест1",
"ACTIVE" => "Y",
"PREVIEW_TEXT" => "Позиция успешно добавлена",
);
if($newElement = $el->Add($arLoadProductArray));
}
}
function AddIBElementByAgent()
{
AddEventHandler("main", "OnProlog", "testAgent");
return "AddIBElementByAgent()";
}
You are smart about something.
Go to the admin panel and create an agent with the testAgent() function;
in init.php create your function
function testAgent()
{
if(CModule::IncludeModule("iblock")){
$el = new \CIBlockElement;
$IBLOCK_ID_CATALOG = 53;
$arLoadProductArray = Array(
"IBLOCK_ID" => $IBLOCK_ID_CATALOG,
"NAME" => "тест1",
"ACTIVE" => "Y",
"PREVIEW_TEXT" => "Позиция успешно добавлена",
);
$newElement = $el->Add($arLoadProductArray);
}
return "testAgent();";
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question