Skip to content

Commit 36570de

Browse files
author
Magently
committed
Improve cyclomatic complexity in Eav modifier
1 parent c63d1e6 commit 36570de

File tree

1 file changed

+17
-6
lines changed
  • app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier

1 file changed

+17
-6
lines changed

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,11 @@ public function modifyData(array $data)
399399

400400
foreach ($attributes as $attribute) {
401401
if (null !== ($attributeValue = $this->setupAttributeData($attribute))) {
402-
if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) {
403-
if ($this->locator->getProduct()->getTypeId() !== ProductType::TYPE_BUNDLE
404-
|| $attribute->getAttributeCode() !== ProductAttributeInterface::CODE_SPECIAL_PRICE
405-
) {
406-
$attributeValue = $this->formatPrice($attributeValue);
407-
}
402+
if ($attribute->getFrontendInput() === 'price'
403+
&& is_scalar($attributeValue)
404+
&& !$this->isBundleSpecialPrice($attribute)
405+
) {
406+
$attributeValue = $this->formatPrice($attributeValue);
408407
}
409408
$data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue;
410409
}
@@ -414,6 +413,18 @@ public function modifyData(array $data)
414413
return $data;
415414
}
416415

416+
/**
417+
* Obtain if current product is bundle and given attribute is special_price
418+
*
419+
* @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute
420+
* @return bool
421+
*/
422+
private function isBundleSpecialPrice(ProductAttributeInterface $attribute)
423+
{
424+
return $this->locator->getProduct()->getTypeId() === ProductType::TYPE_BUNDLE
425+
&& $attribute->getAttributeCode() === ProductAttributeInterface::CODE_SPECIAL_PRICE;
426+
}
427+
417428
/**
418429
* Resolve data persistence
419430
*

0 commit comments

Comments
 (0)