|
13 | 13 |
|
14 | 14 | /**
|
15 | 15 | * Cron operation is responsible for deleting all product prices on WEBSITE level
|
16 |
| - * in case 'Catalog Price Scope' configuratoin parameter is set to GLOBAL. |
| 16 | + * in case 'Catalog Price Scope' configuration parameter is set to GLOBAL. |
17 | 17 | */
|
18 | 18 | class DeleteOutdatedPriceValues
|
19 | 19 | {
|
@@ -48,27 +48,46 @@ public function __construct(
|
48 | 48 | }
|
49 | 49 |
|
50 | 50 | /**
|
51 |
| - * Delete all price values for non-admin stores if PRICE_SCOPE is global |
| 51 | + * Delete all price values for non-admin stores if PRICE_SCOPE is set to global. |
52 | 52 | *
|
53 | 53 | * @return void
|
54 | 54 | */
|
55 | 55 | public function execute()
|
56 | 56 | {
|
57 |
| - $priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE); |
58 |
| - if ($priceScope == Store::PRICE_SCOPE_GLOBAL) { |
59 |
| - /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */ |
60 |
| - $priceAttribute = $this->attributeRepository |
61 |
| - ->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE); |
62 |
| - $connection = $this->resource->getConnection(); |
63 |
| - $conditions = [ |
64 |
| - $connection->quoteInto('attribute_id = ?', $priceAttribute->getId()), |
65 |
| - $connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID), |
66 |
| - ]; |
| 57 | + if ($this->isPriceScopeSetToGlobal() === false) { |
| 58 | + return; |
| 59 | + } |
| 60 | + |
| 61 | + /** @var \Magento\Catalog\Model\ResourceModel\Eav\Attribute $priceAttribute */ |
| 62 | + $priceAttribute = $this->attributeRepository |
| 63 | + ->get(ProductAttributeInterface::ENTITY_TYPE_CODE, ProductAttributeInterface::CODE_PRICE); |
| 64 | + $connection = $this->resource->getConnection(); |
| 65 | + $conditions = [ |
| 66 | + $connection->quoteInto('attribute_id = ?', $priceAttribute->getId()), |
| 67 | + $connection->quoteInto('store_id != ?', Store::DEFAULT_STORE_ID), |
| 68 | + ]; |
67 | 69 |
|
68 |
| - $connection->delete( |
69 |
| - $priceAttribute->getBackend()->getTable(), |
70 |
| - $conditions |
71 |
| - ); |
| 70 | + $connection->delete( |
| 71 | + $priceAttribute->getBackend()->getTable(), |
| 72 | + $conditions |
| 73 | + ); |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * Checks if price scope config option explicitly equal to global value. |
| 78 | + * |
| 79 | + * Such strict comparision is required to prevent price deleting when |
| 80 | + * price scope config option is null for some reason. |
| 81 | + * |
| 82 | + * @return bool |
| 83 | + */ |
| 84 | + private function isPriceScopeSetToGlobal() |
| 85 | + { |
| 86 | + $priceScope = $this->scopeConfig->getValue(Store::XML_PATH_PRICE_SCOPE); |
| 87 | + if ($priceScope === null) { |
| 88 | + return false; |
72 | 89 | }
|
| 90 | + |
| 91 | + return (int)$priceScope === Store::PRICE_SCOPE_GLOBAL; |
73 | 92 | }
|
74 | 93 | }
|
0 commit comments