Author Topic: Unable to get updated cart data on single call  (Read 713 times)


  • Beginner
  • *
  • Posts: 43
  • Indian Software Engineer
Unable to get updated cart data on single call
« on: February 11, 2018, 16:10:47 pm »
VirtueMart V3.2.12
Can somebody help me out? In some piece of code, I am trying to manipulate VirtueMart Cart and then get the updated cart value. Though in every call I am unable to get the updated cart value on a single hit.
Let say I have 2 products in my cart, ProductA with quantity 1 and ProductB with quantity 1. Now I set 'POST' param quantity[] as (2,3) and called up 'cart' helper method updateProductCart(). According to flow the VirtueMart, it will update cart as Product A with quantity 2 and ProductB with quantity 3. And this also what is happening but when I print VirtueMartCart::getCart() it shows me updated value after one additional hit.

To explain further, by VirtueMartCart::getCart() we get cart data. In my case, specifically two indexes are important. It contains an array of objects with the name 'products' which will have all cart products information and another array of array named 'cartProductsData'. Now when I make a hit to update cart, 'cartProductsData' do show updated product count in its index [quantity] after the first call but '->quantity' parameter in 'products' shows the previous value only after completion of the first hit. Here, if I make another hit to VirtueMartCart::getCart() after completion of the first hit, then 'products->quantity' also shows update values.

The reason for required values in 'products' is that it contains all the prices of the product after an update. Like- products[0]->subTotal. I also tried calling prepareCartData(true) method of VirtueMartCart::getCart() and calling VirtueMartCart::getCart() again so that data can be prepared if missed out, but the flow only allowing to get updated values in 'product' when a hit completes and then another hit is made to getCart  :(

Anant Garg
Ghaziabad, India


  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10018
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Unable to get updated cart data on single call
« Reply #1 on: February 19, 2018, 20:52:02 pm »
So you use $cart->add($virtuemart_product_ids,$error); without a redirect? Then you must use also $cart->setCartIntoSession(false,true);
I should fix your bug, please support the VirtueMart project and become a member
Extensions approved by the core team: