Skip to content

Commit 7cd05c3

Browse files
MC-38050: Price Sorting Is not working
1 parent 7adea3a commit 7cd05c3

File tree

1 file changed

+113
-0
lines changed
  • dev/tests/integration/testsuite/Magento/Bundle/Model/ResourceModel/Indexer

1 file changed

+113
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Bundle\Model\ResourceModel\Indexer;
8+
9+
use Magento\Catalog\Api\ProductRepositoryInterface;
10+
use Magento\Catalog\Model\Indexer\Product\Price;
11+
use Magento\Customer\Model\Group;
12+
use Magento\Framework\Indexer\ActionInterface;
13+
use Magento\Framework\ObjectManagerInterface;
14+
use Magento\Store\Api\WebsiteRepositoryInterface;
15+
use Magento\TestFramework\Catalog\Model\Product\Price\GetPriceIndexDataByProductId;
16+
use Magento\CatalogInventory\Model\Indexer\Stock;
17+
use Magento\TestFramework\Helper\Bootstrap;
18+
use PHPUnit\Framework\TestCase;
19+
20+
class PriceTest extends TestCase
21+
{
22+
/**
23+
* @var ObjectManagerInterface
24+
*/
25+
private $objectManager;
26+
27+
/**
28+
* @var ActionInterface
29+
*/
30+
private $indexer;
31+
32+
/**
33+
* @var GetPriceIndexDataByProductId
34+
*/
35+
private $getPriceIndexDataByProductId;
36+
37+
/**
38+
* @var ProductRepositoryInterface
39+
*/
40+
private $productRepository;
41+
42+
/**
43+
* @var WebsiteRepositoryInterface
44+
*/
45+
private $websiteRepository;
46+
47+
/**
48+
* @var Stock
49+
*/
50+
private $stockIndexer;
51+
52+
/**
53+
* @inheritDoc
54+
*/
55+
protected function setUp(): void
56+
{
57+
$this->objectManager = Bootstrap::getObjectManager();
58+
$this->indexer = $this->objectManager->get(Price::class);
59+
$this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class);
60+
$this->getPriceIndexDataByProductId = $this->objectManager->get(GetPriceIndexDataByProductId::class);
61+
$this->websiteRepository = $this->objectManager->get(WebsiteRepositoryInterface::class);
62+
$this->stockIndexer = $this->objectManager->get(Stock::class);
63+
}
64+
65+
/**
66+
* Test get bundle index price if enabled show out off stock
67+
*
68+
* @magentoDbIsolation disabled
69+
* @magentoAppIsolation enabled
70+
* @magentoDataFixture Magento/Bundle/_files/bundle_product_with_dynamic_price.php
71+
* @magentoConfigFixture default_store cataloginventory/options/show_out_of_stock 1
72+
*
73+
* @return void
74+
*/
75+
public function testExecuteRowWithShowOutOfStock(): void
76+
{
77+
78+
$expectedPrices = [
79+
'price' => 0,
80+
'final_price' => 0,
81+
'min_price' => 15.99,
82+
'max_price' => 15.99,
83+
'tier_price' => null
84+
];
85+
$product = $this->productRepository->get('simple1');
86+
$product->setStockData(['qty' => 0]);
87+
$this->productRepository->save($product);
88+
$this->stockIndexer->executeRow($product->getId());
89+
$bundleProduct = $this->productRepository->get('bundle_product_with_dynamic_price');
90+
$this->indexer->executeRow($bundleProduct->getId());
91+
$this->assertIndexTableData($bundleProduct->getId(), $expectedPrices);
92+
}
93+
94+
/**
95+
* Asserts price data in index table.
96+
*
97+
* @param int $productId
98+
* @param array $expectedPrices
99+
* @return void
100+
*/
101+
private function assertIndexTableData(int $productId, array $expectedPrices): void
102+
{
103+
$data = $this->getPriceIndexDataByProductId->execute(
104+
$productId,
105+
Group::NOT_LOGGED_IN_ID,
106+
(int)$this->websiteRepository->get('base')->getId()
107+
);
108+
$data = reset($data);
109+
foreach ($expectedPrices as $column => $price) {
110+
$this->assertEquals($price, $data[$column]);
111+
}
112+
}
113+
}

0 commit comments

Comments
 (0)