12
12
use Magento \Framework \Pricing \PriceCurrencyInterface ;
13
13
use Magento \Framework \Pricing \Render \PriceBox ;
14
14
use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
15
+ use Magento \Tax \Model \Calculation as TaxCalculation ;
15
16
16
17
class PriceBoxTags
17
18
{
@@ -35,31 +36,37 @@ class PriceBoxTags
35
36
*/
36
37
private $ scopeResolver ;
37
38
39
+ /**
40
+ * @var TaxCalculation
41
+ */
42
+ private $ taxCalculation ;
43
+
38
44
/**
39
45
* PriceBoxTags constructor.
40
46
* @param PriceCurrencyInterface $priceCurrency
41
47
* @param TimezoneInterface $dateTime
42
48
* @param ScopeResolverInterface $scopeResolver
43
49
* @param Session $customerSession
50
+ * @param TaxCalculation $taxCalculation
44
51
*/
45
52
public function __construct (
46
53
PriceCurrencyInterface $ priceCurrency ,
47
54
TimezoneInterface $ dateTime ,
48
55
ScopeResolverInterface $ scopeResolver ,
49
- Session $ customerSession
56
+ Session $ customerSession ,
57
+ TaxCalculation $ taxCalculation
50
58
) {
51
59
$ this ->dateTime = $ dateTime ;
52
60
$ this ->customerSession = $ customerSession ;
53
61
$ this ->priceCurrency = $ priceCurrency ;
54
62
$ this ->scopeResolver = $ scopeResolver ;
63
+ $ this ->taxCalculation = $ taxCalculation ;
55
64
}
56
65
57
66
/**
58
67
* @param PriceBox $subject
59
68
* @param string $result
60
69
* @return string
61
- *
62
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
63
70
*/
64
71
public function afterGetCacheKey (PriceBox $ subject , $ result )
65
72
{
@@ -71,7 +78,44 @@ public function afterGetCacheKey(PriceBox $subject, $result)
71
78
$ this ->dateTime ->scopeDate ($ this ->scopeResolver ->getScope ()->getId ())->format ('Ymd ' ),
72
79
$ this ->scopeResolver ->getScope ()->getId (),
73
80
$ this ->customerSession ->getCustomerGroupId (),
81
+ $ this ->getTaxRateIds ($ subject ),
74
82
]
75
83
);
76
84
}
85
+
86
+ /**
87
+ * @param PriceBox $subject
88
+ * @return string
89
+ */
90
+ private function getTaxRateIds (PriceBox $ subject )
91
+ {
92
+ $ rateIds = [];
93
+
94
+ $ customerSession = $ this ->customerSession ;
95
+ $ billingAddress = $ customerSession ->getDefaultTaxBillingAddress ();
96
+ $ shippingAddress = $ customerSession ->getDefaultTaxShippingAddress ();
97
+ $ customerTaxClassId = $ customerSession ->getCustomerTaxClassId ();
98
+
99
+ if (!empty ($ billingAddress )) {
100
+ $ billingAddress = new \Magento \Framework \DataObject ($ billingAddress );
101
+ }
102
+ if (!empty ($ shippingAddress )) {
103
+ $ shippingAddress = new \Magento \Framework \DataObject ($ shippingAddress );
104
+ }
105
+
106
+ if (!empty ($ billingAddress ) || !empty ($ shippingAddress )) {
107
+ $ rateRequest = $ this ->taxCalculation ->getRateRequest (
108
+ $ billingAddress ,
109
+ $ shippingAddress ,
110
+ $ customerTaxClassId ,
111
+ $ this ->scopeResolver ->getScope ()->getId (),
112
+ $ this ->customerSession ->getCustomerId ()
113
+ );
114
+
115
+ $ rateRequest ->setProductClassId ($ subject ->getSaleableItem ()->getTaxClassId ());
116
+ $ rateIds = $ this ->taxCalculation ->getResource ()->getRateIds ($ rateRequest );
117
+ }
118
+
119
+ return implode ('_ ' , $ rateIds );
120
+ }
77
121
}
0 commit comments