Skip to content

Commit 52bd6cb

Browse files
committed
Fix price attribute scope change with app:config:import magento#33559
1 parent 496570c commit 52bd6cb

File tree

3 files changed

+28
-33
lines changed

3 files changed

+28
-33
lines changed

app/code/Magento/Catalog/Observer/SwitchPriceAttributeScopeOnConfigChange.php renamed to app/code/Magento/Catalog/Model/Config/PriceScopeChange.php

+15-28
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,54 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
namespace Magento\Catalog\Observer;
76

8-
use Magento\Framework\Event\Observer as EventObserver;
9-
use Magento\Framework\Event\ObserverInterface;
7+
namespace Magento\Catalog\Model\Config;
8+
109
use Magento\Catalog\Api\Data\ProductAttributeInterface;
1110
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
12-
use Magento\Store\Model\Store;
13-
use Magento\Framework\App\Config\ReinitableConfigInterface;
1411
use Magento\Framework\Api\SearchCriteriaBuilder;
12+
use Magento\Store\Model\Store;
1513

16-
/**
17-
* Observer is responsible for changing scope for all price attributes in system
18-
* depending on 'Catalog Price Scope' configuration parameter
19-
*/
20-
class SwitchPriceAttributeScopeOnConfigChange implements ObserverInterface
14+
class PriceScopeChange
2115
{
2216
/**
23-
* @var ReinitableConfigInterface
17+
* @var SearchCriteriaBuilder
2418
*/
25-
private $config;
19+
private $searchCriteriaBuilder;
2620

2721
/**
2822
* @var ProductAttributeRepositoryInterface
2923
*/
3024
private $productAttributeRepository;
3125

3226
/**
33-
* @var SearchCriteriaBuilder
34-
*/
35-
private $searchCriteriaBuilder;
36-
37-
/**
38-
* @param ReinitableConfigInterface $config
3927
* @param ProductAttributeRepositoryInterface $productAttributeRepository
4028
* @param SearchCriteriaBuilder $searchCriteriaBuilder
4129
*/
4230
public function __construct(
43-
ReinitableConfigInterface $config,
4431
ProductAttributeRepositoryInterface $productAttributeRepository,
4532
SearchCriteriaBuilder $searchCriteriaBuilder
4633
) {
47-
$this->config = $config;
4834
$this->productAttributeRepository = $productAttributeRepository;
4935
$this->searchCriteriaBuilder = $searchCriteriaBuilder;
5036
}
5137

5238
/**
53-
* Change scope for all price attributes according to
54-
* 'Catalog Price Scope' configuration parameter value
39+
* Updates the price attributes scope
40+
*
41+
* @param int $value
42+
* @throws \Magento\Framework\Exception\InputException
43+
* @throws \Magento\Framework\Exception\NoSuchEntityException
44+
* @throws \Magento\Framework\Exception\StateException
5545
*
56-
* @param EventObserver $observer
57-
* @return void
58-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
46+
* @retrun void
5947
*/
60-
public function execute(EventObserver $observer)
48+
public function changeScope(int $value)
6149
{
6250
$this->searchCriteriaBuilder->addFilter('frontend_input', 'price');
6351
$criteria = $this->searchCriteriaBuilder->create();
6452

65-
$scope = $this->config->getValue(Store::XML_PATH_PRICE_SCOPE);
66-
$scope = ($scope == Store::PRICE_SCOPE_WEBSITE)
53+
$scope = ($value === Store::PRICE_SCOPE_WEBSITE)
6754
? ProductAttributeInterface::SCOPE_WEBSITE_TEXT
6855
: ProductAttributeInterface::SCOPE_GLOBAL_TEXT;
6956

app/code/Magento/Catalog/Model/Indexer/Product/Price/System/Config/PriceScope.php

+13-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Product\Price\System\Config;
77

8+
use Magento\Catalog\Model\Config\PriceScopeChange;
9+
810
/**
911
* Price scope backend model
1012
*/
@@ -15,14 +17,20 @@ class PriceScope extends \Magento\Framework\App\Config\Value
1517
*/
1618
protected $indexerRegistry;
1719

20+
/**
21+
* @var PriceScopeChange
22+
*/
23+
private $priceScopeChange;
24+
1825
/**
1926
* @param \Magento\Framework\Model\Context $context
2027
* @param \Magento\Framework\Registry $registry
2128
* @param \Magento\Framework\App\Config\ScopeConfigInterface $config
2229
* @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
2330
* @param \Magento\Framework\Indexer\IndexerRegistry $indexerRegistry
24-
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
25-
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
31+
* @param PriceScopeChange $priceScopeChange
32+
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource
33+
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection
2634
* @param array $data
2735
*/
2836
public function __construct(
@@ -31,12 +39,14 @@ public function __construct(
3139
\Magento\Framework\App\Config\ScopeConfigInterface $config,
3240
\Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
3341
\Magento\Framework\Indexer\IndexerRegistry $indexerRegistry,
42+
\Magento\Catalog\Model\Config\PriceScopeChange $priceScopeChange,
3443
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
3544
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
3645
array $data = []
3746
) {
3847
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
3948
$this->indexerRegistry = $indexerRegistry;
49+
$this->priceScopeChange = $priceScopeChange;
4050
}
4151

4252
/**
@@ -61,5 +71,6 @@ public function processValue()
6171
$this->indexerRegistry->get(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID)
6272
->invalidate();
6373
}
74+
$this->priceScopeChange->changeScope((int)$this->getValue());
6475
}
6576
}

app/code/Magento/Catalog/etc/events.xml

-3
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@
5252
<event name="magento_catalog_api_data_categorytreeinterface_load_after">
5353
<observer name="legacy_categorytree_load_after" instance="Magento\Framework\EntityManager\Observer\AfterEntityLoad" />
5454
</event>
55-
<event name="admin_system_config_changed_section_catalog">
56-
<observer name="catalog_update_price_attribute" instance="Magento\Catalog\Observer\SwitchPriceAttributeScopeOnConfigChange" />
57-
</event>
5855
<event name="catalog_product_save_before">
5956
<observer name="set_special_price_start_date" instance="Magento\Catalog\Observer\SetSpecialPriceStartDate" />
6057
</event>

0 commit comments

Comments
 (0)