I have a prestashop module that has to do a task with a database when this hook is launched: hookActionPaymentConfirmation. But I can't do anything, I don't know if it's a problem with the connection or with the query. This is the code of the function of the hookActionPaymentConfirmation, do you see any error? The task is to update the stock of products in a table of the same database. I want to do it with the name of the database and the name of the server, because I'm planning to implement that table in an external database.
public function hookActionPaymentConfirmation($params)
{
//mail("[email protected]", "yiha", "hola");
$database=Configuration::get('MIMODULOMISMADB_ACCOUNT_NOMBREDB', null);
$user=Configuration::get('MIMODULOMISMADB_ACCOUNT_USUARIO', null);
$password=Configuration::get('MIMODULOMISMADB_ACCOUNT_PASSWORD', null);
//
$db = new DbMySQLi("localhost",$user,$password,$database,true);
//$products = $params['cart']->getProducts(true);//en los nuevos ps ya no va y hay que hacerlo con las dos ordenes siguientes
$order = new Order($params['id_order']);
$products = $order->getCartProducts();
foreach ($products as $product)
{
$id_product = $product['id_product'];
$cantidad = $product['cart_quantity'];
$referencia = $product['reference'];
$product_attribute_id = $product['product_attribute_id'];
$newProduct = new Product($id_product);
if($newProduct->hasCombinations())
{
$sql = 'select * from product_attribute where id_product_attribute = ' . (string) $product_attribute_id . ';';
//$rec = DB::getInstance()->getRow($sql);
$rec = $db->getValue($sql);
$referencia = $rec["reference"];
//mail("[email protected]", "has combinations", $id_product." ".$referencia." ".$cantidad." p.a: ".$product_attribute);
}
$unidades = $db->getValue('SELECT unidades FROM productos WHERE '.$campoid.' = "'.$referencia.'"');
$unidadesRestantes=$unidades-$cantidad;
$db->Execute('UPDATE productos SET unidades="'.$unidadesRestantes.'" WHERE '.$campoid.' = "'.$referencia.'"');
mail("[email protected]", "yay",$database." ".$user." ".$password." ".$unidades);
//mail("[email protected]", "yay",$unidades);
}
}