Skip to content

Commit ebbb706

Browse files
committed
Merge remote-tracking branch 'origin/MC-23506' into 2.4-develop-pr145
2 parents fd1f04d + 5b90c8b commit ebbb706

File tree

3 files changed

+101
-15
lines changed

3 files changed

+101
-15
lines changed

app/code/Magento/GroupedProduct/Model/Product/Type/Grouped.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,12 @@ protected function getProductInfo(\Magento\Framework\DataObject $buyRequest, $pr
351351
if ($isStrictProcessMode && !$subProduct->getQty() && $subProduct->isSalable()) {
352352
return __('Please specify the quantity of product(s).')->render();
353353
}
354-
$productsInfo[$subProduct->getId()] = $subProduct->isSalable() ? (float)$subProduct->getQty() : 0;
354+
if (isset($buyRequest['qty']) && !isset($buyRequest['super_group'])) {
355+
$subProductQty = (float)$subProduct->getQty() * (float)$buyRequest['qty'];
356+
$productsInfo[$subProduct->getId()] = $subProduct->isSalable() ? $subProductQty : 0;
357+
} else {
358+
$productsInfo[$subProduct->getId()] = $subProduct->isSalable() ? (float)$subProduct->getQty() : 0;
359+
}
355360
}
356361
}
357362

dev/tests/api-functional/testsuite/Magento/Quote/Api/CartAddingItemsTest.php

Lines changed: 80 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Magento\Catalog\Model\ResourceModel\Product as ProductResource;
1111
use Magento\Framework\Webapi\Rest\Request;
1212
use Magento\Integration\Api\CustomerTokenServiceInterface;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Quote\Model\QuoteIdMask;
1315
use Magento\TestFramework\Helper\Bootstrap;
1416
use Magento\TestFramework\ObjectManager;
1517
use Magento\TestFramework\TestCase\WebapiAbstract;
@@ -29,6 +31,11 @@ class CartAddingItemsTest extends WebapiAbstract
2931
*/
3032
private $productResource;
3133

34+
/**
35+
* @var array
36+
*/
37+
private $createdQuotes = [];
38+
3239
/**
3340
* @inheritDoc
3441
*/
@@ -38,6 +45,71 @@ protected function setUp(): void
3845
$this->productResource = $this->objectManager->get(ProductResource::class);
3946
}
4047

48+
protected function tearDown(): void
49+
{
50+
/** @var Quote $quote */
51+
$quote = $this->objectManager->create(Quote::class);
52+
foreach ($this->createdQuotes as $quoteId) {
53+
$quote->load($quoteId);
54+
$quote->delete();
55+
}
56+
}
57+
58+
/**
59+
* Test qty for cart after adding grouped product qty specified only for goruped product.
60+
*
61+
* @magentoApiDataFixture Magento/GroupedProduct/_files/product_grouped_with_simple.php
62+
* @magentoApiDataFixture Magento/Customer/_files/customer_one_address.php
63+
* @return void
64+
*/
65+
public function testAddToCartGroupedWithParentQuantity(): void
66+
{
67+
$this->_markTestAsRestOnly();
68+
69+
// Get customer ID token
70+
/** @var CustomerTokenServiceInterface $customerTokenService */
71+
$customerTokenService = $this->objectManager->create(CustomerTokenServiceInterface::class);
72+
$token = $customerTokenService->createCustomerAccessToken(
73+
'customer_one_address@test.com',
74+
'password'
75+
);
76+
77+
// Creating empty cart for registered customer.
78+
$serviceInfo = [
79+
'rest' => [
80+
'resourcePath' => '/V1/carts/mine',
81+
'httpMethod' => Request::HTTP_METHOD_POST,
82+
'token' => $token
83+
]
84+
];
85+
86+
$quoteId = $this->_webApiCall($serviceInfo, ['customerId' => 999]); // customerId 999 will get overridden
87+
$this->assertGreaterThan(0, $quoteId);
88+
89+
/** @var CartRepositoryInterface $cartRepository */
90+
$cartRepository = $this->objectManager->get(CartRepositoryInterface::class);
91+
$quote = $cartRepository->get($quoteId);
92+
93+
$quoteItems = $quote->getItemsCollection();
94+
foreach ($quoteItems as $item) {
95+
$quote->removeItem($item->getId())->save();
96+
}
97+
98+
$requestData = [
99+
'cartItem' => [
100+
'quote_id' => $quoteId,
101+
'sku' => 'grouped',
102+
'qty' => 7
103+
]
104+
];
105+
$this->_webApiCall($this->getServiceInfoAddToCart($token), $requestData);
106+
107+
foreach ($quote->getAllItems() as $item) {
108+
$this->assertEquals(7, $item->getQty());
109+
}
110+
$this->createdQuotes[] = $quoteId;
111+
}
112+
41113
/**
42114
* Test price for cart after adding product to.
43115
*
@@ -94,10 +166,11 @@ public function testPriceForCreatingQuoteFromEmptyCart()
94166
$paymentInfo = $this->_webApiCall($serviceInfoForGettingPaymentInfo);
95167
$this->assertEquals($paymentInfo['totals']['grand_total'], 10);
96168

97-
/** @var \Magento\Quote\Model\Quote $quote */
98-
$quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
99-
$quote->load($quoteId);
100-
$quote->delete();
169+
$this->createdQuotes[] = $quoteId;
170+
// /** @var \Magento\Quote\Model\Quote $quote */
171+
// $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class);
172+
// $quote->load($quoteId);
173+
// $quote->delete();
101174
}
102175

103176
/**
@@ -163,6 +236,7 @@ public function testAddToCartGroupedCustomQuantity(): void
163236
foreach ($quote->getAllItems() as $item) {
164237
$this->assertEquals($qtyData[$item->getProductId()], $item->getQty());
165238
}
239+
$this->createdQuotes[] = $quoteId;
166240
}
167241

168242
/**
@@ -210,6 +284,8 @@ public function testAddToCartGroupedCustomQuantityNotAllParamsSpecified(): void
210284
]
211285
];
212286

287+
$this->createdQuotes[] = $quoteId;
288+
213289
$this->expectException(\Exception::class);
214290
$this->expectExceptionMessage('Please specify id and qty for grouped options.');
215291

dev/tests/integration/testsuite/Magento/Customer/_files/customer_one_address_rollback.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,22 @@
1818
$registry->register('isSecureArea', true);
1919
/** @var CustomerRepositoryInterface $customerRepo */
2020
$customerRepo = $objectManager->get(CustomerRepositoryInterface::class);
21-
try {
22-
$customer = $customerRepo->get('customer_with_addresses@test.com');
23-
/** @var AddressRepositoryInterface $addressRepo */
24-
$addressRepo = $objectManager->get(AddressRepositoryInterface::class);
25-
foreach ($customer->getAddresses() as $address) {
26-
$addressRepo->delete($address);
21+
$customersEmails = [
22+
'customer_one_address@test.com',
23+
'customer_with_addresses@test.com',
24+
];
25+
$addressRepo = $objectManager->get(AddressRepositoryInterface::class);
26+
foreach ($customersEmails as $customerEmail) {
27+
try {
28+
$customer = $customerRepo->get($customerEmail);
29+
foreach ($customer->getAddresses() as $address) {
30+
$addressRepo->delete($address);
31+
}
32+
$customerRepo->delete($customer);
33+
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
34+
} catch (NoSuchEntityException $exception) {
35+
//Already deleted
2736
}
28-
$customerRepo->delete($customer);
29-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock
30-
} catch (NoSuchEntityException $exception) {
31-
//Already deleted
3237
}
3338
$registry->unregister('isSecureArea');
3439
$registry->register('isSecureArea', false);

0 commit comments

Comments
 (0)