Jump to content

Updating the stock through a cron job


stef2015

Recommended Posts

Hello,

I have developed a module that synchronizes the stock from our supplier with ours. This module works quite well and update the stock at each consultation of the product page.

 

In addition to this module, we also want to perform a global update, ie all products of our catalog (ref 15000). To do this and not to slow down the server, we have scheduled a cron job to execute once a day a php script that will update all products in the database.

 

This file is placed in a directory named /cron to the site root. When I run the script manually,

I have an error: "Fatal error" and activating the debugging console, prestashop not return me an error but an array containing PrestaShop parameters. Unfortunately I have not copied the contents because it is very heavy.

 

By examining the script code, I found that the problem was the function:

StockAvailable::setQuantity((int $product ['id_product'], 0, (int)$qty_available);

 

and as for:

StockAvailable::updateQuantity((int)$product ['id_product'], 0, (int)$qty_available);

 

And yet it works (maybe because it is reading and not writing data):

StockAvailable::getQuantityAvailableByProduct((int)$product ['id_product']);

 

These are features I used to handling. I have moreover used in my update module.

 

Is that to use these functions in another directory as a module or controller would be a problem? Thank you in advance for your help.

 

Stephane.

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