12
12
use Magento \Backend \Block \Widget ;
13
13
use Magento \Catalog \Model \Product ;
14
14
use Magento \Catalog \Api \Data \ProductCustomOptionInterface ;
15
+ use Magento \Store \Model \Store ;
15
16
16
17
/**
18
+ * Block for rendering option of product
19
+ *
17
20
* Class \Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option
18
21
*
19
22
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -294,7 +297,6 @@ public function getTemplatesHtml()
294
297
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
295
298
* @SuppressWarnings(PHPMD.NPathComplexity)
296
299
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
297
- * phpcs:disable Generic.Metrics.NestingLevel
298
300
*/
299
301
public function getOptionValues ()
300
302
{
@@ -326,7 +328,7 @@ public function getOptionValues()
326
328
$ value ['sort_order ' ] = $ option ->getSortOrder ();
327
329
$ value ['can_edit_price ' ] = $ this ->getCanEditPrice ();
328
330
329
- if ($ this ->getProduct ()->getStoreId () != \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID ) {
331
+ if ($ this ->getProduct ()->getStoreId () != Store::DEFAULT_STORE_ID ) {
330
332
$ value ['checkboxScopeTitle ' ] = $ this ->getCheckboxScopeHtml (
331
333
$ option ->getOptionId (),
332
334
'title ' ,
@@ -336,49 +338,7 @@ public function getOptionValues()
336
338
}
337
339
338
340
if ($ option ->getGroupByType () == ProductCustomOptionInterface::OPTION_GROUP_SELECT ) {
339
- $ i = 0 ;
340
- $ itemCount = 0 ;
341
- foreach ($ option ->getValues () as $ _value ) {
342
- /* @var $_value \Magento\Catalog\Model\Product\Option\Value */
343
- $ value ['optionValues ' ][$ i ] = [
344
- 'item_count ' => max ($ itemCount , $ _value ->getOptionTypeId ()),
345
- 'option_id ' => $ _value ->getOptionId (),
346
- 'option_type_id ' => $ _value ->getOptionTypeId (),
347
- 'title ' => $ _value ->getTitle (),
348
- 'price ' => $ showPrice ? $ this ->getPriceValue (
349
- $ _value ->getPrice (),
350
- $ _value ->getPriceType ()
351
- ) : '' ,
352
- 'price_type ' => $ showPrice ? $ _value ->getPriceType () : 0 ,
353
- 'sku ' => $ _value ->getSku (),
354
- 'sort_order ' => $ _value ->getSortOrder (),
355
- ];
356
-
357
- if ($ this ->getProduct ()->getStoreId () != \Magento \Store \Model \Store::DEFAULT_STORE_ID ) {
358
- $ value ['optionValues ' ][$ i ]['checkboxScopeTitle ' ] = $ this ->getCheckboxScopeHtml (
359
- $ _value ->getOptionId (),
360
- 'title ' ,
361
- $ _value ->getStoreTitle () === null ,
362
- $ _value ->getOptionTypeId ()
363
- );
364
- $ value ['optionValues ' ][$ i ]['scopeTitleDisabled ' ] = $ _value ->getStoreTitle () === null
365
- ? 'disabled '
366
- : null ;
367
- if ($ scope == \Magento \Store \Model \Store::PRICE_SCOPE_WEBSITE ) {
368
- $ value ['optionValues ' ][$ i ]['checkboxScopePrice ' ] = $ this ->getCheckboxScopeHtml (
369
- $ _value ->getOptionId (),
370
- 'price ' ,
371
- $ _value ->getstorePrice () === null ,
372
- $ _value ->getOptionTypeId (),
373
- ['$(this).up(1).previous() ' ]
374
- );
375
- $ value ['optionValues ' ][$ i ]['scopePriceDisabled ' ] = $ _value ->getStorePrice () === null
376
- ? 'disabled '
377
- : null ;
378
- }
379
- }
380
- $ i ++;
381
- }
341
+ $ value = $ this ->getOptionValueOfGroupSelect ($ value , $ option , $ showPrice , $ scope );
382
342
} else {
383
343
$ value ['price ' ] = $ showPrice ? $ this ->getPriceValue (
384
344
$ option ->getPrice (),
@@ -390,7 +350,7 @@ public function getOptionValues()
390
350
$ value ['file_extension ' ] = $ option ->getFileExtension ();
391
351
$ value ['image_size_x ' ] = $ option ->getImageSizeX ();
392
352
$ value ['image_size_y ' ] = $ option ->getImageSizeY ();
393
- if ($ this ->getProduct ()->getStoreId () != \ Magento \ Store \ Model \ Store::DEFAULT_STORE_ID
353
+ if ($ this ->getProduct ()->getStoreId () != Store::DEFAULT_STORE_ID
394
354
&& $ scope == \Magento \Store \Model \Store::PRICE_SCOPE_WEBSITE
395
355
) {
396
356
$ value ['checkboxScopePrice ' ] = $ this ->getCheckboxScopeHtml (
@@ -409,6 +369,63 @@ public function getOptionValues()
409
369
return $ this ->_values ;
410
370
}
411
371
372
+ /**
373
+ * Get Option Value Of Group Select
374
+ *
375
+ * @param array $value
376
+ * @param \Magento\Catalog\Model\Product\Option $option
377
+ * @param boolean $showPrice
378
+ * @param int $scope
379
+ * @return array
380
+ */
381
+ public function getOptionValueOfGroupSelect ($ value , $ option , $ showPrice , $ scope )
382
+ {
383
+ $ i = 0 ;
384
+ $ itemCount = 0 ;
385
+ foreach ($ option ->getValues () as $ _value ) {
386
+ /* @var $_value \Magento\Catalog\Model\Product\Option\Value */
387
+ $ value ['optionValues ' ][$ i ] = [
388
+ 'item_count ' => max ($ itemCount , $ _value ->getOptionTypeId ()),
389
+ 'option_id ' => $ _value ->getOptionId (),
390
+ 'option_type_id ' => $ _value ->getOptionTypeId (),
391
+ 'title ' => $ _value ->getTitle (),
392
+ 'price ' => $ showPrice ? $ this ->getPriceValue (
393
+ $ _value ->getPrice (),
394
+ $ _value ->getPriceType ()
395
+ ) : '' ,
396
+ 'price_type ' => $ showPrice ? $ _value ->getPriceType () : 0 ,
397
+ 'sku ' => $ _value ->getSku (),
398
+ 'sort_order ' => $ _value ->getSortOrder (),
399
+ ];
400
+
401
+ if ($ this ->getProduct ()->getStoreId () != Store::DEFAULT_STORE_ID ) {
402
+ $ value ['optionValues ' ][$ i ]['checkboxScopeTitle ' ] = $ this ->getCheckboxScopeHtml (
403
+ $ _value ->getOptionId (),
404
+ 'title ' ,
405
+ $ _value ->getStoreTitle () === null ,
406
+ $ _value ->getOptionTypeId ()
407
+ );
408
+ $ value ['optionValues ' ][$ i ]['scopeTitleDisabled ' ] = $ _value ->getStoreTitle () === null
409
+ ? 'disabled '
410
+ : null ;
411
+ if ($ scope == \Magento \Store \Model \Store::PRICE_SCOPE_WEBSITE ) {
412
+ $ value ['optionValues ' ][$ i ]['checkboxScopePrice ' ] = $ this ->getCheckboxScopeHtml (
413
+ $ _value ->getOptionId (),
414
+ 'price ' ,
415
+ $ _value ->getstorePrice () === null ,
416
+ $ _value ->getOptionTypeId (),
417
+ ['$(this).up(1).previous() ' ]
418
+ );
419
+ $ value ['optionValues ' ][$ i ]['scopePriceDisabled ' ] = $ _value ->getStorePrice () === null
420
+ ? 'disabled '
421
+ : null ;
422
+ }
423
+ }
424
+ $ i ++;
425
+ }
426
+ return $ value ;
427
+ }
428
+
412
429
/**
413
430
* Retrieve html of scope checkbox
414
431
*
0 commit comments