Skip to content

Commit 542efa0

Browse files
author
vnayda
committed
MAGETWO-52717: [GitHub] Configurable product disabling lowest price associated product still shows its price #4419
-- fix integration tests -- fix problem with default store id resolving
1 parent 66500bf commit 542efa0

File tree

5 files changed

+36
-149
lines changed

5 files changed

+36
-149
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -839,9 +839,10 @@
839839
</type>
840840
<preference for="Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface" type="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor" />
841841
<type name="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor">
842-
<arguments>
843-
<argument name="baseSelectProcessors" xsi:type="array">
844-
<item name="status" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\StatusBaseSelectProcessor</item>
845-
</argument>
846-
</arguments>
842+
<arguments>
843+
<argument name="baseSelectProcessors" xsi:type="array">
844+
<item name="status" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\StatusBaseSelectProcessor</item>
845+
</argument>
846+
</arguments>
847+
</type>
847848
</config>

app/code/Magento/Store/Model/StoreManager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function isSingleStoreMode()
150150
public function getStore($storeId = null)
151151
{
152152
if (!isset($storeId) || '' === $storeId || $storeId === true) {
153-
if (!$this->currentStoreId) {
153+
if (null === $this->currentStoreId) {
154154
\Magento\Framework\Profiler::start('store.resolve');
155155
$this->currentStoreId = $this->storeResolver->getCurrentStoreId();
156156
\Magento\Framework\Profiler::stop('store.resolve');

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Pricing/Price/LowestPriceOptionProviderTest.php

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@
77

88
use Magento\Catalog\Api\ProductRepositoryInterface;
99
use Magento\Catalog\Model\Product\Attribute\Source\Status;
10+
use Magento\Store\Model\Store;
11+
use Magento\Store\Model\StoreManagerInterface;
1012
use Magento\TestFramework\Helper\Bootstrap;
1113

12-
/**
13-
* @magentoAppIsolation enabled
14-
*/
1514
class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
1615
{
16+
/**
17+
* @var StoreManagerInterface
18+
*/
19+
private $storeManager;
20+
1721
/**
1822
* @var LowestPriceOptionsProviderInterface
1923
*/
@@ -26,27 +30,37 @@ class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
2630

2731
protected function setUp()
2832
{
33+
$this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
2934
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
3035
$this->lowestPriceOptionsProvider = Bootstrap::getObjectManager()->get(
3136
LowestPriceOptionsProviderInterface::class
3237
);
3338
}
3439

3540
/**
36-
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_simple.php
41+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
3742
*/
3843
public function testGetProductsIfOneOfChildIsDisabled()
3944
{
40-
$configurableProduct = $this->productRepository->get('configurable_product_with_two_simple');
45+
$configurableProduct = $this->productRepository->getById(1, false, null, true);
4146
$lowestPriceChildrenProducts = $this->lowestPriceOptionsProvider->getProducts($configurableProduct);
4247
$this->assertCount(1, $lowestPriceChildrenProducts);
4348
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
4449
$this->assertEquals(10, $lowestPriceChildrenProduct->getPrice());
4550

4651
// load full aggregation root
47-
$lowestPriceChildProduct = $this->productRepository->get($lowestPriceChildrenProduct->getSku());
52+
$lowestPriceChildProduct = $this->productRepository->get(
53+
$lowestPriceChildrenProduct->getSku(),
54+
false,
55+
null,
56+
true
57+
);
4858
$lowestPriceChildProduct->setStatus(Status::STATUS_DISABLED);
59+
// update in global scope
60+
$currentStoreId = $this->storeManager->getStore()->getId();
61+
$this->storeManager->setCurrentStore(Store::DEFAULT_STORE_ID);
4962
$this->productRepository->save($lowestPriceChildProduct);
63+
$this->storeManager->setCurrentStore($currentStoreId);
5064

5165
$lowestPriceChildrenProducts = $this->lowestPriceOptionsProvider->getProducts($configurableProduct);
5266
$this->assertCount(1, $lowestPriceChildrenProducts);
@@ -55,22 +69,25 @@ public function testGetProductsIfOneOfChildIsDisabled()
5569
}
5670

5771
/**
58-
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_simple.php
72+
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
5973
*/
6074
public function testGetProductsIfOneOfChildIsOutOfStock()
6175
{
62-
$configurableProduct = $this->productRepository->get('configurable_product_with_two_simple');
76+
$configurableProduct = $this->productRepository->getById(1, false, null, true);
6377
$lowestPriceChildrenProducts = $this->lowestPriceOptionsProvider->getProducts($configurableProduct);
6478
$this->assertCount(1, $lowestPriceChildrenProducts);
6579
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
6680
$this->assertEquals(10, $lowestPriceChildrenProduct->getPrice());
6781

6882
// load full aggregation root
69-
$lowestPriceChildProduct = $this->productRepository->get($lowestPriceChildrenProduct->getSku());
83+
$lowestPriceChildProduct = $this->productRepository->get(
84+
$lowestPriceChildrenProduct->getSku(),
85+
false,
86+
null,
87+
true
88+
);
7089
$stockItem = $lowestPriceChildProduct->getExtensionAttributes()->getStockItem();
71-
$stockItem->setIsInStock(false);
72-
// TODO: Need to delete next string after MAGETWO-59315 fixing
73-
$lowestPriceChildProduct->setStockData(['is_in_stock' => 0, 'qty' => 0]);
90+
$stockItem->setIsInStock(0);
7491
$this->productRepository->save($lowestPriceChildProduct);
7592

7693
$lowestPriceChildrenProducts = $this->lowestPriceOptionsProvider->getProducts($configurableProduct);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_product_with_two_simple.php

Lines changed: 0 additions & 108 deletions
This file was deleted.

dev/tests/integration/testsuite/Magento/ConfigurableProduct/_files/configurable_product_with_two_simple_rollback.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)