我在找比viewtopic.php?t=7080更高级的东西
我需要隐藏(或禁用)脱销和属于特定类别的产品。
这个问题的出现是因为我有一个叫做“清仓”的类别,我希望清仓商品在售罄后自动禁用,因为我们永远不会有更多的库存。同时,我希望所有其他类别的产品在脱销后继续展示。
请帮帮忙。麦克
发布于 2013-08-14 20:03:07
我将在order模型的confirm方法中执行此操作。这是在确认销售后更新产品数量的位置。
打开:
catalog/model/checkout/order.php
在confirm()方法中,您将找到类似以下内容的行:
foreach ($order_product_query->rows as $order_product) {
您可以创建一个新方法,该方法将返回给定产品的现有数量,减去售出数量并检查新数量是否为0,再加上它将检查该产品是否附加到您的给定类别。
如果是,则将产品状态设置为disabled (如果您根本不想显示),或者将stock_status设置为out Out (缺货)(如果只想显示已售罄)。
// check quantity and categories
private function checkQuantity ($product_id) {
$return = array();
// first check if product is attached to your specified category and add boolean to array
$categories = $this->db->query ("SELECT category_id FROM " . DB_PREFIX . "product_to_category WHERE product_id = '" . (int)$product_id . "'");
if (in_array($your_clearance_category_id, $categories->rows)):
$return['check'] = true;
else:
$return['check'] = false;
endif;
// get your pre-sale quantity and add to array
$quantity = $this->db->query ("SELECT quantity FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
$return['quantity'] = $quantity->row['quantity'];
return $return;
}然后在打开foreach ($order_product_query->rows as $order_product) {结构后添加以下内容:
$checks = $this->checkQuantity($order_product['product_id']);
if ($checks['check']):
if (((int)$check['quantity'] - (int)$order_product['quantity']) <= 0):
$this->db->query ("UPDATE " . DB_PREFIX . "product SET status = '0' WHERE product_id = '" . (int)$order_product['product_id'] . "'");
endif;
endif;还没有测试,但它应该可以工作,或没有几个调整。
https://stackoverflow.com/questions/18150485
复制相似问题