Jump to content

Odobrání tovaru z 2 eshopu


Tomáš

Recommended Posts

Caute

Potrebuji radu jako na to popisu to laicky: :)

mam 2 eshopy - 2databazy

potrebuju aby sem si kontroloval tovar tak ak si nekdo neco koupi z jednoho eshopu tak aby to v databazi odratalo i v tom druhym takze prosim napiste mi nazev souboru kde je ten pozadavek z PHP do mySQL aby odebrali tovar z DB
popripade i kod :)
Dik moc

Link to comment
Share on other sites

Že by toto?

static public function addProductSale($product_id, $qty = 1)
   {
       return Db::getInstance()->Execute('
           INSERT INTO '._DB_PREFIX_.'product_sale
           (`id_product`, `quantity`, `sale_nbr`, `date_upd`)
           VALUES ('.intval($product_id).', '.intval($qty).', 1, NOW())
           ON DUPLICATE KEY UPDATE `quantity` = `quantity` + '.intval($qty).', `sale_nbr` = `sale_nbr` + 1, `date_upd` = NOW()');
   }

   static public function getNbrSales($id_product)
   {
       $result = Db::getInstance()->getRow('SELECT `sale_nbr` FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.intval($id_product));
       if (!$result OR empty($result) OR !key_exists('sale_nbr', $result))
           return -1;
       return intval($result['sale_nbr']);
   }

   static public function removeProductSale($id_product, $qty = 1)
   {
       $nbrSales = self::getNbrSales($id_product);
       if ($nbrSales > 1)
           return Db::getInstance()->Execute('UPDATE '._DB_PREFIX_.'product_sale SET `quantity` = `quantity` - '.intval($qty).', `sale_nbr` = `sale_nbr` - 1, `date_upd` = NOW() WHERE `id_product` = '.intval($id_product));
       elseif ($nbrSales == 1)
           return Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'product_sale WHERE `id_product` = '.intval($id_product));
       return true;
   }

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...