File tree Expand file tree Collapse file tree 2 files changed +13
-5
lines changed
Test/Unit/Model/Product/Option Expand file tree Collapse file tree 2 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -144,10 +144,16 @@ public function save(\Magento\Catalog\Api\Data\ProductCustomOptionInterface $opt
144
144
$ option ->setData ('store_id ' , $ product ->getStoreId ());
145
145
146
146
if ($ option ->getOptionId ()) {
147
- if (!$ product ->getOptions ()) {
148
- $ product ->getResource ()->load ($ product , $ product ->getId ());
147
+ $ options = $ product ->getOptions ();
148
+ if (!$ options ) {
149
+ $ options = $ this ->getProductOptions ($ product );
149
150
}
150
- $ persistedOption = $ product ->getOptionById ($ option ->getOptionId ());
151
+
152
+ $ persistedOption = array_filter ($ options , function ($ iOption ) use ($ option ) {
153
+ return $ option ->getOptionId () == $ iOption ->getOptionId ();
154
+ });
155
+ $ persistedOption = reset ($ persistedOption );
156
+
151
157
if (!$ persistedOption ) {
152
158
throw new NoSuchEntityException ();
153
159
}
Original file line number Diff line number Diff line change @@ -244,15 +244,17 @@ public function testSaveNoSuchEntityException()
244
244
{
245
245
$ productSku = 'simple_product ' ;
246
246
$ optionId = 1 ;
247
+ $ productOptionId = 2 ;
247
248
$ this ->optionMock ->expects ($ this ->once ())->method ('getProductSku ' )->willReturn ($ productSku );
248
249
$ this ->productRepositoryMock
249
250
->expects ($ this ->once ())
250
251
->method ('get ' )
251
252
->with ($ productSku )
252
253
->willReturn ($ this ->productMock );
254
+ $ productOption = clone $ this ->optionMock ;
253
255
$ this ->optionMock ->expects ($ this ->any ())->method ('getOptionId ' )->willReturn ($ optionId );
254
- $ this -> productMock -> expects ($ this ->once ())->method ('getOptions ' )->willReturn ([ ' some options ' ] );
255
- $ this ->productMock ->expects ($ this ->once ())->method ('getOptionById ' )->with ( $ optionId )-> willReturn (null );
256
+ $ productOption -> expects ($ this ->any ())->method ('getOptionId ' )->willReturn ($ productOptionId );
257
+ $ this ->productMock ->expects ($ this ->once ())->method ('getOptions ' )->willReturn ([ $ productOption ] );
256
258
$ this ->optionRepository ->save ($ this ->optionMock );
257
259
}
258
260
You can’t perform that action at this time.
0 commit comments