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

Commit 7cc0bc8

Browse files
author
Stanislav Idolov
authored
ENGCOM-1226: [Forwardport] Issue #13582 show message for qty minAllowed, maxAllowed, qtyIncremen… #14508
2 parents 48ff02f + 87c4b0d commit 7cc0bc8

File tree

4 files changed

+86
-16
lines changed

4 files changed

+86
-16
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'] = (float)$stockItem->getMaxSaleQty();
4444
}
4545
if ($stockItem->getQtyIncrements() > 0) {
4646
$params['qtyIncrements'] = (float)$stockItem->getQtyIncrements();

app/code/Magento/CatalogInventory/Test/Unit/Block/Plugin/ProductViewTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ protected function setUp()
2828

2929
$this->stockItem = $this->getMockBuilder(\Magento\CatalogInventory\Model\Stock\Item::class)
3030
->disableOriginalConstructor()
31-
->setMethods(['getMinSaleQty', 'getQtyMaxAllowed', 'getQtyIncrements'])
31+
->setMethods(['getMinSaleQty', 'getMaxSaleQty', 'getQtyIncrements'])
3232
->getMock();
3333

3434
$this->stockRegistry = $this->getMockBuilder(\Magento\CatalogInventory\Api\StockRegistryInterface::class)
@@ -48,8 +48,8 @@ public function testAfterGetQuantityValidators()
4848
'validate-item-quantity' =>
4949
[
5050
'minAllowed' => 0.5,
51-
'maxAllowed' => 5,
52-
'qtyIncrements' => 3
51+
'maxAllowed' => 5.0,
52+
'qtyIncrements' => 3.0
5353
]
5454
];
5555
$validators = [];
@@ -74,7 +74,7 @@ public function testAfterGetQuantityValidators()
7474
->with('productId', 'websiteId')
7575
->willReturn($this->stockItem);
7676
$this->stockItem->expects($this->once())->method('getMinSaleQty')->willReturn(0.5);
77-
$this->stockItem->expects($this->any())->method('getQtyMaxAllowed')->willReturn(5);
77+
$this->stockItem->expects($this->any())->method('getMaxSaleQty')->willReturn(5);
7878
$this->stockItem->expects($this->any())->method('getQtyIncrements')->willReturn(3);
7979

8080
$this->assertEquals($result, $this->block->afterGetQuantityValidators($productViewBlock, $validators));

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

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -909,18 +909,53 @@ 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+
result = false,
914+
// obtain values for validation
915+
qty = utils.parseNumber(value),
914916
isMinAllowedValid = typeof params.minAllowed === 'undefined' ||
915917
qty >= utils.parseNumber(params.minAllowed),
916918
isMaxAllowedValid = typeof params.maxAllowed === 'undefined' ||
917919
qty <= utils.parseNumber(params.maxAllowed),
918920
isQtyIncrementsValid = typeof params.qtyIncrements === 'undefined' ||
919921
qty % utils.parseNumber(params.qtyIncrements) === 0;
920922

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

lib/web/mage/validation.js

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,18 +1566,53 @@
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+
result = false,
1571+
// obtain values for validation
1572+
qty = $.mage.parseNumber(value),
15711573
isMinAllowedValid = typeof params.minAllowed === 'undefined' ||
15721574
qty >= $.mage.parseNumber(params.minAllowed),
15731575
isMaxAllowedValid = typeof params.maxAllowed === 'undefined' ||
15741576
qty <= $.mage.parseNumber(params.maxAllowed),
15751577
isQtyIncrementsValid = typeof params.qtyIncrements === 'undefined' ||
15761578
qty % $.mage.parseNumber(params.qtyIncrements) === 0;
15771579

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

0 commit comments

Comments
 (0)