Skip to content

Commit f379942

Browse files
committed
ACP2E-64: Bundle Products Special Price Column in Grid should have % sign not currency sign
- Replaced plugin to data provider methodology
1 parent 154a151 commit f379942

File tree

2 files changed

+58
-32
lines changed

2 files changed

+58
-32
lines changed

app/code/Magento/Bundle/Ui/DataProvider/Product/Modifier/Plugin/PriceAttributes.php renamed to app/code/Magento/Bundle/Ui/DataProvider/Product/Modifier/SpecialPriceAttributes.php

Lines changed: 42 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,29 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Bundle\Ui\DataProvider\Product\Modifier\Plugin;
8+
namespace Magento\Bundle\Ui\DataProvider\Product\Modifier;
99

10-
use Magento\Bundle\Model\Product\Type;
11-
use Magento\Catalog\Pricing\Price\SpecialPrice;
12-
use Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes as Subject;
1310
use Magento\Directory\Model\Currency as DirectoryCurrency;
1411
use Magento\Framework\Currency;
1512
use Magento\Framework\Exception\NoSuchEntityException;
1613
use Magento\Framework\Locale\CurrencyInterface;
1714
use Magento\Store\Api\Data\StoreInterface;
1815
use Magento\Store\Model\StoreManagerInterface;
16+
use Magento\Ui\DataProvider\Modifier\ModifierInterface;
17+
use Magento\Bundle\Model\Product\Type;
1918
use Zend_Currency;
2019
use Zend_Currency_Exception;
2120

2221
/**
2322
* Modify product listing price attributes
2423
*/
25-
class PriceAttributes
24+
class SpecialPriceAttributes implements ModifierInterface
2625
{
26+
/**
27+
* @var array
28+
*/
29+
private $priceAttributeList;
30+
2731
/**
2832
* @var StoreManagerInterface
2933
*/
@@ -45,50 +49,58 @@ class PriceAttributes
4549
* @param StoreManagerInterface $storeManager
4650
* @param CurrencyInterface $localeCurrency
4751
* @param DirectoryCurrency $directoryCurrency
52+
* @param array $priceAttributeList
4853
*/
4954
public function __construct(
5055
StoreManagerInterface $storeManager,
5156
CurrencyInterface $localeCurrency,
52-
DirectoryCurrency $directoryCurrency
57+
DirectoryCurrency $directoryCurrency,
58+
array $priceAttributeList = []
5359
) {
5460
$this->storeManager = $storeManager;
5561
$this->localeCurrency = $localeCurrency;
62+
$this->priceAttributeList = $priceAttributeList;
5663
$this->directoryCurrency = $directoryCurrency;
5764
}
5865

5966
/**
60-
* Added % symbol in front of special price for bundle products
61-
*
62-
* @param Subject $subject
63-
* @param array $result
64-
* @return array
65-
* @throws Zend_Currency_Exception
67+
* @inheritdoc
6668
* @throws NoSuchEntityException
67-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
69+
* @throws Zend_Currency_Exception
6870
*/
69-
public function afterModifyData(Subject $subject, array $result): array
71+
public function modifyData(array $data): array
7072
{
71-
if (empty($result)) {
72-
return $result;
73+
if (empty($data) || empty($this->priceAttributeList)) {
74+
return $data;
7375
}
7476

75-
foreach ($result['items'] as &$item) {
76-
if (isset($item[SpecialPrice::PRICE_CODE]) && $item['type_id'] == Type::TYPE_CODE) {
77-
$item[SpecialPrice::PRICE_CODE] =
78-
$this->directoryCurrency->format(
79-
$item[SpecialPrice::PRICE_CODE],
80-
['display' => Zend_Currency::NO_SYMBOL],
81-
false
82-
);
83-
$item[SpecialPrice::PRICE_CODE] =
84-
$this->getCurrency()->toCurrency(
85-
sprintf("%f", $item[SpecialPrice::PRICE_CODE]),
86-
['symbol' => '%']
87-
);
77+
foreach ($data['items'] as &$item) {
78+
foreach ($this->priceAttributeList as $priceAttribute) {
79+
if (isset($item[$priceAttribute]) && $item['type_id'] == Type::TYPE_CODE) {
80+
$item[$priceAttribute] =
81+
$this->directoryCurrency->format(
82+
$item[$priceAttribute],
83+
['display' => Zend_Currency::NO_SYMBOL],
84+
false
85+
);
86+
$item[$priceAttribute] =
87+
$this->getCurrency()->toCurrency(
88+
sprintf("%f", $item[$priceAttribute]),
89+
['symbol' => '%']
90+
);
91+
}
8892
}
8993
}
94+
return $data;
95+
96+
}
9097

91-
return $result;
98+
/**
99+
* @inheritdoc
100+
*/
101+
public function modifyMeta(array $meta): array
102+
{
103+
return $meta;
92104
}
93105

94106
/**

app/code/Magento/Bundle/etc/adminhtml/di.xml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,21 @@
4949
</argument>
5050
</arguments>
5151
</type>
52-
<type name="Magento\Catalog\Ui\DataProvider\Product\Modifier\PriceAttributes">
53-
<plugin name="priceAttributes" type="Magento\Bundle\Ui\DataProvider\Product\Modifier\Plugin\PriceAttributes" sortOrder="60" />
52+
<virtualType name="Magento\Catalog\Ui\DataProvider\Product\Listing\Modifier\Pool">
53+
<arguments>
54+
<argument name="modifiers" xsi:type="array">
55+
<item name="specialPriceAttributes" xsi:type="array">
56+
<item name="class" xsi:type="string">Magento\Bundle\Ui\DataProvider\Product\Modifier\SpecialPriceAttributes</item>
57+
<item name="sortOrder" xsi:type="number">20</item>
58+
</item>
59+
</argument>
60+
</arguments>
61+
</virtualType>
62+
<type name="Magento\Bundle\Ui\DataProvider\Product\Modifier\SpecialPriceAttributes">
63+
<arguments>
64+
<argument name="priceAttributeList" xsi:type="array">
65+
<item name="special_price" xsi:type="string">special_price</item>
66+
</argument>
67+
</arguments>
5468
</type>
5569
</config>

0 commit comments

Comments
 (0)