首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Opencart -自动禁用“脱销”产品

问Opencart -自动禁用“脱销”产品
EN

Stack Overflow用户
提问于 2013-08-09 23:37:03
回答 1查看 2.9K关注 0票数 1

我在找比viewtopic.php?t=7080更高级的东西

我需要隐藏(或禁用)脱销和属于特定类别的产品。

这个问题的出现是因为我有一个叫做“清仓”的类别,我希望清仓商品在售罄后自动禁用,因为我们永远不会有更多的库存。同时,我希望所有其他类别的产品在脱销后继续展示。

请帮帮忙。麦克

EN

回答 1

Stack Overflow用户

发布于 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 (缺货)(如果只想显示已售罄)。

代码语言:javascript
复制
// 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) {结构后添加以下内容:

代码语言:javascript
复制
$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;

还没有测试,但它应该可以工作,或没有几个调整。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18150485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档