S
S
smoln2018-06-07 12:44:52
PHP
smoln, 2018-06-07 12:44:52

How to properly set up the unloading of orders in 1C?

Hello everyone, I'm trying to upload orders in 1C
With a direct link 1c_exchange.php?type=sale&mode=query, the xml structure is displayed in the browser
in the file 1c_exchange.php run starts where I just choose what 1C sends and display what
the toorder_1c () function needs - displays xml structure from the database

public function run(){
 $mode = $this->mode;

if($mode=='query'){
$toordeer_1c=toorder_1c();
echo  htmlentities($toordeer_1c, ENT_QUOTES);
}
$this->$mode();
 }

There are no orders in 1C itself, but I don’t accept them (perhaps I need to accept something from the beginning), I just need to upload orders to 1C, help me solve the issue

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
smoln, 2018-06-07
@smoln

In general, there is such an example, I corrected it
In the run method, I call the data in order
1-authorization
2-verification
3-loading orders in 1C
Orders are displayed in the structure of the xml document, that is, using the query link directly, I get the xml structure exactly the same as in the example
Tell me what need to do more

class Exchange1c {
 
        private $mode;
        private $filename;
 
 
        public function __construct() {
                // принимаем значение mode
                $this->mode = $_GET['mode'];
                $this->filename = $_GET['filename'];
        }
 
        public function run(){
        $mode = $this->mode;

        if($mode=='checkauth'){
                echo "success\n";
                echo session_name()."\n";
                echo session_id()."\n";      
        }
        elseif($mode=='int'){
                $zip = extension_loaded('zip') ? 'yes' : 'no';
                echo 'zip='.$zip."\n";
                echo "file_limit=0\n";
        }

        elseif($mode=='query'){
 $ex=toorder_1c();
 //echo $ex;
 echo htmlentities($ex, ENT_QUOTES|ENT_HTML401);

        }


 $this->$mode();

        }//run
 
 
        /*
         * Этап 1. Авторизовываем 1с клиента
         */
        public function checkauth() {
                echo "success\n";
                echo session_name()."\n";
                echo session_id()."\n";
                exit;
        }
 
        /*
         * Этап 2. Говрим 1с, умеем или не умеем работать с архивами
         * в нашем случае - умеем :)
         */
        public function init() {
                $zip = extension_loaded('zip') ? 'yes' : 'no';
                echo 'zip='.$zip."\n";
                echo "file_limit=0\n";
                exit;
        }
 
        /*
         * Этап 3. Принимаем файл и распаковываем его
         */
        public function file() {
 
                // вытаскиваем сырые данные
                $data = file_get_contents('php://input');
 
                //Сохраняем файл импорта в zip архиве
                file_put_contents($this->filename, $data);
               
                // распаковываем
                if(file_exists($this->filename)) {
                        // работаем с zip
                        $zip = new ZipArchive;
                        //все в порядке с архивом?
                        if($res = $zip->open($this->filename, ZIPARCHIVE::CREATE)) {
 
                                // распаковываем два файла в формате xml куда-то
                                // в нашем случае в этот же каталог
                                $zip->extractTo(__DIR__);
                                $zip->close();
 
                                // удаляем временный файл
                                unlink($this->filename);
                                //Всё получилось?
                                echo "success\n";
                                exit;
                        }
                }
                // если ничего не получилось
                echo "failure\n";
                exit;
        }
 
        /*
         * Этап 3 
         */
        public function import() {
                // используем читалку xml
                $xml = simplexml_load_file($this->filename);
                if($xml && $this->filename == 'orders.xml') {
                        /// обрабатываете import.xml как простой xml
                        //Считываете данные, подключаетесь к своей БД, записываете и т.д
                        //во время работы скрипта можете отправлять progress
                        // если все успешно закончилось отправляете успех
                   echo "success\n";
                        echo session_name()."\n";
                        echo session_id()."\n";
                        exit;
 
                }
                else{
                        echo "Ошибка загрузки XML\n";
                        foreach (libxml_get_errors() as $error) {
                                echo "\t", $error->message;
                        }
                        exit;
                }
        }
    
    

    
    
    
    
 
}
session_start();
$exaple = new Exchange1c();
$exaple->run();

A
Alexander Tokarchuk, 2018-06-07
@Kewa2008

To exchange information between 1C and external software, 1C has a wonderful technology - Web services. The solution to your problem lies precisely in this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question