Skip to content

Commit 1067bf6

Browse files
committed
Merge remote-tracking branch 'origin/MC-32617' into 2.4-develop-pr135
2 parents e1dd62c + 08f7c0b commit 1067bf6

File tree

5 files changed

+115
-23
lines changed

5 files changed

+115
-23
lines changed

app/code/Magento/Catalog/view/adminhtml/web/catalog/product/composite/configure.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ define([
6464
click: function () {
6565
self.onConfirmBtn();
6666
}
67-
}]
67+
}],
68+
closed: function () {
69+
self.clean('window');
70+
},
6871
});
6972
});
7073
},
@@ -406,6 +409,7 @@ define([
406409
this.blockMsgError.innerHTML = response.message;
407410
this._showWindow();
408411

412+
jQuery(this.blockForm).trigger('processStop');
409413
return false;
410414
}
411415
}

app/code/Magento/CatalogInventory/Model/StockStateProvider.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -105,47 +105,46 @@ public function verifyNotification(StockItemInterface $stockItem)
105105
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
106106
* @SuppressWarnings(PHPMD.NPathComplexity)
107107
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
108+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
108109
*/
109110
public function checkQuoteItemQty(StockItemInterface $stockItem, $qty, $summaryQty, $origQty = 0)
110111
{
111112
$result = $this->objectFactory->create();
112113
$result->setHasError(false);
113-
114114
$qty = $this->getNumber($qty);
115-
116-
/**
117-
* Check quantity type
118-
*/
119-
$result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal());
120-
if (!$stockItem->getIsQtyDecimal()) {
121-
$result->setHasQtyOptionUpdate(true);
122-
$qty = (int) $qty ?: 1;
123-
/**
124-
* Adding stock data to quote item
125-
*/
126-
$result->setItemQty($qty);
127-
$result->setOrigQty((int)$this->getNumber($origQty) ?: 1);
128-
}
115+
$quoteMessage = __('Please correct the quantity for some products.');
129116

130117
if ($stockItem->getMinSaleQty() && $qty < $stockItem->getMinSaleQty()) {
131118
$result->setHasError(true)
132119
->setMessage(__('The fewest you may purchase is %1.', $stockItem->getMinSaleQty() * 1))
133120
->setErrorCode('qty_min')
134-
->setQuoteMessage(__('Please correct the quantity for some products.'))
121+
->setQuoteMessage($quoteMessage)
135122
->setQuoteMessageIndex('qty');
136123
return $result;
137124
}
138125

139126
if ($stockItem->getMaxSaleQty() && $qty > $stockItem->getMaxSaleQty()) {
140127
$result->setHasError(true)
141-
->setMessage(__('The most you may purchase is %1.', $stockItem->getMaxSaleQty() * 1))
128+
->setMessage(__('The requested qty exceeds the maximum qty allowed in shopping cart'))
142129
->setErrorCode('qty_max')
143-
->setQuoteMessage(__('Please correct the quantity for some products.'))
130+
->setQuoteMessage($quoteMessage)
144131
->setQuoteMessageIndex('qty');
145132
return $result;
146133
}
147134

148135
$result->addData($this->checkQtyIncrements($stockItem, $qty)->getData());
136+
137+
$result->setItemIsQtyDecimal($stockItem->getIsQtyDecimal());
138+
if (!$stockItem->getIsQtyDecimal() && (floor($qty) !== $qty)) {
139+
$result->setHasError(true)
140+
->setMessage(__('You cannot use decimal quantity for this product.'))
141+
->setErrorCode('qty_decimal')
142+
->setQuoteMessage($quoteMessage)
143+
->setQuoteMessageIndex('qty');
144+
145+
return $result;
146+
}
147+
149148
if ($result->getHasError()) {
150149
return $result;
151150
}

app/code/Magento/CatalogInventory/Test/Unit/Model/Spi/StockStateProviderTest.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
use PHPUnit\Framework\TestCase;
2222

2323
/**
24+
* Unit tests for \Magento\CatalogInventory\Model\StockStateProvider class.
25+
*
2426
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2527
*/
2628
class StockStateProviderTest extends TestCase
@@ -115,6 +117,9 @@ class StockStateProviderTest extends TestCase
115117
'getProductName',
116118
];
117119

120+
/**
121+
* @inheritDoc
122+
*/
118123
protected function setUp(): void
119124
{
120125
$this->objectManagerHelper = new ObjectManagerHelper($this);
@@ -383,7 +388,7 @@ protected function getVariations()
383388
'suggestQty' => 51,
384389
'getStockQty' => $stockQty,
385390
'checkQtyIncrements' => false,
386-
'checkQuoteItemQty' => false,
391+
'checkQuoteItemQty' => true,
387392
],
388393
],
389394
[
@@ -411,7 +416,7 @@ protected function getVariations()
411416
'getStockQty' => $stockQty,
412417
'checkQtyIncrements' => false,
413418
'checkQuoteItemQty' => true,
414-
]
419+
],
415420
],
416421
[
417422
'values' => [
@@ -438,8 +443,8 @@ protected function getVariations()
438443
'getStockQty' => null,
439444
'checkQtyIncrements' => false,
440445
'checkQuoteItemQty' => true,
441-
]
442-
]
446+
],
447+
],
443448
];
444449
}
445450

app/code/Magento/CatalogInventory/i18n/en_US.csv

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,5 @@ Stock,Stock
7171
"Qty Uses Decimals","Qty Uses Decimals"
7272
"Allow Multiple Boxes for Shipping","Allow Multiple Boxes for Shipping"
7373
"Done","Done"
74+
"The requested qty exceeds the maximum qty allowed in shopping cart","The requested qty exceeds the maximum qty allowed in shopping cart"
75+
"You cannot use decimal quantity for this product.","You cannot use decimal quantity for this product."

dev/tests/integration/testsuite/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart/UpdateTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace Magento\Customer\Controller\Adminhtml\Cart\Product\Composite\Cart;
99

1010
use Magento\Backend\Model\Session;
11+
use Magento\Bundle\Model\Product\OptionList;
1112
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
13+
use Magento\Catalog\Api\ProductRepositoryInterface;
1214
use Magento\Catalog\Model\Product\Option as ProductOption;
1315
use Magento\Catalog\Model\Product\Option\Type\File\ValidatorInfo;
1416
use Magento\Customer\Api\CustomerRepositoryInterface;
@@ -20,6 +22,7 @@
2022
use Magento\Quote\Model\Quote\Item as QuoteItem;
2123
use Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory;
2224
use Magento\Store\Model\StoreManagerInterface;
25+
use Magento\TestFramework\Quote\Model\GetQuoteByReservedOrderId;
2326
use Magento\TestFramework\TestCase\AbstractBackendController;
2427
use PHPUnit\Framework\MockObject\MockObject;
2528

@@ -201,6 +204,85 @@ public function testUpdateSimpleProductOption(): void
201204
$this->assertRedirect($this->stringContains('catalog/product/showUpdateResult'));
202205
}
203206

207+
/**
208+
* Tests updating bundle item quantity in the customer's shopping cart.
209+
*
210+
* @magentoDataFixture Magento/Customer/_files/customer.php
211+
* @magentoDataFixture Magento/Checkout/_files/quote_with_bundle_product.php
212+
* @dataProvider bundleOptionQuantityProvider
213+
* @param string $quantity
214+
* @param string|null $message
215+
* @return void
216+
*/
217+
public function testUpdateBundleOptionQuantity(string $quantity, ?string $message): void
218+
{
219+
$productRepository = $this->_objectManager->get(ProductRepositoryInterface::class);
220+
$bundleOptionList = $this->_objectManager->get(OptionList::class);
221+
$getQuoteByReservedOrderId = $this->_objectManager->get(GetQuoteByReservedOrderId::class);
222+
223+
$bundleProduct = $productRepository->get('bundle-product');
224+
$bundleOptions = $bundleOptionList->getItems($bundleProduct);
225+
$option = reset($bundleOptions);
226+
$productLinks = $option->getProductLinks();
227+
$this->assertNotNull($productLinks[0]);
228+
229+
$customer = $this->customerRepository->get('customer@example.com');
230+
$quote = $getQuoteByReservedOrderId->execute('test_cart_with_bundle');
231+
$quote->assignCustomer($customer);
232+
$this->quoteRepository->save($quote);
233+
$quoteItem = $quote->getItemsCollection()->getFirstItem();
234+
$this->assertNotEmpty($quoteItem->getId());
235+
236+
$postValue = [
237+
'bundle_option' => [
238+
$option->getOptionId() => $productLinks[0]->getId(),
239+
],
240+
'qty' => $quantity,
241+
'id' => $quoteItem->getId(),
242+
'as_js_varname' => 'iFrameResponse',
243+
];
244+
245+
$this->dispatchCompositeCartUpdate(
246+
[
247+
'customer_id' => $customer->getId(),
248+
'website_id' => $customer->getWebsiteId(),
249+
],
250+
$postValue
251+
);
252+
253+
$updateResult = $this->session->getCompositeProductResult();
254+
$this->assertEquals($message, $updateResult->getMessage());
255+
}
256+
257+
/**
258+
* @return array
259+
*/
260+
public function bundleOptionQuantityProvider(): array
261+
{
262+
return [
263+
'Quantity, less than allowed in the Shopping Cart' => [
264+
'0.1',
265+
'The fewest you may purchase is 1.',
266+
],
267+
'Decimal quantity not allowed' => [
268+
'1.1',
269+
'You cannot use decimal quantity for this product.',
270+
],
271+
'Quantity, greater than available' => [
272+
'1000',
273+
'The requested qty is not available',
274+
],
275+
'Quantity, greater than allowed in the Shopping Cart' => [
276+
'100000',
277+
'The requested qty exceeds the maximum qty allowed in shopping cart',
278+
],
279+
'Allowed quantity' => [
280+
'2',
281+
null,
282+
],
283+
];
284+
}
285+
204286
/**
205287
* Prepare quote item options and sku for update.
206288
*

0 commit comments

Comments
 (0)