在类别页面上显示产品的可用性

Show Products' Availability on Category Pages

我正在使用 opencart 2.0,我需要根据数量调整产品的可用性。 我本来是要在产品页面上这样做的,但现在我还必须在类别页面上显示产品的可用性

转到您的类别控制器

catalog->controller->category.php

这里大约是第 231 行,会有一个名为 $data['products'] 的数组,将其替换为此代码

$data['products'][] = array(
    'product_id'  => $result['product_id'],
    'thumb'       => $image,
    'name'        => $result['name'],
    'description' => utf8_substr(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8')), 0, $this->config->get('config_product_description_length')) . '..',
    'price'       => $price,
    'special'     => $special,
    'tax'         => $tax,
    'rating'      => $result['rating'],
    'href'        => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url),
    'quantity' => $result['quantity'] // add another key for quantity in this array 
);

并且在您主题的 category.tpl 文件中,您可以通过产品循环下的这个变量访问数量

<?php echo $product['quantity']; ?>

希望对您有所帮助。:)