10
10
use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
11
11
use Magento \Framework \Webapi \Rest \Request ;
12
12
use Magento \Integration \Api \CustomerTokenServiceInterface ;
13
+ use Magento \Quote \Model \Quote ;
14
+ use Magento \Quote \Model \QuoteIdMask ;
13
15
use Magento \TestFramework \Helper \Bootstrap ;
14
16
use Magento \TestFramework \ObjectManager ;
15
17
use Magento \TestFramework \TestCase \WebapiAbstract ;
@@ -29,6 +31,11 @@ class CartAddingItemsTest extends WebapiAbstract
29
31
*/
30
32
private $ productResource ;
31
33
34
+ /**
35
+ * @var array
36
+ */
37
+ private $ createdQuotes = [];
38
+
32
39
/**
33
40
* @inheritDoc
34
41
*/
@@ -38,6 +45,71 @@ protected function setUp(): void
38
45
$ this ->productResource = $ this ->objectManager ->get (ProductResource::class);
39
46
}
40
47
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
+
41
113
/**
42
114
* Test price for cart after adding product to.
43
115
*
@@ -94,10 +166,11 @@ public function testPriceForCreatingQuoteFromEmptyCart()
94
166
$ paymentInfo = $ this ->_webApiCall ($ serviceInfoForGettingPaymentInfo );
95
167
$ this ->assertEquals ($ paymentInfo ['totals ' ]['grand_total ' ], 10 );
96
168
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();
101
174
}
102
175
103
176
/**
@@ -163,6 +236,7 @@ public function testAddToCartGroupedCustomQuantity(): void
163
236
foreach ($ quote ->getAllItems () as $ item ) {
164
237
$ this ->assertEquals ($ qtyData [$ item ->getProductId ()], $ item ->getQty ());
165
238
}
239
+ $ this ->createdQuotes [] = $ quoteId ;
166
240
}
167
241
168
242
/**
@@ -210,6 +284,8 @@ public function testAddToCartGroupedCustomQuantityNotAllParamsSpecified(): void
210
284
]
211
285
];
212
286
287
+ $ this ->createdQuotes [] = $ quoteId ;
288
+
213
289
$ this ->expectException (\Exception::class);
214
290
$ this ->expectExceptionMessage ('Please specify id and qty for grouped options. ' );
215
291
0 commit comments