From 262f1df96bfbcdf5af0170ff332ef2441e5e827d Mon Sep 17 00:00:00 2001 From: Dmytro Poperechnyy Date: Wed, 12 May 2021 20:48:32 -0500 Subject: [PATCH] MCP-409: Overload cart repository getActive method --- .../Model/PaymentInformationManagement.php | 28 ++++++------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Checkout/Model/PaymentInformationManagement.php b/app/code/Magento/Checkout/Model/PaymentInformationManagement.php index 3b36391530c8f..1aad8a78bda55 100644 --- a/app/code/Magento/Checkout/Model/PaymentInformationManagement.php +++ b/app/code/Magento/Checkout/Model/PaymentInformationManagement.php @@ -11,6 +11,7 @@ use Magento\Checkout\Api\PaymentSavingRateLimiterInterface; use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\CouldNotSaveException; +use Magento\Quote\Api\CartRepositoryInterface; /** * Payment information management service. @@ -51,7 +52,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor private $logger; /** - * @var \Magento\Quote\Api\CartRepositoryInterface + * @var CartRepositoryInterface */ private $cartRepository; @@ -78,6 +79,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor * @param \Magento\Quote\Api\CartTotalRepositoryInterface $cartTotalsRepository * @param PaymentProcessingRateLimiterInterface|null $paymentRateLimiter * @param PaymentSavingRateLimiterInterface|null $saveRateLimiter + * @param CartRepositoryInterface|null $cartRepository * @codeCoverageIgnore */ public function __construct( @@ -87,7 +89,8 @@ public function __construct( \Magento\Checkout\Model\PaymentDetailsFactory $paymentDetailsFactory, \Magento\Quote\Api\CartTotalRepositoryInterface $cartTotalsRepository, ?PaymentProcessingRateLimiterInterface $paymentRateLimiter = null, - ?PaymentSavingRateLimiterInterface $saveRateLimiter = null + ?PaymentSavingRateLimiterInterface $saveRateLimiter = null, + ?CartRepositoryInterface $cartRepository = null ) { $this->billingAddressManagement = $billingAddressManagement; $this->paymentMethodManagement = $paymentMethodManagement; @@ -98,6 +101,8 @@ public function __construct( ?? ObjectManager::getInstance()->get(PaymentProcessingRateLimiterInterface::class); $this->saveRateLimiter = $saveRateLimiter ?? ObjectManager::getInstance()->get(PaymentSavingRateLimiterInterface::class); + $this->cartRepository = $cartRepository + ?? ObjectManager::getInstance()->get(CartRepositoryInterface::class); } /** @@ -154,10 +159,8 @@ public function savePaymentInformation( } if ($billingAddress) { - /** @var \Magento\Quote\Api\CartRepositoryInterface $quoteRepository */ - $quoteRepository = $this->getCartRepository(); /** @var \Magento\Quote\Model\Quote $quote */ - $quote = $quoteRepository->getActive($cartId); + $quote = $this->cartRepository->getActive($cartId); $customerId = $quote->getBillingAddress() ->getCustomerId(); if (!$billingAddress->getCustomerId() && $customerId) { @@ -204,19 +207,4 @@ private function getLogger() } return $this->logger; } - - /** - * Get Cart repository - * - * @return \Magento\Quote\Api\CartRepositoryInterface - * @deprecated 100.2.0 - */ - private function getCartRepository() - { - if (!$this->cartRepository) { - $this->cartRepository = ObjectManager::getInstance() - ->get(\Magento\Quote\Api\CartRepositoryInterface::class); - } - return $this->cartRepository; - } }