如何在opencart中显示缺货按钮

How to show out of stock button in opencart

我在 opencart 中添加了一个数量为 0 的产品,但是当我在前端看到它时,我想显示缺货文本,并且添加到购物车按钮也应该被禁用

在管理仪表板中;

  • 将鼠标悬停在显示 SYSTEM 的菜单栏上,然后单击 下拉菜单中的设置。

  • Select 您要编辑的商店,然后单击编辑 最右边继续。

  • 点击选项卡,然后向下滚动直到看到 标有“显示缺货警告”的选项。

Note : It's not recommended to make the direct changes in the core files. You can make the vqmod for the same changes. changes given here are tested in the default template, it might be different in other custom theme.

之前 之后

(1) 打开 catalog/controller/product/product.php(大约第 273 行)并搜索以下行:

if ($product_info['quantity'] <= 0) {

并进行如下更改:

$data['stock_qty']=1;
if ($product_info['quantity'] <= 0) {
    $data['stock'] = $product_info['stock_status'];
    $data['stock_qty']=0;
} elseif ($this->config->get('config_stock_display')) {
    $data['stock'] = $product_info['quantity'];
} else {
    $data['stock'] = $this->language->get('text_instock');
}

(2) 打开 catalog/view/theme/default/template/product/product.tpl(大约第 303 到 309 行)

并将 "add to cart button" 的块包裹在条件中。

<?php if($stock_qty!=0) { ?>
<div class="form-group">
<label class="control-label" for="input-quantity"><?php echo $entry_qty; ?></label>
<input type="text" name="quantity" value="<?php echo $minimum; ?>" size="2" id="input-quantity" class="form-control" />
<input type="hidden" name="product_id" value="<?php echo $product_id; ?>" />
<br />
<button type="button" id="button-cart" data-loading-text="<?php echo $text_loading; ?>" class="btn btn-primary btn-lg btn-block"><?php echo $button_cart; ?></button>
</div>
<?php } ?>