Skip to content

Commit

Permalink
MAGETWO-52717: [GitHub] Configurable product disabling lowest price a…
Browse files Browse the repository at this point in the history
…ssociated product still shows its price #4419

-- fix integration tests
-- fix problem with default store id resolving
  • Loading branch information
vnayda committed Oct 11, 2016
1 parent 66500bf commit 542efa0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 149 deletions.
11 changes: 6 additions & 5 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,10 @@
</type>
<preference for="Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface" type="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor" />
<type name="Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor">
<arguments>
<argument name="baseSelectProcessors" xsi:type="array">
<item name="status" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\StatusBaseSelectProcessor</item>
</argument>
</arguments>
<arguments>
<argument name="baseSelectProcessors" xsi:type="array">
<item name="status" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\StatusBaseSelectProcessor</item>
</argument>
</arguments>
</type>
</config>
2 changes: 1 addition & 1 deletion app/code/Magento/Store/Model/StoreManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public function isSingleStoreMode()
public function getStore($storeId = null)
{
if (!isset($storeId) || '' === $storeId || $storeId === true) {
if (!$this->currentStoreId) {
if (null === $this->currentStoreId) {
\Magento\Framework\Profiler::start('store.resolve');
$this->currentStoreId = $this->storeResolver->getCurrentStoreId();
\Magento\Framework\Profiler::stop('store.resolve');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\TestFramework\Helper\Bootstrap;

/**
* @magentoAppIsolation enabled
*/
class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase
{
/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @var LowestPriceOptionsProviderInterface
*/
Expand All @@ -26,27 +30,37 @@ class LowestPriceOptionProviderTest extends \PHPUnit_Framework_TestCase

protected function setUp()
{
$this->storeManager = Bootstrap::getObjectManager()->get(StoreManagerInterface::class);
$this->productRepository = Bootstrap::getObjectManager()->get(ProductRepositoryInterface::class);
$this->lowestPriceOptionsProvider = Bootstrap::getObjectManager()->get(
LowestPriceOptionsProviderInterface::class
);
}

/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_simple.php
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*/
public function testGetProductsIfOneOfChildIsDisabled()
{
$configurableProduct = $this->productRepository->get('configurable_product_with_two_simple');
$configurableProduct = $this->productRepository->getById(1, false, null, true);
$lowestPriceChildrenProducts = $this->lowestPriceOptionsProvider->getProducts($configurableProduct);
$this->assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
$this->assertEquals(10, $lowestPriceChildrenProduct->getPrice());

// load full aggregation root
$lowestPriceChildProduct = $this->productRepository->get($lowestPriceChildrenProduct->getSku());
$lowestPriceChildProduct = $this->productRepository->get(
$lowestPriceChildrenProduct->getSku(),
false,
null,
true
);
$lowestPriceChildProduct->setStatus(Status::STATUS_DISABLED);
// update in global scope
$currentStoreId = $this->storeManager->getStore()->getId();
$this->storeManager->setCurrentStore(Store::DEFAULT_STORE_ID);
$this->productRepository->save($lowestPriceChildProduct);
$this->storeManager->setCurrentStore($currentStoreId);

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

/**
* @magentoDataFixture Magento/ConfigurableProduct/_files/configurable_product_with_two_simple.php
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
*/
public function testGetProductsIfOneOfChildIsOutOfStock()
{
$configurableProduct = $this->productRepository->get('configurable_product_with_two_simple');
$configurableProduct = $this->productRepository->getById(1, false, null, true);
$lowestPriceChildrenProducts = $this->lowestPriceOptionsProvider->getProducts($configurableProduct);
$this->assertCount(1, $lowestPriceChildrenProducts);
$lowestPriceChildrenProduct = reset($lowestPriceChildrenProducts);
$this->assertEquals(10, $lowestPriceChildrenProduct->getPrice());

// load full aggregation root
$lowestPriceChildProduct = $this->productRepository->get($lowestPriceChildrenProduct->getSku());
$lowestPriceChildProduct = $this->productRepository->get(
$lowestPriceChildrenProduct->getSku(),
false,
null,
true
);
$stockItem = $lowestPriceChildProduct->getExtensionAttributes()->getStockItem();
$stockItem->setIsInStock(false);
// TODO: Need to delete next string after MAGETWO-59315 fixing
$lowestPriceChildProduct->setStockData(['is_in_stock' => 0, 'qty' => 0]);
$stockItem->setIsInStock(0);
$this->productRepository->save($lowestPriceChildProduct);

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

This file was deleted.

This file was deleted.

0 comments on commit 542efa0

Please sign in to comment.