Skip to content

Commit ab79011

Browse files
committed
Merge branch 'ACP2E-4100' of https://github.com/adobe-commerce-tier-4/magento2ce into Tier4-08-13-2025
2 parents 1ba76d3 + a9c7c5b commit ab79011

File tree

2 files changed

+43
-13
lines changed

2 files changed

+43
-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: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@
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

24+
/**
25+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
26+
*/
2227
class SpecialPriceBulkResolverTest extends TestCase
2328
{
2429
/**
@@ -37,10 +42,15 @@ class SpecialPriceBulkResolverTest extends TestCase
3742
private SpecialPriceBulkResolver $specialPriceBulkResolver;
3843

3944
/**
40-
* @var SessionManagerInterface
45+
* @var SessionManagerInterface|MockObject
4146
*/
4247
private SessionManagerInterface $customerSession;
4348

49+
/**
50+
* @var StoreManagerInterface|MockObject
51+
*/
52+
private StoreManagerInterface $storeManager;
53+
4454
/**
4555
* @return void
4656
*/
@@ -52,11 +62,12 @@ protected function setUp(): void
5262
->disableOriginalConstructor()
5363
->addMethods(['getCustomerGroupId'])
5464
->getMockForAbstractClass();
55-
65+
$this->storeManager = $this->createMock(StoreManagerInterface::class);
5666
$this->specialPriceBulkResolver = new SpecialPriceBulkResolver(
5767
$this->resource,
5868
$this->metadataPool,
59-
$this->customerSession
69+
$this->customerSession,
70+
$this->storeManager
6071
);
6172
}
6273

@@ -75,9 +86,19 @@ public function testGenerateSpecialPriceMapNoCollection(): void
7586
*/
7687
public function testGenerateSpecialPriceMapCollection(): void
7788
{
89+
$storeId = 2;
90+
$websiteId = 1;
91+
$customerGroupId = 3;
7892
$product = $this->createMock(Product::class);
79-
80-
$this->customerSession->expects($this->once())->method('getCustomerGroupId')->willReturn(1);
93+
$store = $this->createMock(StoreInterface::class);
94+
$store->expects($this->once())->method('getWebsiteId')->willReturn($websiteId);
95+
$this->storeManager->expects($this->once())
96+
->method('getStore')
97+
->with($storeId)
98+
->willReturn($store);
99+
$this->customerSession->expects($this->once())
100+
->method('getCustomerGroupId')
101+
->willReturn($customerGroupId);
81102
$collection = $this->getMockBuilder(AbstractCollection::class)
82103
->disableOriginalConstructor()
83104
->onlyMethods(['getAllIds', 'getIterator'])
@@ -92,14 +113,13 @@ public function testGenerateSpecialPriceMapCollection(): void
92113
->method('getMetadata')
93114
->with(ProductInterface::class)
94115
->willReturn($metadata);
95-
96116
$connection = $this->getMockBuilder(AdapterInterface::class)
97117
->addMethods(['from', 'joinInner', 'where', 'columns', 'joinLeft'])
98118
->getMockForAbstractClass();
99119
$connection->expects($this->once())->method('select')->willReturnSelf();
100120
$connection->expects($this->once())
101121
->method('from')
102-
->with(['e' => 'catalog_product_super_link'])
122+
->with(['e' => 'catalog_product_entity'])
103123
->willReturnSelf();
104124
$connection->expects($this->exactly(3))
105125
->method('joinLeft')
@@ -130,12 +150,13 @@ public function testGenerateSpecialPriceMapCollection(): void
130150
$this->resource->expects($this->exactly(4))
131151
->method('getTableName')
132152
->willReturnOnConsecutiveCalls(
133-
'catalog_product_super_link',
134153
'catalog_product_entity',
154+
'catalog_product_super_link',
135155
'catalog_product_website',
136156
'catalog_product_index_price'
137157
);
138-
139-
$this->specialPriceBulkResolver->generateSpecialPriceMap(1, $collection);
158+
$result = $this->specialPriceBulkResolver->generateSpecialPriceMap($storeId, $collection);
159+
$expectedResult = [1 => true];
160+
$this->assertEquals($expectedResult, $result);
140161
}
141162
}

0 commit comments

Comments
 (0)