VirtueMart Forum

VirtueMart 2 + 3 + 4 => Administration & Configuration => Topic started by: alikon1 on October 22, 2016, 17:27:42 PM

Title: Decimal quantities
Post by: alikon1 on October 22, 2016, 17:27:42 PM
We used VM1, VM2 many years and always there was a modofication for decimal quantities in the cart. Now installed VM3 and it's a problem there with decimals, can't find solution. Know that admins advice to use Customsize plugin, but it's not suitable for us.

As in previous versions, in VM3 we did:
1. Change DB:
   #_virtuemart_products field product_in_stock from integer to float
   #_virtuemart_order_items field product_quantity from integer to float
2. In \components\com_virtuemart\helpers\cart.php quantity Int type replaced with Float
   Line 506 $productData['quantity'] = (int) $post['quantity'][$p_key];
   Line 725 $quantities = vRequest::getInt('quantity');
   Line 1569 $productdata['quantity'] = (int)$productdata['quantity'];

3. In \components\com_virtuemart\assets\js\vmprices.js all parseInt replaced with parseFloat
4. In VM config -> Product -> Product Status -> Purchase Quantity Steps set 0.1

Now when click Add to cart button we see rotating fancybox, which never stops. And Warning: Division by zero in \components\com_virtuemart\helpers\cart.php on line 1735.
(http://s017.radikal.ru/i415/1610/97/ae9d4e6e3d49.jpg)

But if open the cart, there will be good quantity.
(http://s018.radikal.ru/i505/1610/2c/71fff989171d.jpg)

Else quantity box (0.2 on picture), when press + shows 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999, 1.2, 1.3, 1.4000000000000001, 1.5000000000000002, 1.6000000000000003, 1.7000000000000002, 1.8000000000000003, 1.9000000000000004, 2, 2.1, 2.2...
Instead 0.1 step.

Can anybody advice what to do next? Why 0.9999999999999999.... and why rotating fancybox instead "Continue shopping or Show cart" popup.
Title: Re: Decimal quantities
Post by: Studio 42 on October 23, 2016, 00:13:05 AM
I discuted with Max(the project manager) about this, but he don't want have decimal in the cart in VM3. So you have to debug and find yourself a solution, because this get never added in the core.
Regards
Title: Re: Decimal quantities
Post by: alikon1 on October 23, 2016, 10:04:58 AM
\components\com_virtuemart\helpers\cart.php

Near 1737 line replace
if ($step != 0 && ($quantity%$step)!= 0) {
$quantity = $quantity + ($quantity%$step);
$errorMsg = vmText::sprintf('COM_VIRTUEMART_CART_STEP_ORDER', $step);
vmInfo($errorMsg,$product->product_name);
return false;
}

with
if ($step >=1){
if ($step != 0 && ($quantity%$step)!= 0) {
$quantity = $quantity + ($quantity%$step);
$errorMsg = vmText::sprintf('COM_VIRTUEMART_CART_STEP_ORDER', $step);
vmInfo($errorMsg,$product->product_name);
return false;
}
}


And now can add to cart product with any step (In VM config -> Product -> Product Status -> Purchase Quantity Steps).
Title: Re: Decimal quantities
Post by: alikon1 on October 23, 2016, 19:49:55 PM
Problem only with:
QuoteElse quantity box (0.2 on picture), when press + shows 0.1, 0.2, 0.30000000000000004, 0.4, 0.5, 0.6, 0.7, 0.7999999999999999, 0.8999999999999999, 0.9999999999999999, 1.0999999999999999, 1.2, 1.3, 1.4000000000000001, 1.5000000000000002, 1.6000000000000003, 1.7000000000000002, 1.8000000000000003, 1.9000000000000004, 2, 2.1, 2.2...
Instead 0.1 step.

Why not 0.1, 0.2, 0.3, 0.4... Why 16 digit numbers?
Title: Re: Decimal quantities
Post by: alikon1 on October 24, 2016, 12:55:37 PM
\components\com_virtuemart\assets\js\vmprices.js
Replace there:
1. Virtuemart.incrQuantity function: quantity.val((Qtt*10 + Ste*10)/10);
2. Virtuemart.decrQuantity function:quantity.val((Qtt*10 - Ste*10)/10);
3. if ((remainder  != 0) && (step >= 1))


And add to cart decimal quantities is working now.

UPD: Sorry. After update to VM3.2.0 could not understand what I wrote and what to do)
Line 142: Replace quantity.val(Qtt + Ste); with quantity.val((Qtt*10 + Ste*10)/10);
Line 162: Replace quantity.val(Qtt - Ste); with quantity.val((Qtt*10 - Ste*10)/10);
Line 258: Replace if ((remainder  != 0) { with if ((remainder  != 0) && (step >= 1)) {
Title: Re: Decimal quantities
Post by: Studio 42 on October 24, 2016, 18:25:23 PM
Great, if it work, but write this in your notepad and save it. Last answer from Milbo was, it's not logic to use any decimal quantity, so this feature get not implemented.
I wanted use it myself for a project, but used a plugin because i don't wanted core hacks.
The other problem is to calculate weight now for shipment plugin. So if you have time , feel free to write and share the code for this case ;)
Title: Re: Decimal quantities
Post by: Milbo on October 25, 2016, 15:48:16 PM
The chances rises that we can add it.
Title: Re: Decimal quantities
Post by: bindcommerce on September 20, 2017, 16:55:04 PM
Hello,
I only realized today (almost at the end of a project) that VirtueMart no longer handles decimal quantities.

Are there any evolutions? Do you have any advice?

My client sells food, and does not want to hear excuses. In the past he used Magento (that manages the decimals) and I brought it to VirtueMart. Now I have to find a solution.

Thank you
Title: Re: Decimal quantities
Post by: Milbo on September 20, 2017, 20:59:07 PM
Either you buy a silver membership and I add the stuff above to the core. http://extensions.virtuemart.net/support/virtuemart-supporter-membership-silver-detail

Or you buy a customsize plugin http://extensions.virtuemart.net/product/custom-size-detail
Title: Re: Decimal quantities
Post by: ServeTT on January 09, 2024, 11:43:07 AM
Quote from: Milbo on September 20, 2017, 20:59:07 PM
Either you buy a silver membership and I add the stuff above to the core. http://extensions.virtuemart.net/support/virtuemart-supporter-membership-silver-detail

Or you buy a customsize plugin http://extensions.virtuemart.net/product/custom-size-detail

Hello!

Can you please add this feature if I pay for silver membership ??