Skip to content

Commit de8421d

Browse files
committed
MAGETWO-51586: Category page cached for different users from one web client
1 parent 45ce6e5 commit de8421d

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

app/code/Magento/Catalog/Block/Category/Plugin/PriceBoxTags.php

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Pricing\PriceCurrencyInterface;
1313
use Magento\Framework\Pricing\Render\PriceBox;
1414
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
15+
use Magento\Tax\Model\Calculation as TaxCalculation;
1516

1617
class PriceBoxTags
1718
{
@@ -35,31 +36,37 @@ class PriceBoxTags
3536
*/
3637
private $scopeResolver;
3738

39+
/**
40+
* @var TaxCalculation
41+
*/
42+
private $taxCalculation;
43+
3844
/**
3945
* PriceBoxTags constructor.
4046
* @param PriceCurrencyInterface $priceCurrency
4147
* @param TimezoneInterface $dateTime
4248
* @param ScopeResolverInterface $scopeResolver
4349
* @param Session $customerSession
50+
* @param TaxCalculation $taxCalculation
4451
*/
4552
public function __construct(
4653
PriceCurrencyInterface $priceCurrency,
4754
TimezoneInterface $dateTime,
4855
ScopeResolverInterface $scopeResolver,
49-
Session $customerSession
56+
Session $customerSession,
57+
TaxCalculation $taxCalculation
5058
) {
5159
$this->dateTime = $dateTime;
5260
$this->customerSession = $customerSession;
5361
$this->priceCurrency = $priceCurrency;
5462
$this->scopeResolver = $scopeResolver;
63+
$this->taxCalculation = $taxCalculation;
5564
}
5665

5766
/**
5867
* @param PriceBox $subject
5968
* @param string $result
6069
* @return string
61-
*
62-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
6370
*/
6471
public function afterGetCacheKey(PriceBox $subject, $result)
6572
{
@@ -71,7 +78,44 @@ public function afterGetCacheKey(PriceBox $subject, $result)
7178
$this->dateTime->scopeDate($this->scopeResolver->getScope()->getId())->format('Ymd'),
7279
$this->scopeResolver->getScope()->getId(),
7380
$this->customerSession->getCustomerGroupId(),
81+
$this->getTaxRateIds($subject),
7482
]
7583
);
7684
}
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+
}
77121
}

0 commit comments

Comments
 (0)