Skip to content

Commit 22bc2a9

Browse files
committed
ACP2E-4100: Regular price is not visible, even though a special price is applied.
1 parent 6dd3fa9 commit 22bc2a9

File tree

2 files changed

+40
-13
lines changed

2 files changed

+40
-13
lines changed

app/code/Magento/Catalog/Pricing/Price/SpecialPriceBulkResolver.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\EntityManager\MetadataPool;
1414
use Magento\Framework\Session\SessionManagerInterface;
1515
use Magento\Framework\View\Element\Block\ArgumentInterface;
16+
use Magento\Store\Model\StoreManagerInterface;
1617

1718
class SpecialPriceBulkResolver implements SpecialPriceBulkResolverInterface, ArgumentInterface
1819
{
@@ -31,19 +32,27 @@ class SpecialPriceBulkResolver implements SpecialPriceBulkResolverInterface, Arg
3132
*/
3233
private SessionManagerInterface $customerSession;
3334

35+
/**
36+
* @var StoreManagerInterface
37+
*/
38+
private StoreManagerInterface $storeManager;
39+
3440
/**
3541
* @param ResourceConnection $resource
3642
* @param MetadataPool $metadataPool
3743
* @param SessionManagerInterface $customerSession
44+
* @param StoreManagerInterface $storeManager
3845
*/
3946
public function __construct(
4047
ResourceConnection $resource,
4148
MetadataPool $metadataPool,
42-
SessionManagerInterface $customerSession
49+
SessionManagerInterface $customerSession,
50+
StoreManagerInterface $storeManager
4351
) {
4452
$this->resource = $resource;
4553
$this->metadataPool = $metadataPool;
4654
$this->customerSession = $customerSession;
55+
$this->storeManager = $storeManager;
4756
}
4857

4958
/**
@@ -59,7 +68,7 @@ public function generateSpecialPriceMap(int $storeId, ?AbstractCollection $produ
5968
if (!$productCollection) {
6069
return [];
6170
}
62-
71+
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
6372
$metadata = $this->metadataPool->getMetadata(ProductInterface::class);
6473
$connection = $this->resource->getConnection();
6574
$select = $connection->select()
@@ -76,7 +85,7 @@ public function generateSpecialPriceMap(int $storeId, ?AbstractCollection $produ
7685
)
7786
->joinLeft(
7887
['price' => $this->resource->getTableName('catalog_product_index_price')],
79-
'price.entity_id = COALESCE(link.product_id, e.entity_id) AND price.website_id = ' . $storeId .
88+
'price.entity_id = COALESCE(link.product_id, e.entity_id) AND price.website_id = ' . $websiteId .
8089
' AND price.customer_group_id = ' . $this->customerSession->getCustomerGroupId()
8190
)
8291
->where('e.entity_id IN (' . implode(',', $productCollection->getAllIds()) . ')')

app/code/Magento/Catalog/Test/Unit/Pricing/Price/SpecialPriceBulkResolverTest.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Magento\Framework\EntityManager\EntityMetadataInterface;
1717
use Magento\Framework\EntityManager\MetadataPool;
1818
use Magento\Framework\Session\SessionManagerInterface;
19+
use Magento\Store\Api\Data\StoreInterface;
20+
use Magento\Store\Model\StoreManagerInterface;
1921
use PHPUnit\Framework\MockObject\MockObject;
2022
use PHPUnit\Framework\TestCase;
2123

@@ -37,10 +39,15 @@ class SpecialPriceBulkResolverTest extends TestCase
3739
private SpecialPriceBulkResolver $specialPriceBulkResolver;
3840

3941
/**
40-
* @var SessionManagerInterface
42+
* @var SessionManagerInterface|MockObject
4143
*/
4244
private SessionManagerInterface $customerSession;
4345

46+
/**
47+
* @var StoreManagerInterface|MockObject
48+
*/
49+
private StoreManagerInterface $storeManager;
50+
4451
/**
4552
* @return void
4653
*/
@@ -52,11 +59,12 @@ protected function setUp(): void
5259
->disableOriginalConstructor()
5360
->addMethods(['getCustomerGroupId'])
5461
->getMockForAbstractClass();
55-
62+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
5663
$this->specialPriceBulkResolver = new SpecialPriceBulkResolver(
5764
$this->resource,
5865
$this->metadataPool,
59-
$this->customerSession
66+
$this->customerSession,
67+
$this->storeManager
6068
);
6169
}
6270

@@ -75,9 +83,19 @@ public function testGenerateSpecialPriceMapNoCollection(): void
7583
*/
7684
public function testGenerateSpecialPriceMapCollection(): void
7785
{
86+
$storeId = 2;
87+
$websiteId = 1;
88+
$customerGroupId = 3;
7889
$product = $this->createMock(Product::class);
79-
80-
$this->customerSession->expects($this->once())->method('getCustomerGroupId')->willReturn(1);
90+
$store = $this->createMock(StoreInterface::class);
91+
$store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
92+
$this->storeManager->expects($this->once())
93+
->method('getStore')
94+
->with($storeId)
95+
->willReturn($store);
96+
$this->customerSession->expects($this->once())
97+
->method('getCustomerGroupId')
98+
->willReturn($customerGroupId);
8199
$collection = $this->getMockBuilder(AbstractCollection::class)
82100
->disableOriginalConstructor()
83101
->onlyMethods(['getAllIds', 'getIterator'])
@@ -92,14 +110,13 @@ public function testGenerateSpecialPriceMapCollection(): void
92110
->method('getMetadata')
93111
->with(ProductInterface::class)
94112
->willReturn($metadata);
95-
96113
$connection = $this->getMockBuilder(AdapterInterface::class)
97114
->addMethods(['from', 'joinInner', 'where', 'columns', 'joinLeft'])
98115
->getMockForAbstractClass();
99116
$connection->expects($this->once())->method('select')->willReturnSelf();
100117
$connection->expects($this->once())
101118
->method('from')
102-
->with(['e' => 'catalog_product_super_link'])
119+
->with(['e' => 'catalog_product_entity'])
103120
->willReturnSelf();
104121
$connection->expects($this->exactly(3))
105122
->method('joinLeft')
@@ -130,12 +147,13 @@ public function testGenerateSpecialPriceMapCollection(): void
130147
$this->resource->expects($this->exactly(4))
131148
->method('getTableName')
132149
->willReturnOnConsecutiveCalls(
133-
'catalog_product_super_link',
134150
'catalog_product_entity',
151+
'catalog_product_super_link',
135152
'catalog_product_website',
136153
'catalog_product_index_price'
137154
);
138-
139-
$this->specialPriceBulkResolver->generateSpecialPriceMap(1, $collection);
155+
$result = $this->specialPriceBulkResolver->generateSpecialPriceMap($storeId, $collection);
156+
$expectedResult = [1 => true];
157+
$this->assertEquals($expectedResult, $result);
140158
}
141159
}

0 commit comments

Comments
 (0)