Skip to content

Commit

Permalink
MC-19415: Displayed incorrect price
Browse files Browse the repository at this point in the history
  - revert MC-17919
  • Loading branch information
SeruyV committed Aug 21, 2019
1 parent 88b6bcd commit 9c4c3a0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
{
$connection = $this->getConnection();
$qtyExpr = $connection->getCheckSql('cisi.qty > 0', 'cisi.qty', 0);
$metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
$linkField = $metadata->getLinkField();

$select = $connection->select()->from(
['e' => $this->getTable('catalog_product_entity')],
Expand All @@ -243,6 +245,12 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
['cisi' => $this->getTable('cataloginventory_stock_item')],
'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id',
[]
)->joinInner(
['mcpei' => $this->getTable('catalog_product_entity_int')],
'e.' . $linkField . ' = mcpei.' . $linkField
. ' AND mcpei.attribute_id = ' . $this->_getAttribute('status')->getId()
. ' AND mcpei.value = ' . ProductStatus::STATUS_ENABLED,
[]
)->columns(
['qty' => $qtyExpr]
)->where(
Expand Down Expand Up @@ -284,7 +292,6 @@ protected function _prepareIndexTable($entityIds = null)
*/
protected function _updateIndex($entityIds)
{
$this->deleteOldRecords($entityIds);
$connection = $this->getConnection();
$select = $this->_getStockStatusSelect($entityIds, true);
$select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds, true);
Expand All @@ -307,6 +314,7 @@ protected function _updateIndex($entityIds)
}
}

$this->deleteOldRecords($entityIds);
$this->_updateIndexTable($data);

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,24 @@
*/
namespace Magento\CatalogInventory\Model\Indexer\Stock\Action;

use Magento\TestFramework\Helper\Bootstrap;
use Magento\Framework\ObjectManagerInterface;
use Magento\CatalogInventory\Model\Indexer\Stock\Processor;
use Magento\Catalog\Model\CategoryFactory;
use Magento\Catalog\Block\Product\ListProduct;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Model\Product;
use PHPUnit\Framework\TestCase;

/**
* Full reindex Test
*/
class FullTest extends TestCase
class FullTest extends \PHPUnit\Framework\TestCase
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;

/**
* @var Processor
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
*/
protected $_processor;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->objectManager = Bootstrap::getObjectManager();
$this->_processor = $this->objectManager->get(Processor::class);
$this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\CatalogInventory\Model\Indexer\Stock\Processor::class
);
}

/**
* Reindex all
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
Expand All @@ -49,9 +31,13 @@ public function testReindexAll()
{
$this->_processor->reindexAll();

$categoryFactory = $this->objectManager->get(CategoryFactory::class);
/** @var ListProduct $listProduct */
$listProduct = $this->objectManager->get(ListProduct::class);
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Catalog\Model\CategoryFactory::class
);
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Catalog\Block\Product\ListProduct::class
);

$category = $categoryFactory->create()->load(2);
$layer = $listProduct->getLayer();
Expand All @@ -75,37 +61,4 @@ public function testReindexAll()
$this->assertEquals(100, $product->getQty());
}
}

/**
* Reindex with disabled product
*
* @return void
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
*/
public function testReindexAllWithDisabledProduct(): void
{
$productCollectionFactory = $this->objectManager->get(CollectionFactory::class);
$productCollection = $productCollectionFactory
->create()
->addAttributeToSelect('*')
->addAttributeToFilter('sku', ['eq' => 'simple3'])
->addAttributeToSort('created_at', 'DESC')
->joinField(
'stock_status',
'cataloginventory_stock_status',
'stock_status',
'product_id=entity_id',
'{{table}}.stock_id=1',
'left'
)->load();

$this->assertCount(1, $productCollection);

/** @var Product $product */
foreach ($productCollection as $product) {
$this->assertEquals(1, $product->getData('stock_status'));
}
}
}

0 comments on commit 9c4c3a0

Please sign in to comment.