Skip to content

Commit 0104df6

Browse files
committed
Fix modulo with less than a 1 value
1 parent 5569b86 commit 0104df6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

lib/web/mage/validation.js

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,21 @@
204204
return empty === 0;
205205
}
206206

207+
/**
208+
*
209+
* @param {float} qty
210+
* @param {float} qtyIncrements
211+
* @returns {float}
212+
*/
213+
function resolveModulo(qty, qtyIncrements) {
214+
while (qtyIncrements < 1) {
215+
qty *= 10;
216+
qtyIncrements *= 10;
217+
}
218+
219+
return qty % qtyIncrements;
220+
}
221+
207222
/**
208223
* Collection of validation rules including rules from additional-methods.js
209224
* @type {Object}
@@ -1610,7 +1625,7 @@
16101625
isMaxAllowedValid = typeof params.maxAllowed === 'undefined' ||
16111626
qty <= $.mage.parseNumber(params.maxAllowed),
16121627
isQtyIncrementsValid = typeof params.qtyIncrements === 'undefined' ||
1613-
qty % $.mage.parseNumber(params.qtyIncrements) === 0;
1628+
resolveModulo(qty, $.mage.parseNumber(params.qtyIncrements)) === 0.0;
16141629

16151630
result = qty > 0;
16161631

@@ -1639,7 +1654,7 @@
16391654
result = isQtyIncrementsValid;
16401655

16411656
if (result === false) {
1642-
validator.itemQtyErrorMessage = $.mage.__('You can buy this product only in quantities of %1 at a time.').replace('%1', params.qtyIncrements);//eslint-disable-line max-len
1657+
validator.itemQtyErrorMessage = $.mage.__('You can buy this product only in quantities of fanis %1 at a time.').replace('%1', params.qtyIncrements);//eslint-disable-line max-len
16431658

16441659
return result;
16451660
}

0 commit comments

Comments
 (0)