Xml /-------------------------------------------------------------------------------------------------------------------- $object->save(); //卡提戈里同步------------------------------------------------------------------------------------ $object->category=数组($id\u category); $object->id\u category\u default=$id\u category; $object->updateCategories($object->categories,true); //-------------------------------------------------------------------------------------------------------------------- if($new_product | |(!$new_product&&in_数组(“sync_photo”,$params))) { $cover=true; foreach($product->product->associations->images->image as$img) { $this->copyImg($object->id,$id\u image=null,$img->attributes($http://www.w3.org/1999/xlink')->href,$entity='products',$regenate=true,$cover); $cover=假; } $elem_sync[]=“同步照片”; } $sql='update`'_数据库前缀synchrone_products`set id_product_sync='.$object->id.'where id_product='.$id_product; Db::getInstance()->Execute($sql); $date\U add=(字符串)$product->product->date\U add; $date\U upd=(字符串)$product->product->date\U upd; $sql=“UPDATE`gitdk\u tendanceronde`.`tr\u product`SET`date\u add`='”、`date\u upd`='”、`date\u upd`='”、`tr\u product`.`id\u product`='.$product\u edited.;”; //echo$sql; Db::getInstance()->Execute($sql); 返回数组( “产品标识”=>$object->id, “产品名称”=>(字符串)$product->product->name->语言, “新产品”=>$新产品, “同步”=>内爆(“,”,$elem_sync), “活动”=>$object->active );

Xml /-------------------------------------------------------------------------------------------------------------------- $object->save(); //卡提戈里同步------------------------------------------------------------------------------------ $object->category=数组($id\u category); $object->id\u category\u default=$id\u category; $object->updateCategories($object->categories,true); //-------------------------------------------------------------------------------------------------------------------- if($new_product | |(!$new_product&&in_数组(“sync_photo”,$params))) { $cover=true; foreach($product->product->associations->images->image as$img) { $this->copyImg($object->id,$id\u image=null,$img->attributes($http://www.w3.org/1999/xlink')->href,$entity='products',$regenate=true,$cover); $cover=假; } $elem_sync[]=“同步照片”; } $sql='update`'_数据库前缀synchrone_products`set id_product_sync='.$object->id.'where id_product='.$id_product; Db::getInstance()->Execute($sql); $date\U add=(字符串)$product->product->date\U add; $date\U upd=(字符串)$product->product->date\U upd; $sql=“UPDATE`gitdk\u tendanceronde`.`tr\u product`SET`date\u add`='”、`date\u upd`='”、`date\u upd`='”、`tr\u product`.`id\u product`='.$product\u edited.;”; //echo$sql; Db::getInstance()->Execute($sql); 返回数组( “产品标识”=>$object->id, “产品名称”=>(字符串)$product->product->name->语言, “新产品”=>$新产品, “同步”=>内爆(“,”,$elem_sync), “活动”=>$object->active );,xml,prestashop,prestashop-1.7,Xml,Prestashop,Prestashop 1.7,大家好,我找到了一个可能帮助他人的解决方案 有一个从ftp服务器获取文件的函数 function getFile(){ $local_file = 'file'.time().'.xml'; $server_file = 'file.xml'; $conn_id = ftp_connect($ftpurl); $login_result = ftp_login($conn_id, 'username', 'password

大家好,我找到了一个可能帮助他人的解决方案

有一个从ftp服务器获取文件的函数

 function getFile(){


        $local_file = 'file'.time().'.xml';
        $server_file = 'file.xml';

        $conn_id = ftp_connect($ftpurl);

        $login_result = ftp_login($conn_id, 'username', 'password');

        if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {

            echo "Successfully written to $local_file\n";

        } else {
            echo "There was a problem\n";
        }

        ftp_close($conn_id);

        $this->parseFileToArray($local_file);


    }
我将文件解析为另一个函数以获取文件内容

public function parseFileToArray($file){

        $xmlstr = file_get_contents($file);

        $xmlcont = new SimpleXMLElement($xmlstr);

        $arrayProducts = array();

        foreach($xmlcont as $url) 

            { 
                $arrayProducts[] = array('reference' => $url->kode,
                                         //get the parameters u need
                                         ..............
                                         );

            }

        $this->updateProducts($arrayProducts);

    }
现在我将数据传输到函数中进行更新

public function updateProducts($arrayProducts){

      foreach($arrayProducts as $arrayProduct) 

            {  

            $product_id = // sql request to get the product id that match the reference

            if($product_id){

               $object = new Product($product_id);

               $object->wholesale_price = $arrayProduct['wholesale_price'];
               // the update

               $object->save();
            }
            }

}
public function updateProducts($arrayProducts){

      foreach($arrayProducts as $arrayProduct) 

            {  

            $product_id = // sql request to get the product id that match the reference

            if($product_id){

               $object = new Product($product_id);

               $object->wholesale_price = $arrayProduct['wholesale_price'];
               // the update

               $object->save();
            }
            }

}