Lo que un programador necesita saber sobre la integración de sitios y 1C

No puede simplemente tomar e integrar un sitio con 1C. (c) Arte popular.





El propósito de este artículo es presentar toda la información sobre el tema en lenguaje humano.





Integración del sitio en 1C-Bitrix: Site Management y 1C es una fuente inagotable de preguntas y problemas. Hay 16 páginas en el sitio de ideas para Bitrix en la sección correspondiente, en el foro hay más de 23,000 mensajes al respecto. En la forma de ponerse en contacto con el soporte técnico de Bitrix, existe incluso un tipo de solicitud por separado "Intercambio con 1C".





Se cree que la integración de 1C y un sitio en Bitrix debería funcionar desde el primer momento. Las funciones más simples realmente se pueden ejecutar en una o dos horas. Pero puede dedicar 10 o 100 horas a finalizar el intercambio. 





El refinamiento del intercambio de sitios y 1C ya es la magia del nivel "experto", asustando incluso a un desarrollador experimentado con barba. En este artículo hablaremos de cómo se produce el intercambio de datos entre estos dos monstruos y cómo se pueden ampliar las posibilidades de este intercambio. El artículo contiene muchos detalles técnicos del intercambio y será útil principalmente para programadores que quieran comprender el tema.





Este artículo considerará la teoría general del intercambio entre dos sistemas de TI y dos intercambios estándar entre 1C y un sitio en 1C-Bitrix: el intercambio de bienes y el intercambio de libros de referencia.





Un poco de teoría

— 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. — .









.





imagen pegada 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 .





La integración con 1C suele ser la tarea más difícil del proceso de desarrollo. Una comprensión clara de los procesos que tienen lugar en Bitrix es necesaria para proyectos serios. 





El autor del artículo: Anatoly Erofeev.








All Articles