Esempio n. 1
0
 function restock($orders_id, $orders_products_id, $products_id, $products_quantity)
 {
     global $osC_Database;
     if (STOCK_LIMITED == '1') {
         $error = false;
         $osC_Database->startTransaction();
         $Qupdate = $osC_Database->query('update :table_products set products_quantity = products_quantity + :products_quantity, products_ordered = products_ordered - :products_ordered where products_id = :products_id');
         $Qupdate->bindTable(':table_products', TABLE_PRODUCTS);
         $Qupdate->bindInt(':products_quantity', $products_quantity);
         $Qupdate->bindInt(':products_ordered', $products_quantity);
         $Qupdate->bindInt(':products_id', $products_id);
         $Qupdate->setLogging($_SESSION['module'], $orders_id);
         $Qupdate->execute();
         if (!$osC_Database->isError()) {
             $Qcheck = $osC_Database->query('select products_quantity from :table_products where products_id = :products_id and products_status = 0');
             $Qcheck->bindTable(':table_products', TABLE_PRODUCTS);
             $Qcheck->bindInt(':products_id', $products_id);
             $Qcheck->execute();
             if ($Qcheck->numberOfRows() === 1 && $products_quantity > 0) {
                 $Qstatus = $osC_Database->query('update :table_products set products_status = 1 where products_id = :products_id');
                 $Qstatus->bindTable(':table_products', TABLE_PRODUCTS);
                 $Qstatus->bindInt(':products_id', $products_id);
                 $Qstatus->setLogging($_SESSION['module'], $orders_id);
                 $Qstatus->execute();
                 if ($osC_Database->isError() === true) {
                     $error = true;
                 }
             }
         }
         //restock products variant details
         if ($error === false) {
             $Qvariants = $osC_Database->query('select products_variants_groups_id,  products_variants_values_id from :table_orders_products_variants where orders_id = :orders_id and orders_products_id = :orders_products_id order by products_variants_groups_id');
             $Qvariants->bindTable(':table_orders_products_variants', TABLE_ORDERS_PRODUCTS_VARIANTS);
             $Qvariants->bindInt(':orders_id', $orders_id);
             $Qvariants->bindInt(':orders_products_id', $orders_products_id);
             $Qvariants->execute();
             if ($Qvariants->numberOfRows() > 0) {
                 $variants = array();
                 while ($Qvariants->next()) {
                     $variants[$Qvariants->value('products_variants_groups_id')] = $Qvariants->value('products_variants_values_id');
                 }
                 $Qvariants->freeResult();
                 $osC_Product = new osC_Product($products_id);
                 $products_variants_id = $osC_Product->getProductVariantsId($variants);
                 $QstockUpdate = $osC_Database->query('update :table_products_variants set products_quantity = products_quantity + :products_quantity where products_variants_id = :products_variants_id');
                 $QstockUpdate->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $QstockUpdate->bindInt(':products_quantity', $products_quantity);
                 $QstockUpdate->bindInt(':products_variants_id', $products_variants_id);
                 $QstockUpdate->setLogging($_SESSION['module'], $orders_id);
                 $QstockUpdate->execute();
                 if ($osC_Database->isError() === true) {
                     $error = true;
                 }
                 $Qcheck = $osC_Database->query('select products_quantity from :table_products_variants where products_variants_id = :products_variants_id and products_status = 0');
                 $Qcheck->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                 $Qcheck->bindInt(':products_variants_id', $products_variants_id);
                 $Qcheck->execute();
                 if ($error === false) {
                     if ($Qcheck->numberOfRows() === 1 && $Qcheck->valueInt('products_quantity') > 0) {
                         $QattribStatus = $osC_Database->query('update :table_products_variants set products_status = 1 where products_variants_id = :products_variants_id');
                         $QattribStatus->bindTable(':table_products_variants', TABLE_PRODUCTS_VARIANTS);
                         $QattribStatus->bindInt(':products_variants_id', $products_variants_id);
                         $QattribStatus->setLogging($_SESSION['module'], $orders_id);
                         $QattribStatus->execute();
                         if ($osC_Database->isError() === true) {
                             $error = true;
                         }
                     }
                 }
             }
         }
         if ($error === false) {
             $osC_Database->commitTransaction();
             return true;
         }
         $osC_Database->rollbackTransaction();
         return false;
     } else {
         return true;
     }
 }