Jump to content

update product price from xml file


Recommended Posts


define('_PS_ADMIN_DIR_', getcwd());


$xml = simplexml_load_file('price.xml');

foreach ($xml->Products as $product_xml)


$id_product = (int)Db::getInstance()->getValue('SELECT id_product FROM '._DB_PREFIX_.'product WHERE reference = \''.pSQL($product_xml->Reference).'\'');

$product = $id_product ? new Product((int)$id_product, true) : new Product();

$product->reference = $product_xml->Reference;

$product->price = (float)$product_xml->Price;

//$product->link_rewrite[1] = Tools::link_rewrite($product_xml->Products_name);

//$product->weight = (float)$product_xml->Weight;

if (!isset($product->date_add) || empty($product->date_add))

$product->date_add = date('Y-m-d H:i:s');

$product->date_upd = date('Y-m-d H:i:s');



echo 'Product <b>'.$product->name[1].'</b> '.($id_product ? 'updated' : 'created').'<br />';


<?xml version="1.0" encoding="UTF-8"?>

























With this code, you agree to the community of course, I can make an update of the price range, or any other table products. 

I would like to know if: 

1) before running this script on a server online, I have to perform some operation, type maintenaice etc ... 

2) How do you do timing .. 

Thanks to anyone who can help with this code 



Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...