Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DeleteOutdatedPriceValues.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Catalog\Cron;
7 
9 use Magento\Eav\Api\AttributeRepositoryInterface as AttributeRepository;
13 
19 {
23  private $resource;
24 
28  private $attributeRepository;
29 
33  private $scopeConfig;
34 
40  public function __construct(
41  ResourceConnection $resource,
42  AttributeRepository $attributeRepository,
43  ScopeConfig $scopeConfig
44  ) {
45  $this->resource = $resource;
46  $this->attributeRepository = $attributeRepository;
47  $this->scopeConfig = $scopeConfig;
48  }
49 
55  public function execute()
56  {
57  if (!$this->isPriceScopeSetToGlobal()) {
58  return;
59  }
60 
62  $priceAttribute = $this->attributeRepository
64  $connection = $this->resource->getConnection();
65  $conditions = [
66  $connection->quoteInto('attribute_id = ?', $priceAttribute->getId()),
67  $connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID),
68  ];
69 
70  $connection->delete(
71  $priceAttribute->getBackend()->getTable(),
72  $conditions
73  );
74  }
75 
84  private function isPriceScopeSetToGlobal()
85  {
86  $priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE);
87  if ($priceScope === null) {
88  return false;
89  }
90 
91  return (int)$priceScope === Store::PRICE_SCOPE_GLOBAL;
92  }
93 }
$resource
Definition: bulk.php:12
__construct(ResourceConnection $resource, AttributeRepository $attributeRepository, ScopeConfig $scopeConfig)
$connection
Definition: bulk.php:13