5
5
*/
6
6
declare (strict_types=1 );
7
7
8
- namespace Magento \Bundle \Ui \DataProvider \Product \Modifier \ Plugin ;
8
+ namespace Magento \Bundle \Ui \DataProvider \Product \Modifier ;
9
9
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 ;
13
10
use Magento \Directory \Model \Currency as DirectoryCurrency ;
14
11
use Magento \Framework \Currency ;
15
12
use Magento \Framework \Exception \NoSuchEntityException ;
16
13
use Magento \Framework \Locale \CurrencyInterface ;
17
14
use Magento \Store \Api \Data \StoreInterface ;
18
15
use Magento \Store \Model \StoreManagerInterface ;
16
+ use Magento \Ui \DataProvider \Modifier \ModifierInterface ;
17
+ use Magento \Bundle \Model \Product \Type ;
19
18
use Zend_Currency ;
20
19
use Zend_Currency_Exception ;
21
20
22
21
/**
23
22
* Modify product listing price attributes
24
23
*/
25
- class PriceAttributes
24
+ class SpecialPriceAttributes implements ModifierInterface
26
25
{
26
+ /**
27
+ * @var array
28
+ */
29
+ private $ priceAttributeList ;
30
+
27
31
/**
28
32
* @var StoreManagerInterface
29
33
*/
@@ -45,50 +49,58 @@ class PriceAttributes
45
49
* @param StoreManagerInterface $storeManager
46
50
* @param CurrencyInterface $localeCurrency
47
51
* @param DirectoryCurrency $directoryCurrency
52
+ * @param array $priceAttributeList
48
53
*/
49
54
public function __construct (
50
55
StoreManagerInterface $ storeManager ,
51
56
CurrencyInterface $ localeCurrency ,
52
- DirectoryCurrency $ directoryCurrency
57
+ DirectoryCurrency $ directoryCurrency ,
58
+ array $ priceAttributeList = []
53
59
) {
54
60
$ this ->storeManager = $ storeManager ;
55
61
$ this ->localeCurrency = $ localeCurrency ;
62
+ $ this ->priceAttributeList = $ priceAttributeList ;
56
63
$ this ->directoryCurrency = $ directoryCurrency ;
57
64
}
58
65
59
66
/**
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
66
68
* @throws NoSuchEntityException
67
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
69
+ * @throws Zend_Currency_Exception
68
70
*/
69
- public function afterModifyData ( Subject $ subject , array $ result ): array
71
+ public function modifyData ( array $ data ): array
70
72
{
71
- if (empty ($ result )) {
72
- return $ result ;
73
+ if (empty ($ data ) || empty ( $ this -> priceAttributeList )) {
74
+ return $ data ;
73
75
}
74
76
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
+ }
88
92
}
89
93
}
94
+ return $ data ;
95
+
96
+ }
90
97
91
- return $ result ;
98
+ /**
99
+ * @inheritdoc
100
+ */
101
+ public function modifyMeta (array $ meta ): array
102
+ {
103
+ return $ meta ;
92
104
}
93
105
94
106
/**
0 commit comments