Código
, como pudiera solucionarlo
$amountArray[$idproduct] += $amount;
Código
function saveAllSaleDetails($idsale, $sale) { $this->conexion->startTransaction(); $amountArray = []; try { foreach ($sale as $detail): $idproduct = $detail['id']; $amount = $detail['amount']; $price = $detail['price']; $subtotal = $detail['subtotal']; $iduser = 1; $this->saveSaleDetail($idsale, $idproduct, $amount, $price, $subtotal, $iduser); $amountArray[$idproduct] += $amount; $stock = $this->product->getProductStock($idproduct); $stock = $stock[0][0] - $amountArray[$idproduct]; if ($stock <= 20) { $product = $this->product->getProductById($idproduct); $message = $product[0][1]." stock is bellow 20."; notification::add($message, $idproduct, 'warning', 'product.php'); } endforeach; $this->conexion->commit(); $this->conexion->cerrar(); return true; } catch (Exception $e) { $this->conexion->rollback(); $this->conexion->cerrar(); return false; } }