renaud2263 Posted January 26, 2018 Share Posted January 26, 2018 (edited) Hi Everybody, I Built a small BO module which has to allow of updater some tables when the admin modifies or adds a product. In this particular case when a product crosses it dematerialized, it is necessary to put fields minimal_quantity in 0 and available_for_order to 1 (because PS does not do it automatically and the admin forgets in 99 % of the cases, thus the product is declared "stock shortage" is strange for a downloadable one... My hooks: public function install() { if (!parent::install() // Install Sql du module || !$this->registerHook('header') || !$this->registerHook('actionProductSave') ) { return false; } return true; } And then in the function $id_product = $params['id_product']; $is_virtual = $params['product']->is_virtual; if($is_virtual == 1){ Db::getInstance()->execute("UPDATE "._DB_PREFIX_."product SET minimal_quantity ='0', available_for_order = '1' WHERE id_product = '".$id_product."'"); Db::getInstance()->execute("UPDATE "._DB_PREFIX_."product_shop SET available_for_order = '1', minimal_quantity = '0' WHERE id_product = '".$id_product."'"); Db::getInstance()->execute("UPDATE "._DB_PREFIX_."stock_available SET quantity = '0', out_of_stock = '1' WHERE id_product = '".$id_product."'"); } Result? In the modif of the product, 2 last ones run perfect, but not the first that on the table stock_available. And the request is good, no error: I sent it by e-mail via the hook and tested it in myAdmin: no blem. I tried hooks actionProductUpdate and actionProductOutOfStock but it is similar. Why does this hook refuse this request? Edited January 26, 2018 by renaud2263 (see edit history) Link to comment Share on other sites More sharing options...
renaud2263 Posted January 28, 2018 Author Share Posted January 28, 2018 Up ! Link to comment Share on other sites More sharing options...
a17000 Posted January 29, 2018 Share Posted January 29, 2018 don't update directly table, use object example : $product = new Product((int) $ps_product_id); or webservice example : function modify_stock_product($webService,$id_ps_produit,$quantite) { $opt['resource'] = 'products'; $opt['id'] = $id_ps_produit; $xml = $webService->get($opt); foreach ($xml->product->associations->stock_availables->stock_available as $stock) { $xml2 = $webService->get(array('url' => PS_SHOP_PATH . '/api/stock_availables?schema=blank')); $stock_availables = $xml2->children()->children(); $stock_availables->id = $stock->id; $stock_availables->id_product = $id_ps_produit; $stock_availables->quantity = $quantite; $stock_availables->id_shop = 1; $stock_availables->out_of_stock = 1; $stock_availables->depends_on_stock = 0; $stock_availables->id_product_attribute = $stock->id_product_attribute; //POST des données vers la ressource $opt = array('resource' => 'stock_availables'); $opt['putXml'] = $xml2->asXML(); $opt['id'] = $stock->id ; $xml2 = $webService->edit($opt); } } Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now