@@ -1140,4 +1140,86 @@ public function testSpecialPrice()
1140
1140
$ this ->assertEquals (0 , count (array_intersect ($ attributeCodes , $ missingAttributes )));
1141
1141
$ this ->assertEquals (2 , count (array_intersect ($ attributeCodes , $ expectedAttribute )));
1142
1142
}
1143
+
1144
+ /**
1145
+ * Test saving product with custom attribute of multiselect type
1146
+ *
1147
+ * 1. Create multi-select attribute
1148
+ * 2. Create product and set 2 options out of 3 to multi-select attribute
1149
+ * 3. Verify that 2 options are selected
1150
+ * 4. Unselect all options
1151
+ * 5. Verify that non options are selected
1152
+ *
1153
+ * @magentoApiDataFixture Magento/Catalog/_files/multiselect_attribute.php
1154
+ */
1155
+ public function testUpdateMultiselectAttributes ()
1156
+ {
1157
+ $ multiselectAttributeCode = 'multiselect_attribute ' ;
1158
+ $ multiselectOptions = $ this ->getAttributeOptions ($ multiselectAttributeCode );
1159
+ $ option1 = $ multiselectOptions [1 ]['value ' ];
1160
+ $ option2 = $ multiselectOptions [2 ]['value ' ];
1161
+
1162
+ $ productData = $ this ->getSimpleProductData ();
1163
+ $ productData ['custom_attributes ' ] = [
1164
+ ['attribute_code ' => $ multiselectAttributeCode , 'value ' => "{$ option1 }, {$ option2 }" ]
1165
+ ];
1166
+ $ this ->saveProduct ($ productData , 'all ' );
1167
+
1168
+ $ this ->assertMultiselectValue (
1169
+ $ productData [ProductInterface::SKU ],
1170
+ $ multiselectAttributeCode ,
1171
+ "{$ option1 }, {$ option2 }"
1172
+ );
1173
+
1174
+ $ productData ['custom_attributes ' ] = [
1175
+ ['attribute_code ' => $ multiselectAttributeCode , 'value ' => "" ]
1176
+ ];
1177
+ $ this ->saveProduct ($ productData , 'all ' );
1178
+ $ this ->assertMultiselectValue (
1179
+ $ productData [ProductInterface::SKU ],
1180
+ $ multiselectAttributeCode ,
1181
+ ""
1182
+ );
1183
+ }
1184
+
1185
+ /**
1186
+ * @param string $attributeCode
1187
+ * @return array|bool|float|int|string
1188
+ */
1189
+ private function getAttributeOptions ($ attributeCode )
1190
+ {
1191
+ $ serviceInfo = [
1192
+ 'rest ' => [
1193
+ 'resourcePath ' => '/V1/products/attributes/ ' . $ attributeCode . '/options ' ,
1194
+ 'httpMethod ' => \Magento \Framework \Webapi \Rest \Request::HTTP_METHOD_GET ,
1195
+ ],
1196
+ 'soap ' => [
1197
+ 'service ' => 'catalogProductAttributeOptionManagementV1 ' ,
1198
+ 'serviceVersion ' => 'V1 ' ,
1199
+ 'operation ' => 'catalogProductAttributeOptionManagementV1getItems ' ,
1200
+ ],
1201
+ ];
1202
+
1203
+ return $ this ->_webApiCall ($ serviceInfo , ['attributeCode ' => $ attributeCode ]);
1204
+ }
1205
+
1206
+ /**
1207
+ * @param string $productSku
1208
+ * @param string $multiselectAttributeCode
1209
+ * @param string $expectedMultiselectValue
1210
+ */
1211
+ private function assertMultiselectValue ($ productSku , $ multiselectAttributeCode , $ expectedMultiselectValue )
1212
+ {
1213
+ $ response = $ this ->getProduct ($ productSku , 'all ' );
1214
+ $ customAttributes = $ response ['custom_attributes ' ];
1215
+ $ this ->assertNotEmpty ($ customAttributes );
1216
+ $ multiselectValue = null ;
1217
+ foreach ($ customAttributes as $ customAttribute ) {
1218
+ if ($ customAttribute ['attribute_code ' ] == $ multiselectAttributeCode ) {
1219
+ $ multiselectValue = $ customAttribute ['value ' ];
1220
+ break ;
1221
+ }
1222
+ }
1223
+ $ this ->assertEquals ($ expectedMultiselectValue , $ multiselectValue );
1224
+ }
1143
1225
}
0 commit comments