📜 ⬆️ ⬇️

Standard exchange of 1C-Bitrix for BASH: incremental upload of XML files from the import and offers directory

When talking about the benefits of 1C-Bitrix, in the first words mention the easy integration of the system with 1C. Bitrix interacts with 1C by transmitting data in CommerceML format, which defines the format of XML files. In addition to this, Bitrix also offers a standard for the exchange of these XML files between 1C and the site. The exchange consists of sending regular HTTP GET and POST requests to the site from 1C and receiving simple answers from the site that determine the result of the command execution.


It is usually declared that in the 1C there is some "standard exchange with the site", which should work immediately after its inclusion. In practice, the implementation of the exchange is not such a trivial task, as it seems at first. There are complaints that the exchange module with the 1C site prohibitively loads the system and requires modifications for specific needs. That is, in fact, the exchange seems to be there, but to make it work as it should, you need to make an effort.


There are a few more reasons to get into the standard exchange:



To make changes to the data download on the side of Bitrix does not make sense, it performs its function. On the other hand, taking data directly from 1C is also not the best solution, due to the complexity of the database and the issue of security. Often, the bottleneck is obtained precisely at the stage of the exchange of requests between 1C and the site, therefore, the optimal scheme of work may be the following: the standard 1C upload generates XML files and ends its work. This setting is available in the exchange module.


Then we take the resulting files, change them, if necessary, and instead of 1C send to the site. Thus, we get full control over the exchange process, we know at what stage the failure occurs - if it happens, we can keep a log of downloads, an archive of XML files, create our own schedule, and in many ways abstract from 1C in terms of the exchange.


Exchange protocol implementations already exist, but they all use prohibitively complex tools, suggesting an incomplete understanding of the principle of sending simple HTTP requests that are no different from requests to view any Internet sites.


The purpose of writing this script are:



The script is written in BASH and is supposed to work on the internal server of the company, which is usually always available from the web developer and is located on the internal network of the company. This script is part of a family of similar scripts that implement exchanges of goods, balances, loading information blocks, orders, order status. The project is laid out on github and provides work of several online stores.


BASH Script Exchange 1c and Bitrix


The project is called bitrexchange - from bitrix exchange. This project involves a family of scripts written in bash and performing similar exchanges.


For example, the most commonly used exchange is considered: the standard exchange script 1C and Bitrix according to the CommerceML standard: incremental upload of XML files from the import catalog and offers directory.


The minimum version of the script is given. In the next article in this series will be given a line by line analysis of the script.


#!/bin/bash # # bitrexchange - bitrix exchange #    1C     CommerceML #   XML   import  offers # set -e cd $(dirname $0) cdir=$(pwd)"/" remote_dir="/mnt/localwinserver_fs/import/webdata/" zip_fname="catalogue.zip" xml_files="import0_1.xml offers0_1.xml" ctime=$(date +%Y-%m-%d-%H%M) headers="--header=\"User-Agent: 1C+Enterprise/8.2\" --header=\"Accept-Encoding: deflate\"" login="import" password="yourpasswordonbitrix" baseurl="http://yourinternetshop.com/bitrix/admin/1c_exchange.php" ret_line=$( wget $headers --user=${login} --password=${password} --auth-no-challenge -O - -q "${baseurl}?type=sale&mode=checkauth" ) read -a ret_ar <<< $ret_line if [ ${ret_ar[0]} != "success" ]; then echo "Login error\r\n"; exit -1; fi sessvar=${ret_ar[1]} sessid=${ret_ar[2]} echo sessid=$sessid ret=$(wget $headers --header="Cookie: ${sessvar}=${sessid}" -O - -q "${baseurl}?type=catalog&mode=init"); echo $ret ret=$(wget $headers --post-file ${zip_fname} --header="Cookie: ${sessvar}=${sessid}" -O - -q "${baseurl}?type=catalog&mode=file&filename=import.zip"); echo $ret for fname in $xml_files; do st="progress"; while [ "$st" = "progress" ]; do ret=$(wget $headers --header="Cookie: ${sessvar}=${sessid}" -O - -q "${baseurl}?type=catalog&mode=import&filename=${fname}"); st=$( <<< "$ret" head -n1 | cut -c1-8); echo "$ret" | iconv -f cp1251 -t utf-8; done done 

Thanks for attention!


The next article in the series: a detailed and line-by-line analysis of the standard exchange script 1C and Bitrix.


')

Source: https://habr.com/ru/post/321096/


All Articles