News:

Looking for documentation? Take a look on our wiki

Main Menu

Decimal quantities

Started by alikon1, October 22, 2016, 17:27:42 PM

Previous topic - Next topic

alikon1

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.


But if open the cart, there will be good quantity.


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.

Studio 42

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

alikon1

\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).

alikon1

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?

alikon1

#4
\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)) {

Studio 42

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 ;)

Milbo

The chances rises that we can add it.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bindcommerce

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

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/

ServeTT

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 ??