5
5
*/
6
6
namespace Magento \Bundle \Helper \Catalog \Product ;
7
7
8
+ use Magento \Bundle \Model \Product \Price ;
9
+ use Magento \Bundle \Model \Product \Type ;
8
10
use Magento \Catalog \Api \Data \ProductInterface ;
9
11
use Magento \Catalog \Helper \Product \Configuration \ConfigurationInterface ;
12
+ use Magento \Catalog \Helper \Product \Configuration as ProductConfiguration ;
13
+ use Magento \Catalog \Model \Product ;
10
14
use Magento \Catalog \Model \Product \Configuration \Item \ItemInterface ;
11
15
use Magento \Framework \App \Helper \AbstractHelper ;
16
+ use Magento \Framework \App \Helper \Context ;
12
17
use Magento \Framework \App \ObjectManager ;
18
+ use Magento \Framework \Escaper ;
19
+ use Magento \Framework \Exception \LocalizedException ;
20
+ use Magento \Framework \Pricing \Helper \Data ;
21
+ use Magento \Framework \Serialize \Serializer \Json ;
13
22
14
23
/**
15
24
* Helper for fetching properties by product configuration item
@@ -21,75 +30,67 @@ class Configuration extends AbstractHelper implements ConfigurationInterface
21
30
/**
22
31
* Core data
23
32
*
24
- * @var \Magento\Framework\Pricing\Helper\ Data
33
+ * @var Data
25
34
*/
26
35
protected $ pricingHelper ;
27
36
28
37
/**
29
38
* Catalog product configuration
30
39
*
31
- * @var \Magento\Catalog\Helper\Product\Configuration
40
+ * @var ProductConfiguration
32
41
*/
33
42
protected $ productConfiguration ;
34
43
35
44
/**
36
- * @var \Magento\Framework\ Escaper
45
+ * @var Escaper
37
46
*/
38
47
protected $ escaper ;
39
48
40
49
/**
41
50
* Serializer interface instance.
42
51
*
43
- * @var \Magento\Framework\Serialize\Serializer\ Json
52
+ * @var Json
44
53
*/
45
54
private $ serializer ;
46
55
47
56
/**
48
- * @var \Magento\Catalog\Helper\Data
49
- */
50
- private $ catalogHelper ;
51
-
52
- /**
53
- * @var \Magento\Tax\Helper\Data|mixed
57
+ * @var Tax
54
58
*/
55
59
private $ taxHelper ;
56
60
57
61
/**
58
- * @param \Magento\Framework\App\Helper\Context $context
59
- * @param \Magento\Catalog\Helper\Product\Configuration $productConfiguration
60
- * @param \Magento\Framework\Pricing\Helper\Data $pricingHelper
61
- * @param \Magento\Framework\Escaper $escaper
62
- * @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
63
- * @param \Magento\Catalog\Helper\Data|null $catalogHelper
64
- * @param \Magento\Tax\Helper\Data|null $taxHelper
62
+ * @param Context $context
63
+ * @param ProductConfiguration $productConfiguration
64
+ * @param Data $pricingHelper
65
+ * @param Escaper $escaper
66
+ * @param Json|null $serializer
67
+ * @param Tax|null $taxHelper
65
68
*/
66
69
public function __construct (
67
- \Magento \Framework \App \Helper \Context $ context ,
68
- \Magento \Catalog \Helper \Product \Configuration $ productConfiguration ,
69
- \Magento \Framework \Pricing \Helper \Data $ pricingHelper ,
70
- \Magento \Framework \Escaper $ escaper ,
71
- \Magento \Framework \Serialize \Serializer \Json $ serializer = null ,
72
- \Magento \Catalog \Helper \Data $ catalogHelper = null ,
73
- \Magento \Tax \Helper \Data $ taxHelper = null
70
+ Context $ context ,
71
+ ProductConfiguration $ productConfiguration ,
72
+ Data $ pricingHelper ,
73
+ Escaper $ escaper ,
74
+ Json $ serializer = null ,
75
+ Tax $ taxHelper = null
74
76
) {
75
77
$ this ->productConfiguration = $ productConfiguration ;
76
78
$ this ->pricingHelper = $ pricingHelper ;
77
79
$ this ->escaper = $ escaper ;
78
- $ this ->serializer = $ serializer ?: \Magento \Framework \App \ObjectManager::getInstance ()
79
- ->get (\Magento \Framework \Serialize \Serializer \Json::class);
80
- $ this ->catalogHelper = $ catalogHelper ?? ObjectManager::getInstance ()->get (\Magento \Catalog \Helper \Data::class);
81
- $ this ->taxHelper = $ taxHelper ?? ObjectManager::getInstance ()->get (\Magento \Tax \Helper \Data::class);
80
+ $ this ->serializer = $ serializer ?: ObjectManager::getInstance ()
81
+ ->get (Json::class);
82
+ $ this ->taxHelper = $ taxHelper ?? ObjectManager::getInstance ()->get (Tax::class);
82
83
parent ::__construct ($ context );
83
84
}
84
85
85
86
/**
86
87
* Get selection quantity
87
88
*
88
- * @param \Magento\Catalog\Model\ Product $product
89
+ * @param Product $product
89
90
* @param int $selectionId
90
91
* @return float
91
92
*/
92
- public function getSelectionQty (\ Magento \ Catalog \ Model \ Product $ product , $ selectionId )
93
+ public function getSelectionQty (Product $ product , $ selectionId )
93
94
{
94
95
$ selectionQty = $ product ->getCustomOption ('selection_qty_ ' . $ selectionId );
95
96
if ($ selectionQty ) {
@@ -102,15 +103,15 @@ public function getSelectionQty(\Magento\Catalog\Model\Product $product, $select
102
103
* Obtain final price of selection in a bundle product
103
104
*
104
105
* @param ItemInterface $item
105
- * @param \Magento\Catalog\Model\ Product $selectionProduct
106
+ * @param Product $selectionProduct
106
107
* @return float
107
108
*/
108
- public function getSelectionFinalPrice (ItemInterface $ item , \ Magento \ Catalog \ Model \ Product $ selectionProduct )
109
+ public function getSelectionFinalPrice (ItemInterface $ item , Product $ selectionProduct )
109
110
{
110
111
$ selectionProduct ->unsetData ('final_price ' );
111
112
112
113
$ product = $ item ->getProduct ();
113
- /** @var \Magento\Bundle\Model\Product\ Price $price */
114
+ /** @var Price $price */
114
115
$ price = $ product ->getPriceModel ();
115
116
116
117
return $ price ->getSelectionFinalTotalPrice (
@@ -137,7 +138,7 @@ public function getBundleOptions(ItemInterface $item)
137
138
$ options = [];
138
139
$ product = $ item ->getProduct ();
139
140
140
- /** @var \Magento\Bundle\Model\Product\ Type $typeInstance */
141
+ /** @var Type $typeInstance */
141
142
$ typeInstance = $ product ->getTypeInstance ();
142
143
143
144
// get bundle options
@@ -187,22 +188,23 @@ public function getBundleOptions(ItemInterface $item)
187
188
* @param ProductInterface $bundleSelection
188
189
* @param array $option
189
190
* @return array
191
+ * @throws LocalizedException
190
192
*/
191
193
private function getOptionPriceHtml (ItemInterface $ item , ProductInterface $ bundleSelection , array $ option ): array
192
194
{
193
195
$ product = $ item ->getProduct ();
194
196
$ qty = $ this ->getSelectionQty ($ item ->getProduct (), $ bundleSelection ->getSelectionId ()) * 1 ;
195
197
if ($ qty ) {
196
198
$ selectionPrice = $ this ->getSelectionFinalPrice ($ item , $ bundleSelection );
197
- $ selectionFinalPrice = $ this ->catalogHelper ->getTaxPrice ($ item ->getProduct (), $ selectionPrice );
199
+ $ selectionFinalPrice = $ this ->taxHelper ->getTaxPrice ($ item ->getProduct (), $ selectionPrice );
198
200
199
- $ displayBothPrices = $ this ->taxHelper ->displayBothPrices ();
200
- if ($ displayBothPrices ) {
201
+ $ displayCartPricesBoth = $ this ->taxHelper ->displayCartPricesBoth ();
202
+ if ($ displayCartPricesBoth ) {
201
203
$ selectionFinalPrice =
202
- $ this ->catalogHelper
204
+ $ this ->taxHelper
203
205
->getTaxPrice ($ product , $ selectionPrice , true );
204
206
$ selectionFinalPriceExclTax =
205
- $ this ->catalogHelper
207
+ $ this ->taxHelper
206
208
->getTaxPrice ($ product , $ selectionPrice , false );
207
209
}
208
210
$ option ['value ' ][] = $ qty . ' x '
@@ -212,7 +214,7 @@ private function getOptionPriceHtml(ItemInterface $item, ProductInterface $bundl
212
214
$ selectionFinalPrice
213
215
)
214
216
. ' '
215
- . ($ displayBothPrices ? __ ('Excl. tax: ' ) . ' '
217
+ . ($ displayCartPricesBoth ? __ ('Excl. tax: ' ) . ' '
216
218
. $ this ->pricingHelper ->currency (
217
219
$ selectionFinalPriceExclTax
218
220
) : '' );
0 commit comments