dostoyevski Posted March 12, 2022 Share Posted March 12, 2022 (edited) hello! I have a ps module developed by me in which I automatically update the stock of the physical store every time there is a purchase in the ps store. The module worked fine in previous versions of ps but in version 1.7.8.4 it doesn't work. And I suspect that the error is in this line of code: $products = $params['cart']->getProducts(true); where $products seems to contain nothing. In fact, he sends me a "yiha" mail but he doesn't send me a "yay" mail. This is the hook code that is launched when there is a purchase. Do you know if something has changed in this version of prestashop that could be causing this? public function hookActionPaymentConfirmation($params) { $database=Configuration::get('MIMODULOMISMADB_ACCOUNT_NOMBREDB', null); $user=Configuration::get('MIMODULOMISMADB_ACCOUNT_USUARIO', null); $password=Configuration::get('MIMODULOMISMADB_ACCOUNT_PASSWORD', null); mail("[email protected]", "yiha", $database); $db = new DbMySQLi("localhost",$user,$password,$database,true); $products = $params['cart']->getProducts(true); foreach ($products as $product) { $id_product = $product['id_product']; $cantidad = $product['cart_quantity']; $referencia = $product['reference']; $unidades = $db->getValue('SELECT unidades FROM productos WHERE codigo_original = "'.$referencia.'"'); $unidadesRestantes=$unidades-$cantidad; $db->Execute('UPDATE productos SET unidades="'.$unidadesRestantes.'" WHERE codigo_original = "'.$referencia.'"'); mail("[email protected]", "yay", $id_product." ".$referencia." ".$cantidad); } } Edited March 12, 2022 by dostoyevski (see edit history) Link to comment Share on other sites More sharing options...
Ress Posted March 12, 2022 Share Posted March 12, 2022 You would rather take the products like this: public function hookActionPaymentConfirmation($params) { $order = new Order($params['id_order']); $products = $order->getCartProducts(); } 1 Link to comment Share on other sites More sharing options...
dostoyevski Posted March 12, 2022 Author Share Posted March 12, 2022 it worked! thank you. 1 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