News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

how to get number of products in cart

Started by kiasati, February 07, 2018, 14:26:31 PM

Previous topic - Next topic

kiasati

Hi

I have a simple button at the the top of my site that points to the cart page.
I want to show the number of product that are in the cart.
whats the code for it?

I wanna put this code in template index.php file. so i want it to be clean and fast so it wont effect page load time even a little bit.

i appreciate any help...

Milbo

a kind of echo count($cart->products). You just need to check if you have $cart or $this->cart
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

You can not dispay directly the product in cart in index.php.
You get this from Vm session or you need to initialise the cart(see mod_virtuemart_cart for the code)

bart198x

Hi.
Old topic i know, but...
vm3.2.15 J3.8.11
How could I get the amount of all products in component cart in overide of course?
I was trying to find something in $cart->products, but i can't find anything of which i could count. I know this can be done becouse cart module is doing it, but that is in $data->totalProductTxt and I stack on how to call it in component cart or calculate for my own in override component cart file. (scenario 2 products. first x 3 , second x5, and all i get was 2 as the products amount, without products quanatity. I need to get 8 :) )
Thanks for any advise or sugestion.

Studio 42

Quote from: bart198x on August 02, 2018, 22:57:21 PM
Hi.
Old topic i know, but...
vm3.2.15 J3.8.11
How could I get the amount of all products in component cart in overide of course?
Do a var_dump($data)
You should see products array  and each have quantity

GJC Web Design

you need to get the cart by the means discussed above and loop thru the $cart products and accumulate the products*quantity to get the total
$total_prods = 0;
foreach ($this->cart->products as $product){
        $total_prods+= $product->quantity ;
}

these aren't the actual vars.. check the cart object
GJC Web Design
VirtueMart and Joomla Developers - php developers https://www.gjcwebdesign.com
VM4 AusPost Shipping Plugin - e-go Shipping Plugin - VM4 Postcode Shipping Plugin - Radius Shipping Plugin - VM4 NZ Post Shipping Plugin - AusPost Estimator
Samport Payment Plugin - EcomMerchant Payment Plugin - ccBill payment Plugin
VM2 Product Lock Extension - VM2 Preconfig Adresses Extension - TaxCloud USA Taxes Plugin - Virtuemart  Product Review Component
https://extensions.joomla.org/profile/profile/details/67210
Contact for any VirtueMart or Joomla development & customisation

bart198x