Skip to content

Commit

Permalink
Merge pull request #370 from magento-performance/MCP-409
Browse files Browse the repository at this point in the history
MCP-409: Add cart repository to payment information management construct parameters
  • Loading branch information
vzabaznov authored May 13, 2021
2 parents 0c226b0 + 56be08f commit e64cd30
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions app/code/Magento/Checkout/Model/PaymentInformationManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -51,7 +52,7 @@ class PaymentInformationManagement implements \Magento\Checkout\Api\PaymentInfor
private $logger;

/**
* @var \Magento\Quote\Api\CartRepositoryInterface
* @var CartRepositoryInterface
*/
private $cartRepository;

Expand All @@ -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(
Expand All @@ -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;
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}

0 comments on commit e64cd30

Please sign in to comment.