|
3 | 3 | * Copyright © Magento, Inc. All rights reserved.
|
4 | 4 | * See COPYING.txt for license details.
|
5 | 5 | */
|
6 |
| -namespace Magento\Catalog\Observer; |
7 | 6 |
|
8 |
| -use Magento\Framework\Event\Observer as EventObserver; |
9 |
| -use Magento\Framework\Event\ObserverInterface; |
| 7 | +namespace Magento\Catalog\Model\Config; |
| 8 | + |
10 | 9 | use Magento\Catalog\Api\Data\ProductAttributeInterface;
|
11 | 10 | use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
|
12 |
| -use Magento\Store\Model\Store; |
13 |
| -use Magento\Framework\App\Config\ReinitableConfigInterface; |
14 | 11 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
| 12 | +use Magento\Store\Model\Store; |
15 | 13 |
|
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 |
21 | 15 | {
|
22 | 16 | /**
|
23 |
| - * @var ReinitableConfigInterface |
| 17 | + * @var SearchCriteriaBuilder |
24 | 18 | */
|
25 |
| - private $config; |
| 19 | + private $searchCriteriaBuilder; |
26 | 20 |
|
27 | 21 | /**
|
28 | 22 | * @var ProductAttributeRepositoryInterface
|
29 | 23 | */
|
30 | 24 | private $productAttributeRepository;
|
31 | 25 |
|
32 | 26 | /**
|
33 |
| - * @var SearchCriteriaBuilder |
34 |
| - */ |
35 |
| - private $searchCriteriaBuilder; |
36 |
| - |
37 |
| - /** |
38 |
| - * @param ReinitableConfigInterface $config |
39 | 27 | * @param ProductAttributeRepositoryInterface $productAttributeRepository
|
40 | 28 | * @param SearchCriteriaBuilder $searchCriteriaBuilder
|
41 | 29 | */
|
42 | 30 | public function __construct(
|
43 |
| - ReinitableConfigInterface $config, |
44 | 31 | ProductAttributeRepositoryInterface $productAttributeRepository,
|
45 | 32 | SearchCriteriaBuilder $searchCriteriaBuilder
|
46 | 33 | ) {
|
47 |
| - $this->config = $config; |
48 | 34 | $this->productAttributeRepository = $productAttributeRepository;
|
49 | 35 | $this->searchCriteriaBuilder = $searchCriteriaBuilder;
|
50 | 36 | }
|
51 | 37 |
|
52 | 38 | /**
|
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 |
55 | 45 | *
|
56 |
| - * @param EventObserver $observer |
57 |
| - * @return void |
58 |
| - * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 46 | + * @retrun void |
59 | 47 | */
|
60 |
| - public function execute(EventObserver $observer) |
| 48 | + public function changeScope(int $value) |
61 | 49 | {
|
62 | 50 | $this->searchCriteriaBuilder->addFilter('frontend_input', 'price');
|
63 | 51 | $criteria = $this->searchCriteriaBuilder->create();
|
64 | 52 |
|
65 |
| - $scope = $this->config->getValue(Store::XML_PATH_PRICE_SCOPE); |
66 |
| - $scope = ($scope == Store::PRICE_SCOPE_WEBSITE) |
| 53 | + $scope = ($value === Store::PRICE_SCOPE_WEBSITE) |
67 | 54 | ? ProductAttributeInterface::SCOPE_WEBSITE_TEXT
|
68 | 55 | : ProductAttributeInterface::SCOPE_GLOBAL_TEXT;
|
69 | 56 |
|
|
0 commit comments