Skip to content

Commit 2a2aa4d

Browse files
committed
AC-13594: Special price is not showing correctly for Configurable product's child product (simple product)
Revert changes to use a plugin instead
1 parent a9fd38a commit 2a2aa4d

File tree

3 files changed

+57
-20
lines changed

3 files changed

+57
-20
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
namespace Magento\Catalog\Plugin\Model;
8+
9+
use Magento\Catalog\Model\Config as Subject;
10+
use Magento\Catalog\Model\Product;
11+
use Magento\Eav\Model\Config as EavConfig;
12+
13+
/**
14+
* Plugin to ensure special_price attribute is always loaded in product listings
15+
* even when used_in_product_listing = 0
16+
*/
17+
class ConfigPlugin
18+
{
19+
private const SPECIAL_PRICE_ATTR_CODE = 'special_price';
20+
21+
/**
22+
* @param EavConfig $eavConfig
23+
*/
24+
public function __construct(
25+
private readonly EavConfig $eavConfig
26+
) {
27+
}
28+
29+
/**
30+
* Add special_price attribute to the list of attributes used in product listing
31+
* regardless of its used_in_product_listing setting
32+
*
33+
* @param Subject $subject
34+
* @param array $result
35+
* @return array
36+
*/
37+
public function afterGetAttributesUsedInProductListing(Subject $subject, array $result): array
38+
{
39+
// Check if special_price is already in the result
40+
if (!isset($result[self::SPECIAL_PRICE_ATTR_CODE])) {
41+
// Get the special_price attribute
42+
$specialPriceAttribute = $this->eavConfig->getAttribute(
43+
Product::ENTITY,
44+
self::SPECIAL_PRICE_ATTR_CODE
45+
);
46+
47+
if ($specialPriceAttribute && $specialPriceAttribute->getId()) {
48+
// Add it to the result
49+
$result[self::SPECIAL_PRICE_ATTR_CODE] = $specialPriceAttribute;
50+
}
51+
}
52+
return $result;
53+
}
54+
}

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

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ public function getSpecialPrice()
8484
{
8585
$specialPrice = $this->product->getSpecialPrice();
8686

87-
// If special_price is not loaded (null and attribute not loaded), load it from resource
88-
if ($specialPrice === null && $this->product->getTypeId() === 'simple') {
89-
$specialPrice = $this->getSpecialPriceFromResource();
90-
}
91-
9287
if ($specialPrice !== null && $specialPrice !== false && !$this->isPercentageDiscount()) {
9388
$specialPrice = $this->priceCurrency->convertAndRound($specialPrice);
9489
}
@@ -137,19 +132,4 @@ public function isPercentageDiscount()
137132
return false;
138133
}
139134

140-
/**
141-
* Get special price from resource
142-
*
143-
* @return float|null
144-
*/
145-
private function getSpecialPriceFromResource(): ?float
146-
{
147-
$resource = $this->product->getResource();
148-
$specialPrice = $resource->getAttributeRawValue(
149-
$this->product->getId(),
150-
'special_price',
151-
$this->product->getStoreId()
152-
);
153-
return !is_array($specialPrice) ? $specialPrice : null;
154-
}
155135
}

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,7 @@
124124
</argument>
125125
</arguments>
126126
</type>
127+
<type name="Magento\Catalog\Model\Config">
128+
<plugin name="special_price_listing_plugin" type="Magento\Catalog\Plugin\Model\ConfigPlugin" sortOrder="10" />
129+
</type>
127130
</config>

0 commit comments

Comments
 (0)