ÿØÿà JFIF ` ` ÿþxØ
| Server IP : 109.234.164.53 / Your IP : 216.73.216.110 Web Server : Apache System : Linux cervelle.o2switch.net 4.18.0-553.32.1.lve.el8.x86_64 #1 SMP Thu Dec 19 13:14:03 UTC 2024 x86_64 User : computer3 ( 1098) PHP Version : 7.1.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/computer3/litsolide.com/ODLDDD_2/cp-admin/ |
Upload File : |
<?php
// DEBIT DES STOCKS SUR INDEX
// SI CDE ANNULEE
/*
$id_cde = $_POST['id'];
$status_cde = $_POST['status']; case '3':
*/
// lignes cde
$sqlc = $bdd->prepare('SELECT op.*, p.id AS id_product FROM orders_products op
INNER JOIN products p
ON op.id_product = p.id
WHERE id_order = :id_order');
$sqlc->execute(array('id_order' => $id_cde));
$products = $sqlc->fetchAll();
foreach ($products as $ligne) {
$id_product = $ligne['id_product'];
$quantit = 0;
////////////////////////////
// Si attribut
///////////////////////////
if ($ligne['attributes'] != "")
{
$recup_ligne_attribute = $ligne['attributes']; //nom de la valeur : T36 Blanc
$quantit = $ligne['quantity'];
// Recupere le id famille de l attribut
// Trouve famille de l attribut de la cde
$sqlp = $GLOBALS['bdd']->prepare('SELECT * FROM products_attributes_values WHERE id_product =:id_product');
$sqlp->execute(array('id_product' => $id_product));
$fam = $sqlp->fetchAll();
$id_famille = $fam[0]['id_attribute'];
// Recupere le id value de l attribut
$sqla = $GLOBALS['bdd']->prepare('SELECT * FROM attribute_values WHERE id_attribute =:id_attribute AND value =:value');
$sqla->execute(array('id_attribute' => $id_famille, 'value' => $recup_ligne_attribute));
$va = $sqla->fetchAll();
$id_value = $va[0]['id']; ///////////////////////////// id de la valeur
// Recupere le stock actuel attribut
$sqls = $GLOBALS['bdd']->prepare('SELECT * FROM products_attributes_values WHERE id_product =:id_product AND id_attribute =:id_attribute AND id_value =:id_value');
$sqls->execute(array('id_product' => $id_product,
'id_attribute' => $id_famille,
'id_value' => $id_value));
$stock = $sqls->fetchAll();
$stock_actuel = $stock[0]['stock']; ///////////////// Stock actuel
if ($stock_actuel < 0) { $stock_actuel = 0; }
// Recupere stock global produit
$sqlsg = $GLOBALS['bdd']->prepare('SELECT stock, hstock FROM products WHERE id=:id');
$sqlsg->execute(array('id' => $id_product));
$stockg = $sqlsg->fetchAll();
$stock_global = $stockg[0]['stock']; ///////////////// Stock glob actuel
if ($stock_global < 0) { $stock_global = 0; }
$hstock = $stockg[0]['hstock']; /////////////////
////////////////////////////////////////////
if ($id_value !== '') {
// remet le stock attribut a jour si attribut encore valide
$new_stock = 0;
$new_stock = $stock_actuel + $quantit;
$qidd = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products_attributes_values'] . "
SET stock = :stock WHERE id_product =:id_product AND id_attribute =:id_attribute AND id_value =:id_value");
$qidd->execute(array('stock' => $new_stock,
'id_product' => $id_product,
'id_attribute' => $id_famille,
'id_value' => $id_value));
$new_stock_global = $stock_global + $quantit;
$hstocka ='';
if (($new_stock_global > 0) AND ($hstock = '1')) { $hstocka = '0'; } else { $hstocka = $hstock; }
$qidd = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products'] . "
SET stock = :stock, hstock = :hstock WHERE id = :id");
$qidd->execute(array('stock' => $new_stock_global, 'hstock' => $hstocka,
'id' => $id_product));
}
/////////////////////////////////////////////////
/*
echo'<pre>';
echo'<br />prod ';
echo$id_product;
echo'<br /> stock_global ';
echo$stock_global;
echo'</pre>';
*/
$stock_global = 0;
$quantit = 0;
} else {
////////////////////////////
// Si pas attribut
///////////////////////////
$quantit = $ligne['quantity'];
// Recupere stock global produit
$sqlsg = $GLOBALS['bdd']->prepare('SELECT stock, hstock FROM products WHERE id=:id');
$sqlsg->execute(array('id' => $id_product));
$stockg = $sqlsg->fetchAll();
$stock_global = $stockg[0]['stock']; ///////////////// Stock glob actuel
if ($stock_global < 0) { $stock_global = 0; }
$hstock = $stockg[0]['hstock']; /////////////////
$new_stock_global = $stock_global + $quantit;
$hstocka ='';
if (($new_stock_global > 0) AND ($hstock = '1')) { $hstocka = '0'; } else { $hstocka = $hstock; }
$qidd = $bdd->prepare("UPDATE " . $GLOBALS['db_table']['products'] . "
SET stock = :stock, hstock = :hstock WHERE id = :id");
$qidd->execute(array('stock' => $new_stock_global, 'hstock' => $hstocka,
'id' => $id_product));
}
// foreach
}
?>