Commit 42d55ae1 authored by Renato  Pratas's avatar Renato Pratas
Browse files

dev sync production stock digital

parent e58739ab
......@@ -87,10 +87,18 @@ class Sync {
}
}
public function getProductsStockPhysical()
{
$stmt = $this->db->prepare("SELECT cp.id_product FROM perfum24_ps17category_product cp WHERE cp.id_category = 146 GROUP BY cp.id_product");
$stmt->execute();
return $stmt->fetchAll(PDO::FETCH_COLUMN, 0);
}
public function ResetExistencias() {
try {
$this->db->exec("UPDATE perfum24_ps17product p SET p.quantity = '0' WHERE p.id_product NOT IN (SELECT DISTINCT cp.id_product FROM perfum24_ps17category_product cp WHERE cp.id_category = 146)"); //Category id Physical Stock
$this->db->exec("UPDATE perfum24_ps17stock_available sa SET sa.quantity = '0' WHERE sa.id_product NOT IN (SELECT DISTINCT cp.id_product FROM perfum24_ps17category_product cp WHERE cp.id_category = 146)"); //Category id Physical Stock
$this->db->exec("UPDATE perfum24_ps17product p SET p.quantity = '0' WHERE p.id_product NOT IN (" . implode(',',$this->getProductsStockPhysical()) . ")");
$this->db->exec("UPDATE perfum24_ps17stock_available sa SET sa.quantity = '0' WHERE sa.id_product NOT IN (" . implode(',',$this->getProductsStockPhysical()) . ")");
$this->log('Reset Existencias', '');
} catch (PDOException $e) {
$this->log('Reset Existencias', $e->getMessage(), 1);
......
......@@ -42,13 +42,16 @@ try {
$stmt2->bindParam(':id_product', $id_produto, PDO::PARAM_STR);
$stmt2->execute();
if ($restock = $stmt2->fetch(PDO::FETCH_ASSOC)) {
if (isset($restock['price']) && (($row['preco'] < $restock['price']) && ($row['stock'] > 0)) || ($restock['stock'] == 0))
{
//UPDATE DIGITAL STOCK
if(!in_array($id_produto, $sync->getProductsStockPhysical())){
if ($restock = $stmt2->fetch(PDO::FETCH_ASSOC)) {
if (isset($restock['price']) && (($row['preco'] < $restock['price']) && ($row['stock'] > 0)) || ($restock['stock'] == 0))
{
$sync->PreparaStock($id_produto, $row['preco'], $row['stock'], $pvp);
}
} else {
$sync->PreparaStock($id_produto, $row['preco'], $row['stock'], $pvp);
}
} else {
$sync->PreparaStock($id_produto, $row['preco'], $row['stock'], $pvp);
}
$stmt2 = null;
} else {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment