-1

Does anyone have a solution on how to display the cart product Quantity count in featured, Latest, Product Listing page, etc? I need to show How much quantity in the cart the customer already has.

so how can add this easily?

Note: I attached Featured Screenshot AS Well (For Better Understanding)

Image

Could anyone please help me out?

Thanks in advance!

1 Answers1

0

Working example how to add product quantity to category... In catalog/controller/product/category.php

find: $data['products'][] = array( add before:

$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'];
            }
        }
    }

after $data['products'][] = array( add:

'cart_quantity'  => $cart_quantity,

in corresponding template file catalog/view/theme/default/template/product/category.twig

find: <div class="product-thumb"> add after:

{% 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 %}

To add to featured, Latest... in the corresponding files do the same.

To add this modifications you must use OCMOD. After this changes will be made, you must in admin refresh modifications and clear the cache.

K. B.
  • 1,388
  • 2
  • 13
  • 25
  • @KB. I looked your answer right now. I will check tomorrow and gives an update early. – Mujahid Inception Dec 02 '20 at 13:57
  • Actually my requirement so different. if a product goes to cart from listing products like features, category, etc. then a particular product has a cart button inside shows qty like 1x,2x,3x, etc. Demo Site: https://www.e-fresh.gr/en Note: it doesn't open Indian IP. You can open through any VPN like Hola, Free VPN, etc – Mujahid Inception Dec 02 '20 at 14:03
  • @KB. It's Possible or not? Please suggest to me. – Mujahid Inception Dec 03 '20 at 07:18
  • Not so easy, but possible. Maybe better you should place an request on opencart commercial forum. – K. B. Dec 03 '20 at 07:30
  • Please tell me to make code for easier me. – Mujahid Inception Dec 03 '20 at 08:49
  • You can save some needed data to sessions `$this->session->data['some_data'] = $some_data_which_you_need;` And later retrieve where you need this saved to the session data: $some_data = $this->session->data['some_data'];` And using an example in my answer and session data, add additional conditions and achieve what you need... – K. B. Dec 03 '20 at 09:04