A
A
Alex11122020-04-25 14:40:06
1C-Bitrix
Alex1112, 2020-04-25 14:40:06

Integration of goods in Bitrix24 deal?

I'm trying to add products from an online store order for 1s-Bitrix to Bitrix24 (transaction) in custom integration.

I found this code on the Internet, it doesn't work, the transaction is being created, the product is not added.
In the documentation examples also the examples don't work. What is my mistake and how can I upload goods to Bitrix24?

$defaults['TITLE'] = 'НАЗВАНИЕ ЛИДА';
$defaults['NAME'] = 'ТЕСТОВОЕ ИМЯ';
$defaults['LAST_NAME'] = 'ФАМИЛИЯ ТЕСТ';
$defaults['ASSIGNED_BY_ID'] = 1; //ОТВЕТСВЕННЫЙ
$defaults['PHONE'] = array(array("VALUE" => '434873248932', "VALUE_TYPE" => "WORK"));
$defaults['EMAIL'] = array(array("VALUE" => '[email protected]', "VALUE_TYPE" => "WORK"));
$defaults['COMMENTS'] = 'ТЕСТОВЫЙ КОММЕНТАРИЙ';
//статисеский массив передаваемых товаров, заменить на массив содеражащий по каждому из товаров выбранных пользователем информацию о названии товара, цене за 1 единицу и количеству
$products_example = [
    [
        'PRODUCT_NAME' => 'Товар 1',
        'PRICE' => 100.00,
        'QUANTITY' => 3,
    ],
    [
        'PRODUCT_NAME' => 'Товар 2',
        'PRICE' => 200.00,
        'QUANTITY' => 13,
    ],
];
//строка обработчик которая будет выполнять добавление лида в Битрикс24
$queryUrl = 'https://битрикс/rest/1/ключ/crm.lead.add.json';
$queryData = http_build_query(array(
    'fields' => array(
        "TITLE" => $defaults['TITLE'], //поле "Название лида"
        "NAME" => $defaults['NAME'], //поле "Имя"
        "LAST_NAME" => $defaults['LAST_NAME'], //поле "Фамилия"
        "STATUS_ID" => "NEW", //не менять. все лиды должны попдать в этом статусе
        "OPENED" => "N", //этот параметр менять не нужно
        "ASSIGNED_BY_ID" => $defaults['ASSIGNED_BY_ID'], //Числовой идентификатор пользователя который будет назначен ответственным за лид. Можно узнать в Битрикс24
        "PHONE" => $defaults['PHONE'], //поле "Телефон"
        "EMAIL" => $defaults['EMAIL'], //поле "Email"
        "COMMENTS" => $defaults['COMMENTS'], //поле "Комментарий",
        "SOURCE_ID" => "WEB",
    "PRODUCT_ID"=>51,
    ),
    'params' => array("REGISTER_SONET_EVENT" => "Y")
));
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $queryUrl,
    CURLOPT_POSTFIELDS => $queryData,
));
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result, 1);
//строка обработчик для привязки заказанных товаров к лиду
$queryUrl = 'https://битрикс/rest/1/ключ/crm.lead.productrows.set.json';
$queryData = http_build_query(array(
    'id' => $result['result'],
    'rows' => $products_example,
));
$curl = curl_init();
curl_setopt_array($curl, array(
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $queryUrl,
    CURLOPT_POSTFIELDS => $queryData,
));
$result = curl_exec($curl);
curl_close($curl);
$result = json_decode($result, 1);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuri Paimurzin, 2020-04-26
@rusellsystems

Perhaps those products are not in CRM, so first you need to check if the product is there and find out the id, and if there is no product in CRM, then create it, I recently attached products that already exist in CRM to transactions in this way and everything works as it should

$queryUrl = 'https://...............bitrix24.ru/rest/1/'.WEB_HOOK.'/crm.deal.productrows.set';
$queryData = http_build_query(array(
 'id'=>$DEAL_ID, 
 //set of items for link with the created DEAL
 'rows' => [
  array("PRODUCT_ID" => $PRODUCT_ID,"PRICE" => $ordered_cost,"QUANTITY" => 1,)
 ]
)
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question