Given :

  1. Server running centos 6, there I deployed a small bitrix

  2. There is also http://gw.open.1688.com:80/openapi/param2/1/cn.ali ... request for which we get a list of items from 1688.com

It is necessary , on the basis of the data obtained, to create a section with elements in the shopping catalog of the site. The element must contain the price, properties, images, in one word, all that is in the unloading.

For example , I will make a component "CATALOG" on pure bitrix, I will display a section with elements there, as I understand it is necessary to write some script that takes this json, loops over it and throws data through the api functions into the database, I mean after The script has worked in my database will be the goods and the line is no longer necessary to exaggerate?

In general, guys pliz tell me how to approach? how to write this script? How to display a directory correctly ?, preferably in detail, with code examples if possible) Or documentation

    2 answers 2

    Bitrix has a Bitrix \ Main \ Web \ HttpClient class. You can use it to get a json string and then decode it.

    use Bitrix\Main\Web\HttpClient; $httpClient = new HttpClient($options); $httpClient->get($url); $res = $httpClient->getResult(); try { $ar = json_decode($httpClient->getResult(), true); } catch (\Exception $e){ } if(is_array($ar)) { # если данные непосредственно в $ar foreach($ar => $product) { # добавление в базу } } 

    adding an element to the info block https://dev.1c-bitrix.ru/api_help/iblock/classes/ciblockelement/add.php

     $el = new CIBlockElement; $PROP = array(); $PROP[12] = 11; $arLoadProductArray = Array( "MODIFIED_BY" => $USER->GetID(), // элемент изменен текущим пользователем "IBLOCK_SECTION_ID" => false, // элемент лежит в корне раздела "IBLOCK_ID" => 18, "PROPERTY_VALUES"=> $PROP, "NAME" => "Элемент", "ACTIVE" => "Y", // активен "PREVIEW_TEXT" => "текст для списка элементов", "DETAIL_TEXT" => "текст для детального просмотра", "DETAIL_PICTURE" => CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."/image.gif") ); if($PRODUCT_ID = $el->Add($arLoadProductArray)) { # добавляем информацию для каталога # https://dev.1c-bitrix.ru/api_help/catalog/classes/ccatalogproduct/add.php # цены # https://dev.1c-bitrix.ru/api_help/catalog/classes/cprice/add.php } 

    for output, you can use the standard components bitrix: catalog

      Kurl (curl) raking json, the data is run through json_decode (); Then you add the received data of the elements to the information block you need with the help of CIBlockElement :: Add () . Then output all the received good in the right component.