Import XML products to Prestashop in PHP

2020-05-06 13:51发布

问题:

I need create a PHP file to import a lot of products from a external source (a distributor) to my Prestashop 1.7.6.

I need to connect with this service "http://www.ferrunion.com/ita/codice/id_service.php" to take the token and when I recive this string I need to connect with this service "http://www.ferrunion.com/ita/codice/catalogo_service.php" to recive the XML file.

This is an example of the structure of the XML:

<![CDATA[ 
   <product>  
      <id>id<id>
      <description>description</description>
      <quantity>quantity</quantity>
      <confezione>confezione</confezione>
      <prezzo_lordo>prezzo acquisto senza sconti</prezzo_acquisto>
      <price>price</price>
      <info>info</info>
   </product> 
]]>

The problema are 2:

  • How can I conncet whit this services in PHP language?
  • When I have the file, how can import the XML code in my Prestashop's database?


Can you help me with this problem?

Thanks you.

回答1:

I guess your idea is to develop a Prestashop module and run it using a cron, is that so?

Have you tried to bring the XML file using curl?

From your Prestashop module you must bring the XML via CURL. Once you have the XML loaded you just have to parse (take a look:https://www.w3schools.com/php/php_xml_dom.asp) the file and process each product with the Prestashop API.

Tell me if I can help you.