3

Google searches for both "Magento please match the requested format: Qty" and "magento decimal quantites not updating in cart" have turned up nothing useful me.

Hi, I'm using CE 1.9.2.0 w/ patch 6482 installed. My store is early in development and has no themes or extensions whatsoever. I have items in my store with the following inventory attribute : value pairs:

Minimum Qty Allowed in Shopping Cart : .25

Qty Uses Decimals : Yes

Enable Qty Increments : Yes

Qty Increments : .25

I am able to add quantities to the cart if they are a multiple of .25 right from the product detail page. Magento does complain in the form of highlighting the quantity field in red, but the quantity is added to the cart nonetheless. If I do nothing else, I can proceed to checkout at this point without issue.

However, from the shopping cart, I cannot change an integer quantity to a decimal, nor can I change an integer quantity to a different integer quantity while another product's quantity is a decimal, nor can I change a decimal quantity to a different decimal quantity. I can change a decimal quantity to an integer quantity, whether or not other decimal quantities are in the cart.

Magento displays a "Please match the requested format: Qty." message below the quantity field when these violations are detected.

How can I get the form validation for the quantity field to behave as expected?

2 Answers 2

3

Welcome to Magento.SE!

Ah yes. This is wonderful. Magento supports fractional quantities, but the RWD reference theme (the theme that ships with Magento) does not:

enter image description here

In order to handle this you'll need to edit the input field which contains the validation requirements.

In app/design/frontend/rwd/default/template/checkout/cart/item/default.phtml:

    <input type="text" pattern="\d*" name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4"
           data-cart-item-id="<?php echo $this->jsQuoteEscape($_item->getSku()) ?>"
           title="<?php echo Mage::helper('core')->quoteEscape($this->__('Qty')) ?>" class="input-text qty" maxlength="12" />

The important part is pattern="\d*" - this is a regular expression that Magento parses to validate that you've input the right value.

For a decimal value you have a couple choices:

\d+(\.\d{1,2})? allows optional decimals

  • Accepts 1
  • Accepts 1.2
  • Accepts 1.23
  • Rejects 1.002

\d+(\.\d{2}) always enforces two decimal places

  • Rejects 1
  • Rejects 1.2
  • Accepts 1.23
  • Rejects 1.002

Hope that helps!

1
  • Worked great - I made a custom theme and changed the indicated regex. It seems I'm not able to vote up your answer, btw. Thanks for your help.
    – Harley
    Sep 10, 2015 at 22:43
1

Also, for minicart to use decimal

The problem is in skin/frontend/rwd/default/js/minicart.js on line 133:

var quantity = parseInt(input.val(), 10);

parseInt function returns only integer values. If you want to support float numbers, you should copy this file to your theme and change parseInt to parseFloat.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.