77
88namespace Magento \Quote \Api ;
99
10+ use Magento \Catalog \Model \Product ;
11+ use Magento \Catalog \Model \Product \Option ;
12+ use Magento \Catalog \Model \ResourceModel \Product as ProductResource ;
1013use Magento \Framework \Webapi \Rest \Request ;
1114use Magento \Quote \Model \Quote ;
15+ use Magento \TestFramework \Helper \Bootstrap ;
1216use Magento \TestFramework \TestCase \WebapiAbstract ;
1317
1418/**
@@ -27,7 +31,8 @@ class GuestCartAddingItemsTest extends WebapiAbstract
2731
2832 protected function setUp (): void
2933 {
30- $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
34+ $ this ->objectManager = Bootstrap::getObjectManager ();
35+ $ this ->productResource = $ this ->objectManager ->get (ProductResource::class);
3136 }
3237
3338 /**
@@ -39,6 +44,19 @@ protected function setUp(): void
3944 public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart ()
4045 {
4146 $ 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+
4260 // Creating empty cart
4361 $ serviceInfoForCreatingEmptyCart = [
4462 'rest ' => [
@@ -55,37 +73,35 @@ public function testAddtoCartWithCustomOptionsForCreatingQuoteFromEmptyCart()
5573 'httpMethod ' => Request::HTTP_METHOD_POST ,
5674 ]
5775 ];
76+
5877 $ requestData = [
5978 'cartItem ' => [
6079 'quote_id ' => $ quoteId ,
6180 'sku ' => 'simple_with_custom_options ' ,
6281 'qty ' => 1 ,
6382 'product_option ' => [
6483 '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
7085 ]
7186 ]
7287 ]
7388 ];
7489 $ item = $ this ->_webApiCall ($ serviceInfoForAddingProduct , $ requestData );
7590 $ 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+ }
7797 $ requestData = [
7898 'cartItem ' => [
7999 'quote_id ' => $ quoteId ,
80100 'sku ' => 'simple_with_custom_options ' ,
81101 'qty ' => 1 ,
82102 'product_option ' => [
83103 '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
89105 ]
90106 ]
91107 ]
0 commit comments