Skip to content

Commit d24f1c1

Browse files
committed
Refactor code to pass review and static test
1 parent 4ff24c2 commit d24f1c1

File tree

3 files changed

+69
-48
lines changed
  • app/code/Magento

3 files changed

+69
-48
lines changed

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Bundle/Option.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
namespace Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle;
77

88
use Magento\Framework\Data\Form\Element\AbstractElement;
9+
use Magento\Store\Model\Store;
910

1011
/**
12+
* Block for rendering option of bundle product
13+
*
1114
* Class \Magento\Bundle\Block\Adminhtml\Catalog\Product\Edit\Tab\Bundle\Option
1215
*/
1316
class Option extends \Magento\Backend\Block\Widget
@@ -343,6 +346,6 @@ public function getRequireSelectHtml()
343346
*/
344347
public function isDefaultStore()
345348
{
346-
return $this->getProduct()->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID;
349+
return $this->getProduct()->getStoreId() == Store::DEFAULT_STORE_ID;
347350
}
348351
}

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Magento\Ui\Component\Form;
1717
use Magento\Ui\Component\Form\Fieldset;
1818
use Magento\Ui\Component\Modal;
19+
use Magento\Store\Model\Store;
1920

2021
/**
2122
* Create Ship Bundle Items and Affect Bundle Product Selections fields
@@ -814,6 +815,6 @@ protected function getSelectionPriceType()
814815
*/
815816
protected function isDefaultStore()
816817
{
817-
return $this->locator->getProduct()->getStoreId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID;
818+
return $this->locator->getProduct()->getStoreId() == Store::DEFAULT_STORE_ID;
818819
}
819820
}

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Tab/Options/Option.php

Lines changed: 63 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@
1212
use Magento\Backend\Block\Widget;
1313
use Magento\Catalog\Model\Product;
1414
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
15+
use Magento\Store\Model\Store;
1516

1617
/**
18+
* Block for rendering option of product
19+
*
1720
* Class \Magento\Catalog\Block\Adminhtml\Product\Edit\Tab\Options\Option
1821
*
1922
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -294,7 +297,6 @@ public function getTemplatesHtml()
294297
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
295298
* @SuppressWarnings(PHPMD.NPathComplexity)
296299
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
297-
* phpcs:disable Generic.Metrics.NestingLevel
298300
*/
299301
public function getOptionValues()
300302
{
@@ -326,7 +328,7 @@ public function getOptionValues()
326328
$value['sort_order'] = $option->getSortOrder();
327329
$value['can_edit_price'] = $this->getCanEditPrice();
328330

329-
if ($this->getProduct()->getStoreId() != \Magento\Store\Model\Store::DEFAULT_STORE_ID) {
331+
if ($this->getProduct()->getStoreId() != Store::DEFAULT_STORE_ID) {
330332
$value['checkboxScopeTitle'] = $this->getCheckboxScopeHtml(
331333
$option->getOptionId(),
332334
'title',
@@ -336,49 +338,7 @@ public function getOptionValues()
336338
}
337339

338340
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);
382342
} else {
383343
$value['price'] = $showPrice ? $this->getPriceValue(
384344
$option->getPrice(),
@@ -390,7 +350,7 @@ public function getOptionValues()
390350
$value['file_extension'] = $option->getFileExtension();
391351
$value['image_size_x'] = $option->getImageSizeX();
392352
$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
394354
&& $scope == \Magento\Store\Model\Store::PRICE_SCOPE_WEBSITE
395355
) {
396356
$value['checkboxScopePrice'] = $this->getCheckboxScopeHtml(
@@ -409,6 +369,63 @@ public function getOptionValues()
409369
return $this->_values;
410370
}
411371

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+
412429
/**
413430
* Retrieve html of scope checkbox
414431
*

0 commit comments

Comments
 (0)