Skip to content

Commit ec232e8

Browse files
committed
Merge remote-tracking branch 'origin/MC-38050' into 2.4-develop-pr45
2 parents f9bb650 + 6034ada commit ec232e8

File tree

2 files changed

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

2 files changed

+121
-0
lines changed

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Customer\Model\Indexer\CustomerGroupDimensionProvider;
1818
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
1919
use Magento\Catalog\Model\Product\Attribute\Source\Status;
20+
use Magento\CatalogInventory\Model\Stock;
2021

2122
/**
2223
* Bundle products Price indexer resource model
@@ -624,6 +625,13 @@ private function calculateDynamicBundleSelectionPrice($dimensions)
624625
'tier_price' => $tierExpr,
625626
]
626627
);
628+
$select->join(
629+
['si' => $this->getTable('cataloginventory_stock_status')],
630+
'si.product_id = bs.product_id',
631+
[]
632+
);
633+
$select->where('si.stock_status = ?', Stock::STOCK_IN_STOCK);
634+
627635
$this->tableMaintainer->insertFromSelect($select, $this->getBundleSelectionTable(), []);
628636
}
629637

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)