/** * {@inheritdoc} */ public function visitCart(CartInterface $cart) { $paymentMethod = $cart->getPaymentMethod(); if (null !== $cart->getShippingMethodCost()) { $shippingMethod = $cart->getShippingMethodCost()->getShippingMethod(); $collection = $shippingMethod->getPaymentMethods(); if (null === $paymentMethod || !$collection->contains($paymentMethod)) { $defaultPaymentMethod = $shippingMethod->getPaymentMethods()->first(); $cart->setPaymentMethod($defaultPaymentMethod); } } }