M
M
Maksim9942019-11-12 08:35:05
Bitrix24
Maksim994, 2019-11-12 08:35:05

How to attach products to a Bitrix24 lead?

Hi all.
I have such a question, it is necessary to integrate woocommerce with bitrix24.ru.
I added the sending of contact information, and it remains to send the goods that the client has chosen.
Here is the code that I got

$queryAddProductUrl = 'ССЫЛКА НА ВЕБХУК/crm.lead.productrows.set.json';
  $queryAddProductData = http_build_query(
    array(
      'id' => $result['result'],
      'rows' => array(
        array(
          'ID' => '1',
          'PRODUCT_NAME' => 'Название товара', 
          'PRICE' => 200.00, 
          'QUANTITY' => 2
        ),
      ),
    )
  );
  $curlAdd = curl_init();

  curl_setopt_array($curlAdd, array(
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POST => 1,
    CURLOPT_HEADER => 0,
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => $queryAddProductUrl,
    CURLOPT_POSTFIELDS => $queryAddProductData,
    ));

    $resultAddProduct = curl_exec($curlAdd);
    curl_close($curlAdd);
    $resultAddProduct = json_decode($resultAddProduct, 1);

$result['result'] - taken from the previous request, the lead id is stored there
But it seems like the request is being executed but the products in the lead are not displayed
5dca446739c14678539836.png
please tell me what I'm doing wrong here

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasyl Fomin, 2019-11-12
@Maxim994

When I did the integration, when transferring the goods, I also indicated PRODUCT_ID
In the loop, I filled the $rows array:

$rows[] = [
                            'PRODUCT_ID' => $product->sku,
                            'PRICE' => $product->price / 100,
                            'QUANTITY' => $product->quantity,
                        ];

Then he transferred - attached to a previously created order:
// Добавляем к сделки товары
                $b24->crmDealProductrowsSet([
                    'id' => $b24Deal['result'],
                    'rows' => $rows,
                ]);

On my website PRODUCT_ID - this was the sku field, its value must match the acc. field in bitrex, otherwise the product will not be found and added.
For the convenience of working with Bitrix24, I used a PHP library that also works through webhooks:
$b24 = new \Fomvasss\Bitrix24ApiHook\Bitrix24(variable('bitrix24_host'), variable('bitrix24_user'), variable('bitrix24_hook_code'));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question