05.06.2023 Have you read it yet 3772 once It helped to the readers

Debugging integration between Bitrix and 1C

The script can be used to start exchanging orders, directories, and goods with the site. Need download file bx_1c_sync.php install it on your computer and upload it to the root folder of the site.

Configuring the script

Before launching, at the beginning of the downloaded file in the line $password = ''; You need to specify a password that you can use to log in.

You need to work with the script in browser mode. incognito so that it doesn't turn out that we are working from the admin and everything is fine, but 1C then it works from another user and everything breaks down.

To emulate the unloading of goods from 1C to the website, you must first make an exchange by setting file saving. This is done by adding a line to /bitrix/php_interface/dbconn.php, which enables saving files in a folder upload/1c_catalog:

define("BX_CATALOG_IMPORT_1C_PRESERVE", true);

Running the script

Initially, you will have a window like this:

1 (1).jpg
















If the integration has not been redone on the site, then you will have a standard upload address. /bitrix/admin/1c_exchange.php

Login and password are the ones that 1C uses to access the site.

Type of exchange and operation - select the desired ones from the list.

If required, select the file. Most often, the site works with archives. When uploading the archive, specify the name of the xml file in the archive.


When using the get_catalog method, the site returns the products one at a time. If you have 1000 products, you will need at least 1000 requests. Therefore, the script does not try to download all the goods, but receives only the first 5.

Work plan to fix the upload bug

  1. Find out from 1C what address they are uploading to
  2. To add logging of all incoming requests to this file, for example::
    file_put_contents(__FILE__ . '.log', date('r') . '->' . $_SERVER['REQUEST_URI'] . PHP_EOL, FILE_APPEND);
  3. Setting the constant BX_CATALOG_IMPORT_1C_PRESERVE in true
  4. Performing a full upload
  5. Let's see if what needs to change has changed.
  6. Looking at the files in /upload/1c_catalog
  7. Using the script at the link above, we upload ourselves to the same address where 1C uploads
  8. Let's see if what needs to change has changed.
  9. We compare the requests from 1C and from the script, they should be the same
  10. Manually run the script and debug it, look at where it is working out what condition is wrong and determine how to fix it.

Stages of exchange

The exchange is always encoded windows-1251. There are six types of requests in the exchange, and we'll talk about them later.

By default, the entry point is a file /bitrix/admin/1c_exchange.php, all requests are sent there:

https://example.ru/bitrix/admin/1c_exchange.php?type=catalog&mode=checkauth

The first request is always checkauth, through HTTP basic authentication the login and password are transmitted, the response is similar to this:

success
PHPSESSID
c84bba7587de83c2b7f88a837ffc4237
sessid=641ec5e7f1547d4934458141ec237512
timestamp=1623238486

If successful, the first line is success. The second line cookie's name, the third cookie value. Next are the parameters that should be passed in all subsequent requests.

The files are transmitted in the request body, the files on the server are not taken from $_FILES, and from php://input. That is, the data is not divided as in the usual POST request via boundary, and all the data being sent is a file.

Sale type - import and export of online store orders


  • checkauth authorization check, no action is taking place
  • init deletes files from the exchange folder 1c_exchange, checks the file .htaccess, sets the mode if required zip
  • query unloading orders by filter, unloads orders that were updated after the last upload
  • success after query, sets the end time of the last upload
  • file uploading a file if on init it was zip=yes, the file must be in the format zip. For older versions of the exchange, there is also a validation check. xml
  • import Unpacking the archive is only available in the new version. File processing without creating temporary tables
  • info getting online store directories on the website


CRM type - for working with 1C and Bitrix 24


The same as sale, not in use zip, compression via is possible gz, you can receive specific orders for ID, you can specify the date starting from which to upload orders



Catalog type - import of goods to the website


  • checkauth authorization verification, no action is taking place, the parameter is present in the response timestamp
  • init initializing the exchange, deletes files from the exchange folder 1c_catalog, checks the file .htaccess, sets if a mode is required zip
  • file uploading a file, if at the stage init it was zip=yes, the file must be in the format zip
  • import - data import in several steps:
    1. If used zip unpacking
    2. Deleting old temporary tables
    3. Creating temporary tables, an event is triggered OnBeforeCatalogImport1C
    4. Reading XML and transferring data to temporary tables
    5. Creating indexes in temporary tables
    6. Importing metadata
    7. Importing partitions
    8. Deactivating old partitions
    9. Import of goods
    10. Deactivation of old products
    12. Deleting the info block cache, ending work, calling an event OnSuccessCatalogImport1C
  • deactivate deactivation of old sections and products on the site that are older than timestamp. It is transmitted from 1C to the site timestamp, which was obtained in the method checkauth
  • complete the event of successful completion of the exchange, the launch of the event OnCompleteCatalogImport1C

It is through the binding to the event OnSuccessCatalogImport1C many people refine the import, since at this step you can access the file and get any field from there. The callback accepts two parameters: "Connection parameters of the exchange component" of the array type and "Full path to the XML file of the exchange" of the string type.



The reference type is uploading reference books (hlblocks) to the site


  • checkauth authorization check, no action is taking place
  • init deletes files from the exchange folder 1c_highloadblock, checks the file .htaccess, sets if a mode is required zip
  • file uploading a file, if at the stage init it was zip=yes, the file must be in the format zip
  • import data import, an event is triggered at the beginning of data processing OnBeforeCatalogImportHL, at the end OnSuccessCatalogImportHL


get_catalog type - export of goods from the site


  • init authorization check, no action is taking place
  • query getting the file


The listen type is waiting for changes.


Request to wait for changes in orders. The server response is pending 1 Just a minute If there have been changes, reply success, an exchange of orders is required. If there were no changes, the answer is no, HTTP 304 Not Modified. Next, 1C sends the request again with the expectation of changes.



Feedback

Was the material useful?

The assessment helps to understand which materials are worth developing and supplementing.

Discuss the task

Ask for help

Describe the task and leave your contacts. I will look at the introductory notes and contact you in a convenient way.

Direction *