diff --git a/src/Compatibility/Storefront/Route/PaymentMethodRoute/Cache/CachedPaymentMethodRoute64.php b/src/Compatibility/Storefront/Route/PaymentMethodRoute/Cache/CachedPaymentMethodRoute64.php index c353bc8f1..d2ee4bbe5 100644 --- a/src/Compatibility/Storefront/Route/PaymentMethodRoute/Cache/CachedPaymentMethodRoute64.php +++ b/src/Compatibility/Storefront/Route/PaymentMethodRoute/Cache/CachedPaymentMethodRoute64.php @@ -8,6 +8,7 @@ use Shopware\Core\Checkout\Cart\Cart; use Shopware\Core\Checkout\Cart\SalesChannel\CartService; use Shopware\Core\Checkout\Payment\Event\PaymentMethodRouteCacheKeyEvent; +use Shopware\Core\System\SalesChannel\SalesChannelContext; use Symfony\Component\EventDispatcher\EventSubscriberInterface; class CachedPaymentMethodRoute64 implements EventSubscriberInterface @@ -66,11 +67,15 @@ public function onGenerateCacheKey(PaymentMethodRouteCacheKeyEvent $event): void $event->getContext()->setRuleIds($originalRuleIds); $parts = $event->getParts(); - - $parts = $this->addVoucherKey($cart, $parts); - $parts = $this->addMollieLimitsKey($parts); - $parts = $this->addSubscriptionKey($cart, $parts); - + $cacheParts = []; + $cacheParts = $this->addVoucherKey($cart, $cacheParts); + $cacheParts = $this->addMollieLimitsKey($cacheParts); + $cacheParts = $this->addSubscriptionKey($cart, $cacheParts); + $cacheParts = $this->addCartAmountKey($cart, $cacheParts); + $cacheParts = $this->addCurrencyCodeKey($event->getContext(), $cacheParts); + $cacheParts = $this->addBillingAddressKey($event->getContext(), $cacheParts); + + $parts[] = md5(implode('-', $cacheParts)); $event->setParts($parts); } @@ -145,4 +150,50 @@ private function isSubscriptionCart(Cart $cart): bool return false; } + + /** + * @param Cart $cart + * @param array $cacheParts + * @return array + */ + private function addCartAmountKey(Cart $cart, array $cacheParts): array + { + $cacheParts[] = $cart->getPrice()->getTotalPrice(); + return $cacheParts; + } + + /** + * @param SalesChannelContext $context + * @param array $cacheParts + * @return array + */ + private function addCurrencyCodeKey(SalesChannelContext $context, array $cacheParts):array + { + $cacheParts[] = $context->getCurrency()->getIsoCode(); + return $cacheParts; + } + + /** + * @param SalesChannelContext $context + * @param array $cacheParts + * @return array + */ + private function addBillingAddressKey(SalesChannelContext $context, array $cacheParts):array + { + $customer = $context->getCustomer(); + + if ($customer === null) { + return $cacheParts; + } + + $billingAddress = $customer->getActiveBillingAddress(); + + if ($billingAddress === null) { + return $cacheParts; + } + + $cacheParts[]=$billingAddress->getId(); + + return $cacheParts; + } } diff --git a/src/Resources/config/services/subscriber.xml b/src/Resources/config/services/subscriber.xml index be985f435..ba25c3490 100644 --- a/src/Resources/config/services/subscriber.xml +++ b/src/Resources/config/services/subscriber.xml @@ -63,5 +63,6 @@ +