GuestBillingAddressManagement.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Model\GuestCart;
  7. use Magento\Quote\Api\GuestBillingAddressManagementInterface;
  8. use Magento\Quote\Api\BillingAddressManagementInterface;
  9. use Magento\Quote\Model\QuoteIdMask;
  10. use Magento\Quote\Model\QuoteIdMaskFactory;
  11. /**
  12. * Billing address management service for guest carts.
  13. */
  14. class GuestBillingAddressManagement implements GuestBillingAddressManagementInterface
  15. {
  16. /**
  17. * @var QuoteIdMaskFactory
  18. */
  19. private $quoteIdMaskFactory;
  20. /**
  21. * @var BillingAddressManagementInterface
  22. */
  23. private $billingAddressManagement;
  24. /**
  25. * Constructs a quote billing address service object.
  26. *
  27. * @param BillingAddressManagementInterface $billingAddressManagement
  28. * @param QuoteIdMaskFactory $quoteIdMaskFactory
  29. */
  30. public function __construct(
  31. BillingAddressManagementInterface $billingAddressManagement,
  32. QuoteIdMaskFactory $quoteIdMaskFactory
  33. ) {
  34. $this->quoteIdMaskFactory = $quoteIdMaskFactory;
  35. $this->billingAddressManagement = $billingAddressManagement;
  36. }
  37. /**
  38. * {@inheritDoc}
  39. */
  40. public function assign($cartId, \Magento\Quote\Api\Data\AddressInterface $address, $useForShipping = false)
  41. {
  42. /** @var $quoteIdMask QuoteIdMask */
  43. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  44. return $this->billingAddressManagement->assign($quoteIdMask->getQuoteId(), $address, $useForShipping);
  45. }
  46. /**
  47. * {@inheritDoc}
  48. */
  49. public function get($cartId)
  50. {
  51. /** @var $quoteIdMask QuoteIdMask */
  52. $quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
  53. return $this->billingAddressManagement->get($quoteIdMask->getQuoteId());
  54. }
  55. }