Skip to content

Commit 12e9506

Browse files
authored
Merge pull request #4670 from magento-tsg/2.3.3-develop-pr73
[TSG] Fixes for 2.3 (pr73) (2.3.3-develop)
2 parents 50144fb + 74c17f7 commit 12e9506

File tree

4 files changed

+24
-81
lines changed
  • app/code/Magento
  • dev/tests/integration/testsuite/Magento

4 files changed

+24
-81
lines changed

app/code/Magento/Catalog/Model/ProductLink/Search.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function prepareCollection(
6060
): \Magento\Catalog\Model\ResourceModel\Product\Collection {
6161
$productCollection = $this->productCollectionFactory->create();
6262
$productCollection->addAttributeToSelect(ProductInterface::NAME);
63+
$productCollection->setVisibility($this->catalogVisibility->getVisibleInCatalogIds());
6364
$productCollection->setPage($pageNum, $limit);
6465
$this->filter->addFilter($productCollection, 'fulltext', ['fulltext' => $searchKey]);
6566
$productCollection->setPage($pageNum, $limit);

app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
230230
{
231231
$connection = $this->getConnection();
232232
$qtyExpr = $connection->getCheckSql('cisi.qty > 0', 'cisi.qty', 0);
233+
$metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
234+
$linkField = $metadata->getLinkField();
233235

234236
$select = $connection->select()->from(
235237
['e' => $this->getTable('catalog_product_entity')],
@@ -243,6 +245,12 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
243245
['cisi' => $this->getTable('cataloginventory_stock_item')],
244246
'cisi.stock_id = cis.stock_id AND cisi.product_id = e.entity_id',
245247
[]
248+
)->joinInner(
249+
['mcpei' => $this->getTable('catalog_product_entity_int')],
250+
'e.' . $linkField . ' = mcpei.' . $linkField
251+
. ' AND mcpei.attribute_id = ' . $this->_getAttribute('status')->getId()
252+
. ' AND mcpei.value = ' . ProductStatus::STATUS_ENABLED,
253+
[]
246254
)->columns(
247255
['qty' => $qtyExpr]
248256
)->where(
@@ -284,7 +292,6 @@ protected function _prepareIndexTable($entityIds = null)
284292
*/
285293
protected function _updateIndex($entityIds)
286294
{
287-
$this->deleteOldRecords($entityIds);
288295
$connection = $this->getConnection();
289296
$select = $this->_getStockStatusSelect($entityIds, true);
290297
$select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds, true);
@@ -307,6 +314,7 @@ protected function _updateIndex($entityIds)
307314
}
308315
}
309316

317+
$this->deleteOldRecords($entityIds);
310318
$this->_updateIndexTable($data);
311319

312320
return $this;

dev/tests/integration/testsuite/Magento/Catalog/Controller/Adminhtml/Product/SearchTest.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ public function testExecuteNonExistingSearchKey() : void
3838
->setPostValue('limit', 50);
3939
$this->dispatch('backend/catalog/product/search');
4040
$responseBody = $this->getResponse()->getBody();
41-
$jsonResponse = json_decode($responseBody, true);
42-
$this->assertEmpty($jsonResponse['options']);
41+
$this->assertContains('{"options":[],"total":0}', $responseBody);
4342
}
4443

4544
/**
@@ -58,24 +57,6 @@ public function testExecuteNotVisibleIndividuallyProducts() : void
5857
->setPostValue('limit', 50);
5958
$this->dispatch('backend/catalog/product/search');
6059
$responseBody = $this->getResponse()->getBody();
61-
$jsonResponse = json_decode($responseBody, true);
62-
$this->assertEquals(1, $jsonResponse['total']);
63-
$this->assertCount(1, $jsonResponse['options']);
64-
}
65-
66-
/**
67-
* @magentoDataFixture Magento/Catalog/_files/multiple_mixed_products.php
68-
*/
69-
public function testExecuteEnabledAndDisabledProducts() : void
70-
{
71-
$this->getRequest()
72-
->setPostValue('searchKey', 'simple')
73-
->setPostValue('page', 1)
74-
->setPostValue('limit', 50);
75-
$this->dispatch('backend/catalog/product/search');
76-
$responseBody = $this->getResponse()->getBody();
77-
$jsonResponse = json_decode($responseBody, true);
78-
$this->assertEquals(7, $jsonResponse['total']);
79-
$this->assertCount(7, $jsonResponse['options']);
60+
$this->assertContains('{"options":[],"total":0}', $responseBody);
8061
}
8162
}

dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/FullTest.php

Lines changed: 12 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,24 @@
55
*/
66
namespace Magento\CatalogInventory\Model\Indexer\Stock\Action;
77

8-
use Magento\TestFramework\Helper\Bootstrap;
9-
use Magento\Framework\ObjectManagerInterface;
10-
use Magento\CatalogInventory\Model\Indexer\Stock\Processor;
11-
use Magento\Catalog\Model\CategoryFactory;
12-
use Magento\Catalog\Block\Product\ListProduct;
13-
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
14-
use Magento\Catalog\Model\Product;
15-
use PHPUnit\Framework\TestCase;
16-
178
/**
189
* Full reindex Test
1910
*/
20-
class FullTest extends TestCase
11+
class FullTest extends \PHPUnit\Framework\TestCase
2112
{
2213
/**
23-
* @var ObjectManagerInterface
24-
*/
25-
private $objectManager;
26-
27-
/**
28-
* @var Processor
14+
* @var \Magento\CatalogInventory\Model\Indexer\Stock\Processor
2915
*/
3016
protected $_processor;
3117

32-
/**
33-
* @inheritdoc
34-
*/
3518
protected function setUp()
3619
{
37-
$this->objectManager = Bootstrap::getObjectManager();
38-
$this->_processor = $this->objectManager->get(Processor::class);
20+
$this->_processor = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
21+
\Magento\CatalogInventory\Model\Indexer\Stock\Processor::class
22+
);
3923
}
4024

4125
/**
42-
* Reindex all
43-
*
4426
* @magentoDbIsolation disabled
4527
* @magentoAppIsolation enabled
4628
* @magentoDataFixture Magento/Catalog/_files/product_simple.php
@@ -49,9 +31,13 @@ public function testReindexAll()
4931
{
5032
$this->_processor->reindexAll();
5133

52-
$categoryFactory = $this->objectManager->get(CategoryFactory::class);
53-
/** @var ListProduct $listProduct */
54-
$listProduct = $this->objectManager->get(ListProduct::class);
34+
$categoryFactory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
35+
\Magento\Catalog\Model\CategoryFactory::class
36+
);
37+
/** @var \Magento\Catalog\Block\Product\ListProduct $listProduct */
38+
$listProduct = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
39+
\Magento\Catalog\Block\Product\ListProduct::class
40+
);
5541

5642
$category = $categoryFactory->create()->load(2);
5743
$layer = $listProduct->getLayer();
@@ -75,37 +61,4 @@ public function testReindexAll()
7561
$this->assertEquals(100, $product->getQty());
7662
}
7763
}
78-
79-
/**
80-
* Reindex with disabled product
81-
*
82-
* @return void
83-
* @magentoDbIsolation disabled
84-
* @magentoAppIsolation enabled
85-
* @magentoDataFixture Magento/Catalog/_files/products_with_layered_navigation_attribute.php
86-
*/
87-
public function testReindexAllWithDisabledProduct(): void
88-
{
89-
$productCollectionFactory = $this->objectManager->get(CollectionFactory::class);
90-
$productCollection = $productCollectionFactory
91-
->create()
92-
->addAttributeToSelect('*')
93-
->addAttributeToFilter('sku', ['eq' => 'simple3'])
94-
->addAttributeToSort('created_at', 'DESC')
95-
->joinField(
96-
'stock_status',
97-
'cataloginventory_stock_status',
98-
'stock_status',
99-
'product_id=entity_id',
100-
'{{table}}.stock_id=1',
101-
'left'
102-
)->load();
103-
104-
$this->assertCount(1, $productCollection);
105-
106-
/** @var Product $product */
107-
foreach ($productCollection as $product) {
108-
$this->assertEquals(1, $product->getData('stock_status'));
109-
}
110-
}
11164
}

0 commit comments

Comments
 (0)