Skip to content

Commit 9d9b9d0

Browse files
ENGCOM-7019: Experius 2.3 patch catalog flat #25734
- Merge Pull Request #25734 from experius/magento2:experius-2.3-patch-catalog-flat - Merged commits: 1. 2e9d1bb 2. c6d3c8e 3. 2bcec6b 4. 43402b0 5. 7afe256 6. 121886f
2 parents 45b624c + 121886f commit 9d9b9d0

File tree

3 files changed

+87
-32
lines changed
  • app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/Action

3 files changed

+87
-32
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Eraser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ public function removeDisabledProducts(array &$ids, $storeId)
9999
['status_global_attr' => $statusAttribute->getBackendTable()],
100100
' status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
101101
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID
102-
. ' AND status_global_attr.' . $statusAttribute->getEntityIdField() . '='
102+
. ' AND status_global_attr.' . $metadata->getLinkField() . '='
103103
. 'product_table.' . $metadata->getLinkField(),
104104
[]
105105
);
106106
$select->joinLeft(
107107
['status_attr' => $statusAttribute->getBackendTable()],
108108
' status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
109109
. ' AND status_attr.store_id = ' . $storeId
110-
. ' AND status_attr.' . $statusAttribute->getEntityIdField() . '='
110+
. ' AND status_attr.' . $metadata->getLinkField() . '='
111111
. 'product_table.' . $metadata->getLinkField(),
112112
[]
113113
);

app/code/Magento/Catalog/Model/Indexer/Product/Flat/Action/Rows.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;
77

8+
use Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction;
89
use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder;
910
use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder;
1011

1112
/**
1213
* Class Rows reindex action for mass actions
13-
*
1414
*/
15-
class Rows extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
15+
class Rows extends AbstractAction
1616
{
1717
/**
1818
* @var Eraser
@@ -67,6 +67,7 @@ public function execute($ids)
6767
foreach ($idsBatches as $changedIds) {
6868
if ($tableExists) {
6969
$this->flatItemEraser->removeDeletedProducts($changedIds, $store->getId());
70+
$this->flatItemEraser->removeDisabledProducts($changedIds, $store->getId());
7071
}
7172
if (!empty($changedIds)) {
7273
$this->_reindex($store->getId(), $changedIds);

dev/tests/integration/testsuite/Magento/Catalog/Model/Indexer/Product/Flat/Action/RowsTest.php

Lines changed: 82 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,63 +3,117 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;
710

11+
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Block\Product\ListProduct;
13+
use Magento\Catalog\Model\Indexer\Product\Flat\Processor;
14+
use Magento\Catalog\Model\Product;
15+
use Magento\Catalog\Model\Product\Attribute\Source\Status;
16+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
17+
use Magento\Catalog\Api\CategoryRepositoryInterface;
18+
use Magento\Framework\View\LayoutInterface;
19+
use Magento\TestFramework\Helper\Bootstrap;
20+
use Magento\TestFramework\Indexer\TestCase;
21+
822
/**
9-
* Class RowsTest
23+
* Test for \Magento\Catalog\Model\Indexer\Product\Flat\Action\Rows.
1024
*/
11-
class RowsTest extends \Magento\TestFramework\Indexer\TestCase
25+
class RowsTest extends TestCase
1226
{
1327
/**
14-
* @var \Magento\Catalog\Model\Product
28+
* @var Processor
1529
*/
16-
protected $_product;
30+
private $processor;
1731

1832
/**
19-
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
33+
* @var ProductRepositoryInterface
2034
*/
21-
protected $_processor;
35+
private $productRepository;
2236

37+
/**
38+
* @var CategoryRepositoryInterface
39+
*/
40+
private $categoryRepository;
41+
42+
/**
43+
* @var CollectionFactory
44+
*/
45+
private $productCollectionFactory;
46+
47+
/**
48+
* @var LayoutInterface
49+
*/
50+
private $layout;
51+
52+
/**
53+
* @inheritdoc
54+
*/
2355
protected function setUp()
2456
{
25-
$this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
26-
\Magento\Catalog\Model\Product::class
27-
);
28-
$this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
29-
\Magento\Catalog\Model\Indexer\Product\Flat\Processor::class
30-
);
57+
$objectManager = Bootstrap::getObjectManager();
58+
$this->processor = $objectManager->get(Processor::class);
59+
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
60+
$this->categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
61+
$this->productCollectionFactory = $objectManager->get(CollectionFactory::class);
62+
$this->layout = $objectManager->get(LayoutInterface::class);
3163
}
3264

3365
/**
66+
* Test update category products
67+
*
3468
* @magentoDbIsolation disabled
3569
* @magentoAppIsolation enabled
3670
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
3771
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
72+
*
73+
* @return void
3874
*/
39-
public function testProductsUpdate()
75+
public function testProductsUpdate(): void
4076
{
41-
$this->_product->load(1);
42-
43-
$this->_processor->reindexList([$this->_product->getId()]);
44-
45-
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
46-
\Magento\Catalog\Model\CategoryFactory::class
47-
);
48-
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
49-
\Magento\Catalog\Block\Product\ListProduct::class
50-
);
77+
$product = $this->productRepository->getById(1);
78+
$this->processor->reindexList([$product->getId()]);
5179

52-
$category = $categoryFactory->create()->load(2);
80+
$category = $this->categoryRepository->get(2);
81+
$listProduct = $this->layout->createBlock(ListProduct::class);
5382
$layer = $listProduct->getLayer();
5483
$layer->setCurrentCategory($category);
5584
$productCollection = $layer->getProductCollection();
5685

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

59-
/** @var $product \Magento\Catalog\Model\Product */
60-
foreach ($productCollection as $product) {
61-
$this->assertEquals($this->_product->getName(), $product->getName());
62-
$this->assertEquals($this->_product->getShortDescription(), $product->getShortDescription());
88+
/** @var $productItem Product */
89+
foreach ($productCollection as $productItem) {
90+
$this->assertEquals($product->getName(), $productItem->getName());
91+
$this->assertEquals($product->getShortDescription(), $productItem->getShortDescription());
6392
}
6493
}
94+
95+
/**
96+
* Products update with different statuses
97+
*
98+
* @magentoDbIsolation disabled
99+
* @magentoAppArea frontend
100+
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
101+
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_attribute_in_flat.php
102+
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
103+
*
104+
* @return void
105+
*/
106+
public function testProductsDifferentStatusesUpdate(): void
107+
{
108+
$firstProduct = $this->productRepository->get('simple_with_custom_flat_attribute');
109+
$secondProduct = $this->productRepository->get('simple-1');
110+
111+
$this->processor->getIndexer()->setScheduled(true);
112+
$this->productRepository->save($secondProduct->setStatus(Status::STATUS_DISABLED));
113+
$this->processor->reindexList([$firstProduct->getId(), $secondProduct->getId()], true);
114+
$collection = $this->productCollectionFactory->create();
115+
116+
$this->assertCount(1, $collection);
117+
$this->assertEquals($firstProduct->getId(), $collection->getFirstItem()->getId());
118+
}
65119
}

0 commit comments

Comments
 (0)