Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 01d2739

Browse files
committed
MAGETWO-75221: Unexpected prices missing
1 parent d2d82ac commit 01d2739

File tree

2 files changed

+52
-19
lines changed

2 files changed

+52
-19
lines changed

app/code/Magento/Catalog/Cron/DeleteOutdatedPriceValues.php

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
/**
1515
* 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.
1717
*/
1818
class DeleteOutdatedPriceValues
1919
{
@@ -48,27 +48,46 @@ public function __construct(
4848
}
4949

5050
/**
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.
5252
*
5353
* @return void
5454
*/
5555
public function execute()
5656
{
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+
];
6769

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;
7289
}
90+
91+
return (int)$priceScope === Store::PRICE_SCOPE_GLOBAL;
7392
}
7493
}

dev/tests/integration/testsuite/Magento/Catalog/Cron/DeleteOutdatedPriceValuesTest.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ public function setUp()
5454
*/
5555
public function testExecute()
5656
{
57+
$defaultStorePrice = 10.00;
58+
$secondStorePrice = 9.99;
5759
$secondStoreId = $this->store->load('fixture_second_store')->getId();
5860
/** @var \Magento\Catalog\Model\Product\Action $productAction */
5961
$productAction = $this->objectManager->create(
@@ -85,7 +87,7 @@ public function testExecute()
8587
'add'
8688
);
8789
$product->setStoreId($secondStoreId);
88-
$product->setPrice(9.99);
90+
$product->setPrice($secondStorePrice);
8991

9092
$productResource->save($product);
9193
$attribute = $this->objectManager->get(\Magento\Eav\Model\Config::class)
@@ -94,13 +96,25 @@ public function testExecute()
9496
'price'
9597
);
9698
$this->assertEquals(
97-
'9.99',
99+
$secondStorePrice,
98100
$productResource->getAttributeRawValue($productId, $attribute->getId(), $secondStoreId)
99101
);
100102
/** @var MutableScopeConfigInterface $config */
101103
$config = $this->objectManager->get(
102104
MutableScopeConfigInterface::class
103105
);
106+
107+
$config->setValue(
108+
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
109+
null,
110+
ScopeConfigInterface::SCOPE_TYPE_DEFAULT
111+
);
112+
$this->cron->execute();
113+
$this->assertEquals(
114+
$secondStorePrice,
115+
$productResource->getAttributeRawValue($productId, $attribute->getId(), $secondStoreId)
116+
);
117+
104118
$config->setValue(
105119
\Magento\Store\Model\Store::XML_PATH_PRICE_SCOPE,
106120
\Magento\Store\Model\Store::PRICE_SCOPE_GLOBAL,
@@ -109,7 +123,7 @@ public function testExecute()
109123
/** @var \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig */
110124
$this->cron->execute();
111125
$this->assertEquals(
112-
'10.0000',
126+
$defaultStorePrice,
113127
$productResource->getAttributeRawValue($productId, $attribute->getId(), $secondStoreId)
114128
);
115129
}

0 commit comments

Comments
 (0)