如何使用 opencart 3 在 Featured/Product 列表内容中 Show/Display 产品购物车数量

How to Show/Display Product Cart Quantity in Featured/Product Listing Content using opencart 3

有没有人有关于如何在特色、最新、产品列表页面等中显示购物车产品数量的解决方案? 我需要显示客户购物车中已有多少数量。

那么如何轻松添加呢?

注意:我附上精选截图(为了更好地理解)

Image

谁能帮帮我吗?

提前致谢!

工作示例如何将产品数量添加到类别... 在catalog/controller/product/category.php

发现: $data['products'][] = array( 在前面添加:

$cart_quantity = '';
if ($this->cart->hasProducts()) {
    $cart_products = $this->cart->getProducts();
        foreach ($cart_products as $cart_product) {
            if (isset($cart_product['product_id']) && $result['product_id'] == $cart_product['product_id']) {
                $cart_quantity = $cart_product['quantity'];
            }
        }
    }

$data['products'][] = array( 之后添加:

'cart_quantity'  => $cart_quantity,

在相应的模板文件中 catalog/view/theme/default/template/product/category.树枝

查找:<div class="product-thumb"> 在之后添加:

{% if product.cart_quantity %} <div style=" padding: 10px; position: absolute; z-index: 1000; color: red; font-weight: bold;">In cart: {{ product.cart_quantity }} pcs.</div>{% endif %}

要添加到特色,最新...在相应的文件中做同样的事情。

要添加此修改,您必须使用 OCMOD。 进行此更改后,您必须在管理中刷新修改并清除缓存。