Jump to content

update product price from xml file


pinarello

Recommended Posts


<?php

define('_PS_ADMIN_DIR_', getcwd());

include(_PS_ADMIN_DIR_.'/../config/config.inc.php');

$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');

$product->save();

 

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

}


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

<Document>

<Products>

<Reference>905911261</Reference>

<Price>100</Price>

</Products>

<Products>

<Reference>91731A8</Reference>

<Price>11</Price>

</Products>

<Products>

<Reference>908509S</Reference>

<Price>200</Price>

</Products>

<Products>

<Reference>9F05025</Reference>

<Price>55.99</Price>

</Products>

 

 

 

 

 

</Document>

 

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 

PIN

 

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