File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
Test/Unit/Model/Product/Option Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -172,7 +172,9 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt
172172 $ originalValues = $ persistedOption ->getValues ();
173173 $ newValues = $ option ->getData ('values ' );
174174 if ($ newValues ) {
175- $ newValues = $ this ->markRemovedValues ($ newValues , $ originalValues );
175+ if (isset ($ originalValues )) {
176+ $ newValues = $ this ->markRemovedValues ($ newValues , $ originalValues );
177+ }
176178 $ option ->setData ('values ' , $ newValues );
177179 }
178180 }
Original file line number Diff line number Diff line change @@ -267,4 +267,29 @@ public function testSave()
267267 ]);
268268 $ this ->assertEquals ($ this ->optionMock , $ this ->optionRepository ->save ($ this ->optionMock ));
269269 }
270+
271+ public function testSaveWhenOptionTypeWasChanged ()
272+ {
273+ $ productSku = 'simple_product ' ;
274+ $ optionId = 1 ;
275+ $ this ->optionMock ->expects ($ this ->once ())->method ('getProductSku ' )->willReturn ($ productSku );
276+ $ this ->productRepositoryMock
277+ ->expects ($ this ->once ())
278+ ->method ('get ' )
279+ ->with ($ productSku )
280+ ->willReturn ($ this ->productMock );
281+ $ this ->optionMock ->expects ($ this ->any ())->method ('getOptionId ' )->willReturn ($ optionId );
282+ $ this ->productMock ->expects ($ this ->once ())->method ('getOptions ' )->willReturn ([]);
283+ $ this ->optionMock ->expects ($ this ->once ())->method ('getData ' )->with ('values ' )->willReturn ([
284+ ['option_type_id ' => 4 ],
285+ ['option_type_id ' => 5 ]
286+ ]);
287+ $ optionCollection = $ this ->getMockBuilder (\Magento \Catalog \Model \ResourceModel \Product \Option \Collection::class)
288+ ->disableOriginalConstructor ()
289+ ->getMock ();
290+ $ optionCollection ->expects ($ this ->once ())->method ('getProductOptions ' )->willReturn ([$ this ->optionMock ]);
291+ $ this ->optionCollectionFactory ->expects ($ this ->once ())->method ('create ' )->willReturn ($ optionCollection );
292+ $ this ->optionMock ->expects ($ this ->once ())->method ('getValues ' )->willReturn (null );
293+ $ this ->assertEquals ($ this ->optionMock , $ this ->optionRepository ->save ($ this ->optionMock ));
294+ }
270295}
You can’t perform that action at this time.
0 commit comments