6
6
*/
7
7
namespace Magento \ConfigurableProduct \Api ;
8
8
9
+ use Magento \Catalog \Model \ResourceModel \Eav \Attribute ;
10
+ use Magento \Eav \Model \AttributeRepository ;
11
+
9
12
class LinkManagementTest extends \Magento \TestFramework \TestCase \WebapiAbstract
10
13
{
11
14
const SERVICE_NAME = 'configurableProductLinkManagementV1 ' ;
12
15
const SERVICE_VERSION = 'V1 ' ;
13
16
const RESOURCE_PATH = '/V1/configurable-products ' ;
14
17
18
+ /**
19
+ * @var \Magento\Framework\ObjectManagerInterface
20
+ */
21
+ protected $ objectManager ;
22
+
23
+ /**
24
+ * @var AttributeRepository
25
+ */
26
+ protected $ attributeRepository ;
27
+
28
+ /**
29
+ * Execute per test initialization
30
+ */
31
+ public function setUp ()
32
+ {
33
+ $ this ->objectManager = \Magento \TestFramework \Helper \Bootstrap::getObjectManager ();
34
+ $ this ->attributeRepository = $ this ->objectManager ->get ('Magento\Eav\Model\AttributeRepository ' );
35
+ }
36
+
15
37
/**
16
38
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
17
39
*/
@@ -40,8 +62,8 @@ public function testGetChildren()
40
62
}
41
63
42
64
/**
43
- * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_simple_77.php
44
65
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
66
+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_simple_77.php
45
67
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/delete_association.php
46
68
*/
47
69
public function testAddChild ()
@@ -63,6 +85,146 @@ public function testAddChild()
63
85
$ this ->assertTrue ($ res );
64
86
}
65
87
88
+ /**
89
+ * Test case to cover bug MAGETWO-58401
90
+ * @magentoApiDataFixture Magento/ConfigurableProduct/_files/configurable_attribute.php
91
+ */
92
+ public function testAddChildFullRestCreation ()
93
+ {
94
+ $ this ->createConfigurableProduct ();
95
+ $ attribute = $ this ->attributeRepository ->get ('catalog_product ' , 'test_configurable ' );
96
+ $ attributeValues = $ attribute ->getOptions ();
97
+ $ this ->addOptionToConfigurableProduct ($ attribute ->getAttributeId (), $ attributeValues [1 ]->getValue ());
98
+ $ this ->createSimpleProduct ($ attributeValues [1 ]->getValue ());
99
+
100
+ $ requestData = [
101
+ 'sku ' => 'configurable-product-sku ' ,
102
+ 'childSku ' => 'simple-product-sku '
103
+ ];
104
+ $ serviceInfo = [
105
+ 'rest ' => [
106
+ 'resourcePath ' => self ::RESOURCE_PATH . '/configurable-product-sku/child ' ,
107
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST
108
+ ],
109
+ 'soap ' => [
110
+ 'service ' => self ::SERVICE_NAME ,
111
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
112
+ 'operation ' => self ::SERVICE_NAME . 'AddChild '
113
+ ]
114
+ ];
115
+ $ res = $ this ->_webApiCall ($ serviceInfo , $ requestData );
116
+ $ this ->assertTrue ($ res );
117
+
118
+ // clean up products
119
+ $ serviceInfo = [
120
+ 'rest ' => [
121
+ 'resourcePath ' => '/V1/products/configurable-product-sku ' ,
122
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_DELETE
123
+ ],
124
+ 'soap ' => [
125
+ 'service ' => 'catalogProductRepositoryV1 ' ,
126
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
127
+ 'operation ' => 'catalogProductRepositoryV1DeleteById ' ,
128
+ ],
129
+ ];
130
+ $ this ->_webApiCall ($ serviceInfo , ['sku ' => 'configurable-product-sku ' ]);
131
+ $ serviceInfo = [
132
+ 'rest ' => [
133
+ 'resourcePath ' => '/V1/products/simple-product-sku ' ,
134
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_DELETE
135
+ ],
136
+ 'soap ' => [
137
+ 'service ' => 'catalogProductRepositoryV1 ' ,
138
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
139
+ 'operation ' => 'catalogProductRepositoryV1DeleteById ' ,
140
+ ],
141
+ ];
142
+ $ this ->_webApiCall ($ serviceInfo , ['sku ' => 'simple-product-sku ' ]);
143
+ }
144
+
145
+ protected function createConfigurableProduct ()
146
+ {
147
+ $ requestData = [
148
+ 'product ' => [
149
+ 'sku ' => 'configurable-product-sku ' ,
150
+ 'name ' => 'configurable-product ' ,
151
+ 'type_id ' => 'configurable ' ,
152
+ 'price ' => 50 ,
153
+ 'attribute_set_id ' => 4 ,
154
+ ]
155
+ ];
156
+ $ serviceInfo = [
157
+ 'rest ' => [
158
+ 'resourcePath ' => '/V1/products ' ,
159
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST
160
+ ],
161
+ 'soap ' => [
162
+ 'service ' => 'catalogProductRepositoryV1 ' ,
163
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
164
+ 'operation ' => 'catalogProductRepositoryV1Save ' ,
165
+ ],
166
+ ];
167
+ return $ this ->_webApiCall ($ serviceInfo , $ requestData );
168
+ }
169
+
170
+ protected function addOptionToConfigurableProduct ($ attributeId , $ attributeValue )
171
+ {
172
+ $ requestData = [
173
+ 'sku ' => 'configurable-product-sku ' ,
174
+ 'option ' => [
175
+ 'attribute_id ' => $ attributeId ,
176
+ 'label ' => 'color ' ,
177
+ 'position ' => 0 ,
178
+ 'is_use_default ' => true ,
179
+ 'values ' => [
180
+ ['value_index ' => $ attributeValue ],
181
+ ]
182
+ ]
183
+ ];
184
+ $ serviceInfo = [
185
+ 'rest ' => [
186
+ 'resourcePath ' => '/V1/configurable-products/configurable-product-sku/options ' ,
187
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
188
+ ],
189
+ 'soap ' => [
190
+ 'service ' => 'configurableProductOptionRepositoryV1 ' ,
191
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
192
+ 'operation ' => 'configurableProductOptionRepositoryV1Save ' ,
193
+ ],
194
+ ];
195
+ return $ this ->_webApiCall ($ serviceInfo , $ requestData );
196
+ }
197
+
198
+ protected function createSimpleProduct ($ attributeValue )
199
+ {
200
+ $ requestData = [
201
+ 'product ' => [
202
+ 'sku ' => 'simple-product-sku ' ,
203
+ 'name ' => 'simple-product ' ,
204
+ 'type_id ' => 'simple ' ,
205
+ 'attribute_set_id ' => 4 ,
206
+ 'price ' => 3.62 ,
207
+ 'status ' => 1 ,
208
+ 'visibility ' => 4 ,
209
+ 'custom_attributes ' => [
210
+ ['attribute_code ' => 'test_configurable ' , 'value ' => $ attributeValue ],
211
+ ]
212
+ ]
213
+ ];
214
+ $ serviceInfo = [
215
+ 'rest ' => [
216
+ 'resourcePath ' => '/V1/products ' ,
217
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_POST ,
218
+ ],
219
+ 'soap ' => [
220
+ 'service ' => 'catalogProductRepositoryV1 ' ,
221
+ 'serviceVersion ' => self ::SERVICE_VERSION ,
222
+ 'operation ' => 'catalogProductRepositoryV1Save ' ,
223
+ ],
224
+ ];
225
+ return $ this ->_webApiCall ($ serviceInfo , $ requestData );
226
+ }
227
+
66
228
/**
67
229
* @magentoApiDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
68
230
*/
0 commit comments