Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit a2c1a64

Browse files
bordeoMastiuhin Oleksandr
authored andcommitted
Issue #13582 show message for qty minAllowed, maxAllowed, qtyIncrements validation. Fix ProductView plugin for maxAllowed
1 parent 5a7c3bd commit a2c1a64

File tree

3 files changed

+80
-12
lines changed

3 files changed

+80
-12
lines changed

app/code/Magento/CatalogInventory/Block/Plugin/ProductView.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ public function afterGetQuantityValidators(
3939

4040
$params = [];
4141
$params['minAllowed'] = (float)$stockItem->getMinSaleQty();
42-
if ($stockItem->getQtyMaxAllowed()) {
43-
$params['maxAllowed'] = $stockItem->getQtyMaxAllowed();
42+
if ($stockItem->getMaxSaleQty()) {
43+
$params['maxAllowed'] = $stockItem->getMaxSaleQty();
4444
}
4545
if ($stockItem->getQtyIncrements() > 0) {
4646
$params['qtyIncrements'] = (float)$stockItem->getQtyIncrements();

app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -909,18 +909,52 @@ define([
909909
],
910910
'validate-item-quantity': [
911911
function (value, params) {
912-
// obtain values for validation
913-
var qty = utils.parseNumber(value),
912+
var validator = this,
913+
// obtain values for validation
914+
qty = utils.parseNumber(value),
914915
isMinAllowedValid = typeof params.minAllowed === 'undefined' ||
915916
qty >= utils.parseNumber(params.minAllowed),
916917
isMaxAllowedValid = typeof params.maxAllowed === 'undefined' ||
917918
qty <= utils.parseNumber(params.maxAllowed),
918919
isQtyIncrementsValid = typeof params.qtyIncrements === 'undefined' ||
919920
qty % utils.parseNumber(params.qtyIncrements) === 0;
920921

921-
return isMaxAllowedValid && isMinAllowedValid && isQtyIncrementsValid && qty > 0;
922-
},
923-
''
922+
var result = qty > 0;
923+
924+
if (result === false) {
925+
validator.itemQtyErrorMessage = $.mage.__("Please enter a quantity greater than 0.");//eslint-disable-line max-len
926+
927+
return result;
928+
}
929+
930+
var result = isMinAllowedValid;
931+
932+
if (result === false) {
933+
validator.itemQtyErrorMessage = $.mage.__("The fewest you may purchase is %1.").replace('%1', params.minAllowed);//eslint-disable-line max-len
934+
935+
return result;
936+
}
937+
938+
result = isMaxAllowedValid;
939+
940+
if (result === false) {
941+
validator.itemQtyErrorMessage = $.mage.__("The maximum you may purchase is %1.").replace('%1', params.maxAllowed);//eslint-disable-line max-len
942+
943+
return result;
944+
}
945+
946+
result = isQtyIncrementsValid;
947+
948+
if (result === false) {
949+
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
950+
951+
return result;
952+
}
953+
954+
return result;
955+
}, function () {
956+
return this.itemQtyErrorMessage;
957+
}
924958
],
925959
'equalTo': [
926960
function (value, param) {

lib/web/mage/validation.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,18 +1566,52 @@
15661566
],
15671567
'validate-item-quantity': [
15681568
function (value, element, params) {
1569-
// obtain values for validation
1570-
var qty = $.mage.parseNumber(value),
1569+
var validator = this,
1570+
// obtain values for validation
1571+
qty = $.mage.parseNumber(value),
15711572
isMinAllowedValid = typeof params.minAllowed === 'undefined' ||
15721573
qty >= $.mage.parseNumber(params.minAllowed),
15731574
isMaxAllowedValid = typeof params.maxAllowed === 'undefined' ||
15741575
qty <= $.mage.parseNumber(params.maxAllowed),
15751576
isQtyIncrementsValid = typeof params.qtyIncrements === 'undefined' ||
15761577
qty % $.mage.parseNumber(params.qtyIncrements) === 0;
15771578

1578-
return isMaxAllowedValid && isMinAllowedValid && isQtyIncrementsValid && qty > 0;
1579-
},
1580-
''
1579+
var result = qty > 0;
1580+
1581+
if (result === false) {
1582+
validator.itemQtyErrorMessage = $.mage.__("Please enter a quantity greater than 0.");//eslint-disable-line max-len
1583+
1584+
return result;
1585+
}
1586+
1587+
var result = isMinAllowedValid;
1588+
1589+
if (result === false) {
1590+
validator.itemQtyErrorMessage = $.mage.__("The fewest you may purchase is %1.").replace('%1', params.minAllowed);//eslint-disable-line max-len
1591+
1592+
return result;
1593+
}
1594+
1595+
result = isMaxAllowedValid;
1596+
1597+
if (result === false) {
1598+
validator.itemQtyErrorMessage = $.mage.__("The maximum you may purchase is %1.").replace('%1', params.maxAllowed);//eslint-disable-line max-len
1599+
1600+
return result;
1601+
}
1602+
1603+
result = isQtyIncrementsValid;
1604+
1605+
if (result === false) {
1606+
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
1607+
1608+
return result;
1609+
}
1610+
1611+
return result;
1612+
}, function () {
1613+
return this.itemQtyErrorMessage;
1614+
}
15811615
],
15821616
'password-not-equal-to-user-name': [
15831617
function (value, element, params) {

0 commit comments

Comments
 (0)