VM 3.0.2 replaces quantity update in cart to remove non-numeric

Started by rickkh, December 17, 2014, 03:46:38 AM

Previous topic - Next topic

rickkh

I am trying to figure out where in the code does VM3.0.2 remove non-numerics from the product quantity when this is updated in the cart.
I am trying to find out because I must make VM3 work with decimal (0.5, 1.5, etc.) quantities. I figured out half the solution: now I can add 0.5 from the products list and the cart successfuly shows 0.5 and calculates the correct price/total.

However when I try changing to 2.5 (for example) from the cart and I press enter or the update icon, the value changes to 25. When I try 2a, value changes to 2. 1a1, value changes to 11. This leads me to believe that there's a preg_replace or some JS replace somewhere but I can't find it!!! Any help would be very appreciate it.

Once I have a full solution working for the decimal I will post it for the benefit of the community.

Milbo

helpers cart
function updateProductCart

$quantities = vRequest::getInt('quantity');

But it is wrong to solve that by quantity. If you want to sell an half a liter you sell 1 * 0.5 liter, not 0.5 * 1 liter,... this is what you do now. The customsize plugin does it correctly. there you can buy for example 5 times an half meter. 5 times an half meter is not just 2.5 meter, right?

Take a look here http://extensions.virtuemart.net/products/custom-size-detail
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rickkh

Hi Milbo,

Thank you for your response. I believe I have replaced that part with a getFloat but I'll double check when I am back home.
In my case, the customer may order half a case (of apples), one case, or 3.5 cases (or more)...

The customize extension seems to solve part of the problem (Please correct me if I understood the extension wrong):
With this extension, the customer can order 0.5 case, 1 case, but the customer can't EASILY order 3.5 cases as to do that he will have to order 7 quantity *0.5 cases... Alternatively, the client has to add 3 cases, switch to half case and then add 1 half case... My client does not like that and desires his customer to be able to directly order 3.5 cases via keying in 3.5 OR via quantity + (0.5 steps) ...
Am I wrong here?

Thanks again!
Rick


rickkh

Hi Milbo,

Verified here's what I have:

public function updateProductCart() {
                $quantities = vRequest::getFloat('quantity');
                if(empty($quantities)) return false;
                $updated = false;
                echo print_r($quantities,true);
....
}

With two products in the cart, one is initially "4.5" and the other "3", when I updated the one with "3" and changed it to "4",  the echo statement above printed the following:

Array (
  • => 45 [1] => 4 )

    Hence, the value 4.5 is being changed BEFORE the call to updateProductCart...

    I have also verified in the previous call (function updateCart in the controller) which calls updateProductCart and the value of quantity was 45 over there as well:
    public function updatecart($html=true){
                    $cart = VirtueMartCart::getCart();
                    $cart->_fromCart = true;
                    $cart->_redirected = false;
                    echo print_r($cart,true);

    I then tried to print it from getCart() in the helper at the following location:
    if (!empty($cartSession)) {
                                            $sessionCart = (object)json_decode( $cartSession ,true);
                                            echo print_r($sessionCart,true);

    However this function seems to get the session before the update (eventual!)

    That said, I believe that the value is being updated before even calling the controller's "updateCart" function... Any ideas where could that be?

    Thanks a lot,
    Rick

rickkh

Also for my case, customize size plugin does not work...

While it is true that you don't order 1.8 quantity of 1 meters, you order 1.8 meters with 1 quantity, but in my situation:
Would you rather order 3x 0.5 cases or 1.5 of 1 case? 5x 0.5 cases or 2.5 of 1 case?

If you enter 1.5 or 2.5 in the custom size text field of the plugin, then the problem would be updating the quantity (which would be 1) from the cart...

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rickkh

I sell vegetables and fruits in cases or boxes or crates...
Any hints about what's changing the float to int when I update the qty in the cart?

Milbo

and there you see the point. You cannot sell half boxes or crates. I think actually you maybe need maybe a mix of the customsize http://extensions.virtuemart.net/products/custom-size-detail and the packager http://extensions.virtuemart.net/products/package-size-detail

But it makes of course perfectly sense to sell a 1kg basket only filled with 850 gramm. For that we have the customsize and we have almost finished the feature for vm3, that it directly changes the weight of your product, so that you also get the correct shipment.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rickkh

Actually this is for a produce (vegetables and fruits) distribution company that distributes to restaurants. They have been taking orders by phone for 20 years.
A customer will call to order and say:
I need 4 boxes of red apples, 1.5 boxes of oranges and 3.5 boxes of avocadoes. The customer may add: Oh, did I say 1.5 boxes of oranges? make that 2.5 (hence the need to allow updating from the cart)...

They need the same business model in their cart product.

Also customers do not pay shipment, it is free delivery... I do concur that customize-size is an excellent and very useful extension but for my specific scenario it does not work... nor does package-size alone. As you said a cross between these is needed and a cross is simply allowing to add 0.5, 1, 1.5, 2 quanitites and allowing the same to be updated from the cart page...

For my workaround, I have updated the product's minimum quantity to 0.5, step size to 0.5, and removed all (int) next to quantities, changed getInt to getFloat for quantities. Still I need to allow updation of the quantity
So I guess my only solution is to be able to update the cart with 1.5, 2.5, 3, 4, 7.5, etc. quantities but I am still unable to find the code that is changing the quantity form float to integer when updating the cart... I really need help finding this part PLEASE!?

Milbo

Please read http://dev.virtuemart.net/projects/virtuemart/wiki/Setting_up_a_Development_Environment

in special about the svn and create a patch of your version, so that i can take a look of what you did already. Maybe I implement it in the core.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rickkh

Milbo,

I'll be glad to do that but shouldn't I wait first until I figure out why updating the quantity directly from the cart is still changing to Integer despite that I replaced all getInt(quantity) with getFloat(quantity) and removed all (int) that were before the quantity parameters?

In all cases I'll do that with what I have if I am unable to figure this out soon.

Thanks,
Richard

bluezeyes

Have you checked the tax and coupon area / procedures as well for existence of getint()?

Jm2c

rickkh

Not using Coupons... And the Produce (vegetables and fruits) are tax free! :)

Also it would be a huge bug if taxes are treated as integers but I don't think that is it

bluezeyes

Your right that would be a big flaw.. 

Hmm last try..  Have you enabled rounding for prices in front end? 

Maybe it affects the amount of products too. Which would normally not be visible on integers for the amount...

mariadegraas

#14
Has anyone found a solution for allowing decimal quantities in the cart?

I am also stuck at the same point as rickkh - I can add decimal quantities (e.g. 0.2) on category and product details pages to cart but the qty changes to integer when the cart is saved during checkout or when qty is changed (e.g. from 0.2 to 2).

What I've done so far is changing in template files addtocart.php and addtocartbar.php by removing quantity check javascript (js-recalculate class and Virtuemart.checkQuantity function); in core files cart.php, view.html.php in productdetails, and vmprices.js I replaced (int) with (float) and getInt with getFloat.
Also, minimum order quantity is set to 0.1 in admin area for items that need the decimal quantity, and in MySQL table #_virtuemart_order_items changed field product_quantity from int to float.
But still the cart (option=com_virtuemart&view=cart) still uses integer.

We're selling veggies, fruit, spices, etc and people must have the option to by 0.5kg or 2.8kg (can't ask people to buy whole kilos of chilly, right :) ).
Virtuemart 3.0.4 / Joomla 3.3.6

What else must be changed to allow decimal quantities in the cart?

Any ideas would be greatly appreciated :)