事情丢失或破坏,所以基本上,我想要做的是将实际库存数据库与zencart商店库存进行比较,如果它大于真实库存数据库,则更新zencart库存。
我的第一个数据库(zencart)和第二个数据库(库存)中有一个表'产品',如下所示: 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 |
[...]
inventory.products数据库是可用产品的实际数量。
当zencart股票查询功能测试货物是否可用时, 我希望它将库存数量与库存数据库进行比较。 如果zencart库存数量>然后,比库存股票 将zencart库存数量更新为库存库存。
zencart股票函数使用zencart.products.product_id 所以必须使用zencart.products.products_model来比较2个数据库。
这就是我所说的取代zencart库存计数功能。它似乎过于复杂,我不确定是否有全球库存$ db2;需要加入。
function zen_get_products_stock($products_id) {
global $db;
$products_id = zen_get_prid($products_id);
$stock_query = "select products_quantity
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$products_id . "'";
$stock_model_query = "select products_model
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$products_id . "'";
$inv_stock_query = "select products_quantity
from inventory.products.products_model
where 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
WHERE
zencart.products.products_model = inventory.products.model
}
$stock_values = $db->Execute($stock_query);
return $stock_values->fields['products_quantity'];
}
来自zencart的原始代码/ includes / functions / functions_lookups.com
/**
* Return a product's stock count.
*
* @param int The product id of the product who's stock we want
*/
function zen_get_products_stock($products_id) {
global $db;
$products_id = zen_get_prid($products_id);
$stock_query = "select products_quantity
from " . TABLE_PRODUCTS . "
where products_id = '" . (int)$products_id . "'";
$stock_values = $db->Execute($stock_query);
return $stock_values->fields['products_quantity'];
}
/**
* Check if the required stock is available.
*
* If insufficent stock is available return an out of stock message
*
* @param int The product id of the product whos's stock is to be checked
* @param int Is this amount of stock available
*
* @TODO naughty html in a 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;
}
感谢您的帮助。