Jump to content

Updating product price using CRUD


Recommended Posts

Hi all,

I am currently trying to run my Prestashop update methods, porting from SQL to CRUD Data Transfer methods.

I have seen some online util Tutorials, with this I can prepare the return of a Get to edit and later use in an EDIT, so I can edit the xml with the values ​​that most interest me, such as price, here the code:


<html><head><title>CRUD Data Transfer - Update example</title></head><body>
// Here we define constants /!\ You need to replace this parameters
define('DEBUG', true);
define('PS_SHOP_PATH', 'http://XXXXXXX.XXXX');
define('ID_PRODUCT', 512);
@ini_set('display_errors', 'on');
$webService = new PrestaShopWebservice(PS_SHOP_PATH, PS_WS_AUTH_KEY, DEBUG);
$opt = array('resource' => 'products');
$xml = $webService->get($opt);
echo "Successfully recived data.";
	 /* List of nodes that can't modify
	 *  - "manufacturer_name"
	 *  - "position_in_category"
	 *  - "quantity"
	 *  - "type"
   $xml->children()->children()->price = 111.0; // <-- new price!
//Load new data to query generator
$xml = $webService->edit($opt);
// if WebService don't throw an exception the action worked well and we don't show the following message
echo "Successfully updated.";
catch (PrestaShopWebserviceException $ex)
// Here we are dealing with errors
$trace = $ex->getTrace();
if ($trace[0]['args'][0] == 404) echo 'Bad ID';
else if ($trace[0]['args'][0] == 401) echo 'Bad auth key';
else echo 'Other error<br />'.$ex->getMessage();



And my question is if there's another way to do this but more faster?



Edited by ferran_comenz (see edit history)

Share this post

Link to post
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...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More