VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: anantmaks on February 11, 2018, 16:10:47 PM

Title: Unable to get updated cart data on single call
Post by: anantmaks 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  :(

Title: Re: Unable to get updated cart data on single call
Post by: Milbo 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);