From 0f579fa086a6e220e038261366a3e9274d7f63d5 Mon Sep 17 00:00:00 2001 From: rogerdz Date: Fri, 13 Jun 2025 04:34:07 +0000 Subject: [PATCH 1/4] Incorrect Scope Assigned to Price Attributes at Creation --- .../ChangePriceAttributeScopeOnCreate.php | 48 +++++++++++++++++++ app/code/Magento/Catalog/etc/events.xml | 3 ++ 2 files changed, 51 insertions(+) create mode 100644 app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php diff --git a/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php b/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php new file mode 100644 index 0000000000000..33f1e35edcbf4 --- /dev/null +++ b/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php @@ -0,0 +1,48 @@ +getEvent()->getAttribute(); + if (empty($attribute->getId) && $attribute->getFrontendInput() == 'price') { + $scope = $this->catalogData->getPriceScope(); + $scope = ($scope == Store::PRICE_SCOPE_WEBSITE) + ? ProductAttributeInterface::SCOPE_WEBSITE_TEXT + : ProductAttributeInterface::SCOPE_GLOBAL_TEXT; + $attribute->setScope($scope); + } + return $this; + } +} diff --git a/app/code/Magento/Catalog/etc/events.xml b/app/code/Magento/Catalog/etc/events.xml index 64505d8c18105..b0373000cd4bb 100644 --- a/app/code/Magento/Catalog/etc/events.xml +++ b/app/code/Magento/Catalog/etc/events.xml @@ -70,4 +70,7 @@ + + + From 6160001b226b2e149e1ccd2b8889632d228c2e7d Mon Sep 17 00:00:00 2001 From: rogerdz Date: Fri, 13 Jun 2025 04:37:18 +0000 Subject: [PATCH 2/4] update code --- .../Catalog/Observer/ChangePriceAttributeScopeOnCreate.php | 2 +- app/code/Magento/Catalog/etc/events.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php b/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php index 33f1e35edcbf4..55a343817fad8 100644 --- a/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php +++ b/app/code/Magento/Catalog/Observer/ChangePriceAttributeScopeOnCreate.php @@ -30,7 +30,7 @@ public function __construct( /** * Change scope for price attribute when create * - * @param \EventObserver $observer + * @param EventObserver $observer * @return $this */ public function execute(EventObserver $observer) diff --git a/app/code/Magento/Catalog/etc/events.xml b/app/code/Magento/Catalog/etc/events.xml index b0373000cd4bb..dba27c0b155e1 100644 --- a/app/code/Magento/Catalog/etc/events.xml +++ b/app/code/Magento/Catalog/etc/events.xml @@ -71,6 +71,6 @@ - + From c66f2cf24bd9f718c7c87a98be3f164c229b13dd Mon Sep 17 00:00:00 2001 From: rogerdz Date: Fri, 13 Jun 2025 06:21:07 +0000 Subject: [PATCH 3/4] add test --- .../Attribute/Save/AttributePriceTest.php | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php index 8eda6be968946..0b2eaa5c46134 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php @@ -1,12 +1,13 @@ assertEquals( + $this->getAttribute()->getIsGlobal(), + ProductAttributeInterface::SCOPE_WEBSITE_TEXT + ); + } + /** * @inheritdoc */ From 213c887147fa26ca3e04d2504aa7286ac247060f Mon Sep 17 00:00:00 2001 From: rogerdz Date: Mon, 16 Jun 2025 03:59:54 +0000 Subject: [PATCH 4/4] update code --- .../Model/Product/Attribute/Save/AttributePriceTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php index 0b2eaa5c46134..0cf324e175a90 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/Product/Attribute/Save/AttributePriceTest.php @@ -58,10 +58,7 @@ public function testDefaultValue(string $productSku): void */ public function testScopePriceAttribute() { - $this->assertEquals( - $this->getAttribute()->getIsGlobal(), - ProductAttributeInterface::SCOPE_WEBSITE_TEXT - ); + $this->assertTrue($this->getAttribute()->isScopeWebsite()); } /**