What a programmer needs to know about site integration and 1C

You can't just take and integrate a site with 1C. (c) Folk art.





The purpose of writing a post is to present all the information on the topic in human language.





Site integration on 1C-Bitrix: Site Management and 1C is an inexhaustible source of questions and problems. There are 16 pages on the site of ideas for Bitrix in the corresponding section, on the forum there are more than 23,000 messages about it. In the form of contacting Bitrix technical support, there is even a separate type of request "Exchange with 1C".





It is believed that the integration of 1C and a site on Bitrix should work out of the box. The simplest functions can really be launched in an hour or two. But you can spend 10 or 100 hours on finalizing the exchange. 





Refinement of the exchange of the site and 1C is already magic of the "expert" level, frightens even a bearded experienced developer. In this article we will talk about how the exchange of data between these two monsters takes place and how you can expand the possibilities of this exchange. The article contains many technical details of the exchange and will be useful mainly for programmers who want to understand the subject.





This article will consider the general theory of exchange between two IT systems and two standard exchanges between 1C and a site on 1C-Bitrix: the exchange of goods and the exchange of reference books.





A bit of theory

— IT-. . , () ,





= (, XML, YML, JSON, CSV).





= (, HTTP, SIP, SMTP, FTP). 





= . - UML Activity.





:





  1. ( FTP, CSV);





  2. ( HTTP, XML);





  3. . ( HTTP, YML).





3 :













  1. .





«» («») «» («»). , , . , 1 , . , .





. «1» — , - « 1», «1:» (, «1: » «1:ERP ») .  - . . 1-: — «».





— .





— .





— . 





1 — .





— .





— . 





1

« » ( ) 4 :





  1. 1 ( «catalog»);





  2. 1 ( «reference»);





  3. / 1 ( «sale»);





  4. ( «sale»):





    1. 1 ;





    2. 1.





1 HTTP, . .. 1 , «» , ( POST GET) . 1 ( ). « 1 1-».





1 — , — . 1. 1 , 1 .





. 1 ( ).









— 1. «success», , «progress», «error» «failure», . ( ).





— CommerceML 2 . XML, , , , , (+ ).





, — HTTP. ( ) . ,









GET-:





type=< >





mode=checkauth





Basic access :





1





Basic access :





1









:





success





< Cookie >





< Cookie >





sessid=<ID >





<1>=<1>





<2>=<2>





...





:





failure





< >





1 Basic access. «success»,  Cookie ( ), id ( type — ).

















. .









. .









.





1 php- :





COption::SetOptionString("catalog", "DEFAULT_SKIP_SOURCE_CHECK", "Y");





COption::SetOptionString("sale", "secure_1c_exchange", "N");





.





iblock .





. , BX_SESSION_ID_CHANGE: define('BX_SESSION_ID_CHANGE', false);









- , 10 . . .





-









GET-:





type=< >





mode=init





sessid=<ID >





Cookie:





< Cookie >=< Cookie >









:





zip=<yes|no>





file_limit=<>





1 . « 1» .

















zip





zip-. yes — 1 , .





yes





no





file_limit





HTTP-. 1 , .





>= 0





, 1 . «zip=yes», zip-. . .





















. . /upload/1c_catalog/.





(1 -> )

(type=catalog) :





  • ;





  • UF- ;





  • ;





  • SKU;





  • ;





  • ;





  • ;





  • ();





  • ;





  • .





1 XML-, . 1 4 :





import_ — , , .





offers_ — SKU.





prices_ — .





rests_ — .





timestamp ( ). 1 timestamp . 





1. ()





GET-:





type=catalog





mode=file





sessid=<ID >





filename=< >





POST:









Cookie:





< Cookie>=< Cookie>









:





success





:





failure





< >





. file_limit (. ) POST-. , . GET- filename . , 1 . 

















HTTP





1.





< >





apache, .





< >





apache, .





2.





GET-:





type=< >





mode=import





sessid=<ID >





filename=< >





Cookie:





< Cookie>=< Cookie>









:





success





:





progress





< >





:





failure





< >





— . . 11 , 1 . GET mode=import ( !), . $_SESSION[BX_CML2_IMPORT][NS]. , STEP .





2.1 (, )









:





progress









:





progress









:





failure





< >





, 1 ZIP. , ( — /upload/1c_catalog/). ( STEP ).





















PHP zip_open Zip . — .





2.2









:





progress









($_SESSION[BX_CML2_IMPORT][NS])





STEP





0





XML ( , ) . b_xml_tree. b_xml_tree, , .





2.3









:





progress









($_SESSION[BX_CML2_IMPORT][NS])





STEP





1





b_xml_tree . PHP BX_XML_CREATE_INDEXES_IMMEDIATELY, . OnBeforeCatalogImport1C .





















.





2.4 ()









:





progress





<>%





:





progress









:





failure





< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





2





1 , b_xml_tree. , . « 1» .

























2.5









:





progress









:





failure





< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





3





b_xml_tree .





















: , .





2.6









:





progress









:





failure









< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





4





:





  1. SKU





  2. ( CML2_: CML2_BAR_CODE, CML2_ARTICLE, CML2_ATTRIBUTES…)













  3. UF-

















: . 1 , .

















« ».













API, .





( : <>)





, XML .













(xml_id: <>)









.









. .









. 1 .









2.7









:





progress









:





failure









< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





5





, XML . XML- XML_ID.





XML_ID , . , XML . , TIMESTAMP_X . — . .





( LEFT_MARGIN RIGHT_MARGIN).









, . .





  1. « 1» (nginx).





  2. 1, «progress».





  3. .





, . , XML- 20001 . 10000 .





№ /





..













1





0





10000









2





10000





10000









3





20000





1





progress









, . 10000 ( TIMESTAMP_X) 10000 , -. 3- 1 .





2.8









:





progress





/





:





failure









< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





6





:





  1. / ( 1)









1 : «» ="true", .





2019 1 . , ( , ) , ( ). « 1». , .





LEFT_MARGIN RIGHT_MARGIN .





2.9 ()









:





progress





<> <>





:





progress









:





failure





< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





7





DONE





,





, XML . XML_ID.





XML_ID , . , XML . 





, « », TIMESTAMP_X . .





TMP_ID. <>. — XML .





















1 1 . 4.9, 4.2.





2.10 / ()









:





progress





<> <>





:





progress





/





:





failure





< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





8





DONE





,





(   2.8 ) . “” XML ="true" ( ). , .





2019 .





2.11









:





success









:





failure





< >





($_SESSION[BX_CML2_IMPORT][NS])





STEP





9





. , OnSuccessCatalogImport1C .





3.





GET-:





type=< >





mode=deactivate





sessid=<ID >





timestamp=< >





Cookie:





< Cookie>=< Cookie>









:





success









:





failure









2019 , . timestamp, 1 — , .





, ( ):





, 1 . 1 .





4.





GET-:





type=< >





mode=complete





sessid=<ID >





Cookie:





< Cookie>=< Cookie>









:





success









:





failure





< >





. , catalog OnCompleteCatalogImport1C. OnSuccessCatalogImport1C , .





(1 -> )

(type=reference) HL-. .





— .





1. ()

. , ( mode, mode=reference).





2.





GET-:





type=reference





mode=import





sessid=<ID >





Cookie:





< Cookie>=< Cookie>





2.1 (, )





. .





2.2









:





progress





. : <ID>





:





failure





< >





HL- ( ) UF-. catalog OnBeforeCatalogImportHL. , XML-. .





:





  • 1 , ;





  • 1 : , , , ;





  • , 1 , , , ;





  • : UF_NAME, UF_XML_ID, UF_VERSION, UF_DESCRIPTION.

















< >





1





< >





1





XML. : < >





1





.













10





XML





20





XML





110





XML <>





120





XML <>





210





UF- higloadblock





220





XML <> <>





230





XML <> <>





240





<> <> ( : , , , )





250





UF- highload





310





higloadblock





320





XML <> <>





330





XML <> <> <>





2.3 ()









:





success









:





progress





: <>





:





failure





< >





 





HL-.





, HL-, UF_VERSION <ID > + «#»





catalog OnSuccessCatalogImportHL. — .









.





pasted image 0 (35) .png
pasted image 0 (35).png

XML.





  • <>





    • ( ).





    • «b_» ( ).





  • <> . . , (sic!)





  • <> :





    • <>





      • XML ID





      • «UF_»





    • <>





      • UF-.





    • <>





      • 4 : , , ,





  • <> :





  • <>





    • UF_XML_ID





  • <>





    • C <ID > + «#» UF_VERSION





  • <>









      • UF_NAME









      • UF_DESCRIPTION

















      • «» YYYY-MM-DD HH:MI:SS.





      • «» true false ( ).





?

( ) 1 /bitrix/admin/1c_exchange.php. , « »  /bitrix/modules/sale/admin/1c_exchange.php. , ( /bitrix/admin/1c_exchange_custom.php) 1.





, GET- ( -) . .





. , GET-, . 









GET[type]

















,





sale





bitrix:sale.export.1c





\CSaleOrderLoader





/bitrix/modules/sale/general/order_loader.php





, , , ,





catalog





bitrix:catalog.import.1c





\CIBlockCMLImport





/bitrix/modules/iblock/classes/general/cml2.php









reference





bitrix:catalog.import.hl





\CBitrixCatalogImportHl









3 1:





  1. , .









  2. .





, .





:





  1. . /bitrix/admin/1c_exchange_custom.php.





  2. /bitrix/modules/sale/admin/1c_exchange.php.





  3. (, bitrix:catalog.import.1c intervolga:catalog.import.1c) .





  4. . (, \Intervolga\Custom\Exchange\Cml \CIBlockCMLImport ImportElements).





« » 1. , .





( ) , 1 - . highloadblock (, , ) . 





, 1, , .





— . . , . , 2 1 .





Integration with 1C is often the most difficult task in the development process. A clear understanding of the processes taking place in Bitrix is ​​necessary for serious projects. 





The author of the article: Anatoly Erofeev.








All Articles