php - dual database compare and update inventory value zencart stock function -


things lost or broken, basically, want compare actual inventory database against zencart store stock , update zencart stock if greater real inventory database.

i have table 'products' in first database (zencart) , second database (inventory), this: products_id products_model products_quantity

zencart.products : products_id : 3 | products_model : j293-04 | products_quantity : 4 |  [...]  inventory.products : products_id : 15 | products_model : j293-04 | products_quantity : 1 |  [...] 

the inventory.products database actual count of products available.

when zencart stock query function tests if goods available, want compare stock quantity inventory database. if zencart stock quantity > inventory stock, update zencart stock quantity = inventory stock.

the zencart stock functions use zencart.products.product_id zencart.products.products_model has used compare 2 databases.

this have come replace zencart stock count function. seems overly complex, , not sure if inventory global $db2; needs put in.

function zen_get_products_stock($products_id) { global $db; $products_id = zen_get_prid($products_id);  $stock_query = "select products_quantity                 " . table_products . "                 products_id = '" . (int)$products_id . "'"; $stock_model_query = "select products_model                 " . table_products . "                 products_id = '" . (int)$products_id . "'";  $inv_stock_query = "select products_quantity                 inventory.products.products_model                 zencart.products.products_model =                       inventory.products.products_model  if $stock_query > $inv_stock_query  {    $stock_query = $inv_stock_query    update     inventory.products,     zencart.products     set     zencart.products.products_quantity = inventory.products.products_quantity        zencart.products.products_model = inventory.products.model }  $stock_values = $db->execute($stock_query);  return $stock_values->fields['products_quantity']; } 

original code zencart/includes/functions/functions_lookups.com

/**  * return product's stock count.  *  * @param int product id of product who's stock want */   function zen_get_products_stock($products_id) {     global $db;     $products_id = zen_get_prid($products_id);     $stock_query = "select products_quantity                 " . table_products . "                 products_id = '" . (int)$products_id . "'";  $stock_values = $db->execute($stock_query);  return $stock_values->fields['products_quantity']; }  /**  * check if required stock available.  *  * if insufficent stock available return out of stock message  *  * @param int product id of product whos's stock checked  * @param int amount of stock available  *  * @todo naughty html in function */ function zen_check_stock($products_id, $products_quantity) { $stock_left = zen_get_products_stock($products_id) - $products_quantity; $out_of_stock = '';  if ($stock_left < 0) {   $out_of_stock = '<span class="markproductoutofstock">' . stock_mark_product_out_of_stock . '</span>'; }  return $out_of_stock;   } 

thank help.


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -