CartTotalManagement.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\Cart;
  7. use Magento\Quote\Api\CartTotalManagementInterface;
  8. /**
  9. * @inheritDoc
  10. */
  11. class CartTotalManagement implements CartTotalManagementInterface
  12. {
  13. /**
  14. * @var \Magento\Quote\Api\ShippingMethodManagementInterface
  15. */
  16. protected $shippingMethodManagement;
  17. /**
  18. * @var \Magento\Quote\Api\PaymentMethodManagementInterface
  19. */
  20. protected $paymentMethodManagement;
  21. /**
  22. * @var \Magento\Quote\Api\CartTotalRepositoryInterface
  23. */
  24. protected $cartTotalsRepository;
  25. /**
  26. * @var \Magento\Quote\Model\Cart\TotalsAdditionalDataProcessor
  27. */
  28. protected $dataProcessor;
  29. /**
  30. * @param \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagement
  31. * @param \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
  32. * @param \Magento\Quote\Api\CartTotalRepositoryInterface $cartTotalsRepository
  33. * @param \Magento\Quote\Model\Cart\TotalsAdditionalDataProcessor $dataProcessor
  34. */
  35. public function __construct(
  36. \Magento\Quote\Api\ShippingMethodManagementInterface $shippingMethodManagement,
  37. \Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement,
  38. \Magento\Quote\Api\CartTotalRepositoryInterface $cartTotalsRepository,
  39. \Magento\Quote\Model\Cart\TotalsAdditionalDataProcessor $dataProcessor
  40. ) {
  41. $this->shippingMethodManagement = $shippingMethodManagement;
  42. $this->paymentMethodManagement = $paymentMethodManagement;
  43. $this->cartTotalsRepository = $cartTotalsRepository;
  44. $this->dataProcessor = $dataProcessor;
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function collectTotals(
  50. $cartId,
  51. \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
  52. $shippingCarrierCode = null,
  53. $shippingMethodCode = null,
  54. \Magento\Quote\Api\Data\TotalsAdditionalDataInterface $additionalData = null
  55. ) {
  56. if ($shippingCarrierCode && $shippingMethodCode) {
  57. $this->shippingMethodManagement->set($cartId, $shippingCarrierCode, $shippingMethodCode);
  58. }
  59. $this->paymentMethodManagement->set($cartId, $paymentMethod);
  60. if ($additionalData !== null) {
  61. $this->dataProcessor->process($additionalData, $cartId);
  62. }
  63. return $this->cartTotalsRepository->get($cartId);
  64. }
  65. }