7
7
8
8
namespace Magento \Quote \Api ;
9
9
10
+ use Magento \Catalog \Model \Product ;
11
+ use Magento \Catalog \Model \Product \Option ;
12
+ use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
10
13
use Magento \Framework \Webapi \Rest \Request ;
11
14
use Magento \Quote \Model \Quote ;
15
+ use Magento \TestFramework \Helper \Bootstrap ;
12
16
use Magento \TestFramework \TestCase \WebapiAbstract ;
13
17
14
18
/**
@@ -27,7 +31,8 @@ class GuestCartAddingItemsTest extends WebapiAbstract
27
31
28
32
protected function setUp (): void
29
33
{
30
- $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
34
+ $ this ->objectManager = Bootstrap::getObjectManager ();
35
+ $ this ->productResource = $ this ->objectManager ->get (ProductResource::class);
31
36
}
32
37
33
38
/**
@@ -39,6 +44,19 @@ protected function setUp(): void
39
44
public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart ()
40
45
{
41
46
$ this ->_markTestAsRestOnly ();
47
+
48
+ $ productId = $ this ->productResource ->getIdBySku ('simple_with_custom_options ' );
49
+ $ product = $ this ->objectManager ->create (Product::class)->load ($ productId );
50
+ $ customOptionCollection = $ this ->objectManager ->get (Option::class)
51
+ ->getProductOptionCollection ($ product );
52
+ $ customOptions = [];
53
+ foreach ($ customOptionCollection as $ option ) {
54
+ $ customOptions [] = [
55
+ 'option_id ' => $ option ->getId (),
56
+ 'option_value ' => $ option ->getType () !== 'field ' ? 1 : 'test '
57
+ ];
58
+ }
59
+
42
60
// Creating empty cart
43
61
$ serviceInfoForCreatingEmptyCart = [
44
62
'rest ' => [
@@ -55,37 +73,35 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
55
73
'httpMethod ' => Request::HTTP_METHOD_POST ,
56
74
]
57
75
];
76
+
58
77
$ requestData = [
59
78
'cartItem ' => [
60
79
'quote_id ' => $ quoteId ,
61
80
'sku ' => 'simple_with_custom_options ' ,
62
81
'qty ' => 1 ,
63
82
'product_option ' => [
64
83
'extension_attributes ' => [
65
- 'custom_options ' => [
66
- ['option_id ' => 1 , 'option_value ' => 1 ],
67
- ['option_id ' => 2 , 'option_value ' => 1 ],
68
- ['option_id ' => 3 , 'option_value ' => 'test ' ]
69
- ]
84
+ 'custom_options ' => $ customOptions
70
85
]
71
86
]
72
87
]
73
88
];
74
89
$ item = $ this ->_webApiCall ($ serviceInfoForAddingProduct , $ requestData );
75
90
$ this ->assertNotEmpty ($ item );
76
-
91
+ foreach ($ customOptionCollection as $ option ) {
92
+ $ customOptions [] = [
93
+ 'option_id ' => $ option ->getId (),
94
+ 'option_value ' => $ option ->getType () != 'field ' ? 2 : 'test2 '
95
+ ];
96
+ }
77
97
$ requestData = [
78
98
'cartItem ' => [
79
99
'quote_id ' => $ quoteId ,
80
100
'sku ' => 'simple_with_custom_options ' ,
81
101
'qty ' => 1 ,
82
102
'product_option ' => [
83
103
'extension_attributes ' => [
84
- 'custom_options ' => [
85
- ['option_id ' => 1 , 'option_value ' => 2 ],
86
- ['option_id ' => 2 , 'option_value ' => 2 ],
87
- ['option_id ' => 3 , 'option_value ' => 'test2 ' ]
88
- ]
104
+ 'custom_options ' => $ customOptions
89
105
]
90
106
]
91
107
]
0 commit comments