From c63d1e636629a0035e23f54cdaa8b0f087f3802b Mon Sep 17 00:00:00 2001 From: Magently Date: Fri, 7 Sep 2018 16:42:27 +0200 Subject: [PATCH 1/3] Don't format Special Price value for Bundle Product --- .../Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php index 2266b84a7e873..41ef898dd4276 100755 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php @@ -32,6 +32,7 @@ use Magento\Ui\DataProvider\Mapper\FormElement as FormElementMapper; use Magento\Ui\DataProvider\Mapper\MetaProperties as MetaPropertiesMapper; use Magento\Eav\Model\ResourceModel\Entity\Attribute\CollectionFactory as AttributeCollectionFactory; +use \Magento\Catalog\Model\Product\Type as ProductType; /** * Class Eav @@ -399,7 +400,11 @@ public function modifyData(array $data) foreach ($attributes as $attribute) { if (null !== ($attributeValue = $this->setupAttributeData($attribute))) { if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) { - $attributeValue = $this->formatPrice($attributeValue); + if ($this->locator->getProduct()->getTypeId() !== ProductType::TYPE_BUNDLE + || $attribute->getAttributeCode() !== ProductAttributeInterface::CODE_SPECIAL_PRICE + ) { + $attributeValue = $this->formatPrice($attributeValue); + } } $data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue; } From 36570de1c7c7045d4a6a89e3b589412da0ff6bb6 Mon Sep 17 00:00:00 2001 From: Magently Date: Fri, 14 Sep 2018 11:12:02 +0200 Subject: [PATCH 2/3] Improve cyclomatic complexity in Eav modifier --- .../Product/Form/Modifier/Eav.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php index 41ef898dd4276..61cf6bb19b66e 100755 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php @@ -399,12 +399,11 @@ public function modifyData(array $data) foreach ($attributes as $attribute) { if (null !== ($attributeValue = $this->setupAttributeData($attribute))) { - if ($attribute->getFrontendInput() === 'price' && is_scalar($attributeValue)) { - if ($this->locator->getProduct()->getTypeId() !== ProductType::TYPE_BUNDLE - || $attribute->getAttributeCode() !== ProductAttributeInterface::CODE_SPECIAL_PRICE - ) { - $attributeValue = $this->formatPrice($attributeValue); - } + if ($attribute->getFrontendInput() === 'price' + && is_scalar($attributeValue) + && !$this->isBundleSpecialPrice($attribute) + ) { + $attributeValue = $this->formatPrice($attributeValue); } $data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue; } @@ -414,6 +413,18 @@ public function modifyData(array $data) return $data; } + /** + * Obtain if current product is bundle and given attribute is special_price + * + * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute + * @return bool + */ + private function isBundleSpecialPrice(ProductAttributeInterface $attribute) + { + return $this->locator->getProduct()->getTypeId() === ProductType::TYPE_BUNDLE + && $attribute->getAttributeCode() === ProductAttributeInterface::CODE_SPECIAL_PRICE; + } + /** * Resolve data persistence * From 194429936730a6350d1f2cde0e09bcaf6f963a35 Mon Sep 17 00:00:00 2001 From: Magently Date: Thu, 25 Oct 2018 11:25:33 +0200 Subject: [PATCH 3/3] Separate the logic of checking if the attribute is the price in Catalog EavModifier --- .../Product/Form/Modifier/Eav.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php index 61cf6bb19b66e..65aaa003f1370 100755 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php @@ -399,10 +399,7 @@ public function modifyData(array $data) foreach ($attributes as $attribute) { if (null !== ($attributeValue = $this->setupAttributeData($attribute))) { - if ($attribute->getFrontendInput() === 'price' - && is_scalar($attributeValue) - && !$this->isBundleSpecialPrice($attribute) - ) { + if ($this->isPriceAttribute($attribute, $attributeValue)) { $attributeValue = $this->formatPrice($attributeValue); } $data[$productId][self::DATA_SOURCE_DEFAULT][$attribute->getAttributeCode()] = $attributeValue; @@ -413,6 +410,20 @@ public function modifyData(array $data) return $data; } + /** + * Obtain if given attribute is a price + * + * @param \Magento\Catalog\Api\Data\ProductAttributeInterface $attribute + * @param string|integer $attributeValue + * @return bool + */ + private function isPriceAttribute(ProductAttributeInterface $attribute, $attributeValue) + { + return $attribute->getFrontendInput() === 'price' + && is_scalar($attributeValue) + && !$this->isBundleSpecialPrice($attribute); + } + /** * Obtain if current product is bundle and given attribute is special_price *