Skip to content

Experius 2.3 patch catalog flat #25734

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ public function removeDisabledProducts(array &$ids, $storeId)
['status_global_attr' => $statusAttribute->getBackendTable()],
' status_global_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
. ' AND status_global_attr.store_id = ' . Store::DEFAULT_STORE_ID
. ' AND status_global_attr.' . $statusAttribute->getEntityIdField() . '='
. ' AND status_global_attr.' . $metadata->getLinkField() . '='
. 'product_table.' . $metadata->getLinkField(),
[]
);
$select->joinLeft(
['status_attr' => $statusAttribute->getBackendTable()],
' status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
. ' AND status_attr.store_id = ' . $storeId
. ' AND status_attr.' . $statusAttribute->getEntityIdField() . '='
. ' AND status_attr.' . $metadata->getLinkField() . '='
. 'product_table.' . $metadata->getLinkField(),
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;

use Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction;
use Magento\Catalog\Model\Indexer\Product\Flat\FlatTableBuilder;
use Magento\Catalog\Model\Indexer\Product\Flat\TableBuilder;

/**
* Class Rows reindex action for mass actions
*
*/
class Rows extends \Magento\Catalog\Model\Indexer\Product\Flat\AbstractAction
class Rows extends AbstractAction
{
/**
* @var Eraser
Expand Down Expand Up @@ -67,6 +67,7 @@ public function execute($ids)
foreach ($idsBatches as $changedIds) {
if ($tableExists) {
$this->flatItemEraser->removeDeletedProducts($changedIds, $store->getId());
$this->flatItemEraser->removeDisabledProducts($changedIds, $store->getId());
}
if (!empty($changedIds)) {
$this->_reindex($store->getId(), $changedIds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,63 +3,117 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

declare(strict_types=1);

namespace Magento\Catalog\Model\Indexer\Product\Flat\Action;

use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Catalog\Block\Product\ListProduct;
use Magento\Catalog\Model\Indexer\Product\Flat\Processor;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
use Magento\Catalog\Api\CategoryRepositoryInterface;
use Magento\Framework\View\LayoutInterface;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\Indexer\TestCase;

/**
* Class RowsTest
* Test for \Magento\Catalog\Model\Indexer\Product\Flat\Action\Rows.
*/
class RowsTest extends \Magento\TestFramework\Indexer\TestCase
class RowsTest extends TestCase
{
/**
* @var \Magento\Catalog\Model\Product
* @var Processor
*/
protected $_product;
private $processor;

/**
* @var \Magento\Catalog\Model\Indexer\Product\Flat\Processor
* @var ProductRepositoryInterface
*/
protected $_processor;
private $productRepository;

/**
* @var CategoryRepositoryInterface
*/
private $categoryRepository;

/**
* @var CollectionFactory
*/
private $productCollectionFactory;

/**
* @var LayoutInterface
*/
private $layout;

/**
* @inheritdoc
*/
protected function setUp()
{
$this->_product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\Catalog\Model\Product::class
);
$this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Catalog\Model\Indexer\Product\Flat\Processor::class
);
$objectManager = Bootstrap::getObjectManager();
$this->processor = $objectManager->get(Processor::class);
$this->productRepository = $objectManager->get(ProductRepositoryInterface::class);
$this->categoryRepository = $objectManager->get(CategoryRepositoryInterface::class);
$this->productCollectionFactory = $objectManager->get(CollectionFactory::class);
$this->layout = $objectManager->get(LayoutInterface::class);
}

/**
* Test update category products
*
* @magentoDbIsolation disabled
* @magentoAppIsolation enabled
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
*
* @return void
*/
public function testProductsUpdate()
public function testProductsUpdate(): void
{
$this->_product->load(1);

$this->_processor->reindexList([$this->_product->getId()]);

$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Catalog\Model\CategoryFactory::class
);
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Catalog\Block\Product\ListProduct::class
);
$product = $this->productRepository->getById(1);
$this->processor->reindexList([$product->getId()]);

$category = $categoryFactory->create()->load(2);
$category = $this->categoryRepository->get(2);
$listProduct = $this->layout->createBlock(ListProduct::class);
$layer = $listProduct->getLayer();
$layer->setCurrentCategory($category);
$productCollection = $layer->getProductCollection();

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

/** @var $product \Magento\Catalog\Model\Product */
foreach ($productCollection as $product) {
$this->assertEquals($this->_product->getName(), $product->getName());
$this->assertEquals($this->_product->getShortDescription(), $product->getShortDescription());
/** @var $productItem Product */
foreach ($productCollection as $productItem) {
$this->assertEquals($product->getName(), $productItem->getName());
$this->assertEquals($product->getShortDescription(), $productItem->getShortDescription());
}
}

/**
* Products update with different statuses
*
* @magentoDbIsolation disabled
* @magentoAppArea frontend
* @magentoConfigFixture current_store catalog/frontend/flat_catalog_product 1
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_custom_attribute_in_flat.php
* @magentoDataFixture Magento/Catalog/_files/product_simple_duplicated.php
*
* @return void
*/
public function testProductsDifferentStatusesUpdate(): void
{
$firstProduct = $this->productRepository->get('simple_with_custom_flat_attribute');
$secondProduct = $this->productRepository->get('simple-1');

$this->processor->getIndexer()->setScheduled(true);
$this->productRepository->save($secondProduct->setStatus(Status::STATUS_DISABLED));
$this->processor->reindexList([$firstProduct->getId(), $secondProduct->getId()], true);
$collection = $this->productCollectionFactory->create();

$this->assertCount(1, $collection);
$this->assertEquals($firstProduct->getId(), $collection->getFirstItem()->getId());
}
}