QuoteAdapter.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Gateway\Data\Quote;
  7. use Magento\Framework\Exception\LocalizedException;
  8. use Magento\Payment\Gateway\Data\OrderAdapterInterface;
  9. use Magento\Quote\Api\Data\CartInterface;
  10. use Magento\Payment\Gateway\Data\AddressAdapterInterface;
  11. /**
  12. * Class QuoteAdapter
  13. */
  14. class QuoteAdapter implements OrderAdapterInterface
  15. {
  16. /**
  17. * @var CartInterface
  18. */
  19. private $quote;
  20. /**
  21. * @var AddressAdapter
  22. */
  23. private $addressAdapterFactory;
  24. /**
  25. * @param CartInterface $quote
  26. * @param AddressAdapterFactory $addressAdapterFactory
  27. */
  28. public function __construct(
  29. CartInterface $quote,
  30. AddressAdapterFactory $addressAdapterFactory
  31. ) {
  32. $this->quote = $quote;
  33. $this->addressAdapterFactory = $addressAdapterFactory;
  34. }
  35. /**
  36. * Returns currency code
  37. *
  38. * @return string
  39. */
  40. public function getCurrencyCode()
  41. {
  42. return $this->quote->getCurrency()->getBaseCurrencyCode();
  43. }
  44. /**
  45. * Returns order increment id
  46. *
  47. * @return string
  48. */
  49. public function getOrderIncrementId()
  50. {
  51. return $this->quote->getReservedOrderId();
  52. }
  53. /**
  54. * Returns customer ID
  55. *
  56. * @return int|null
  57. */
  58. public function getCustomerId()
  59. {
  60. return $this->quote->getCustomer()->getId();
  61. }
  62. /**
  63. * Returns billing address
  64. *
  65. * @return AddressAdapterInterface|null
  66. */
  67. public function getBillingAddress()
  68. {
  69. if ($this->quote->getBillingAddress()) {
  70. return $this->addressAdapterFactory->create(
  71. ['address' => $this->quote->getBillingAddress()]
  72. );
  73. }
  74. return null;
  75. }
  76. /**
  77. * Returns shipping address
  78. *
  79. * @return AddressAdapterInterface|null
  80. */
  81. public function getShippingAddress()
  82. {
  83. if ($this->quote->getShippingAddress()) {
  84. return $this->addressAdapterFactory->create(
  85. ['address' => $this->quote->getShippingAddress()]
  86. );
  87. }
  88. return null;
  89. }
  90. /**
  91. * Returns order store id
  92. *
  93. * @return int
  94. */
  95. public function getStoreId()
  96. {
  97. return $this->quote->getStoreId();
  98. }
  99. /**
  100. * Returns order id
  101. *
  102. * @return int
  103. */
  104. public function getId()
  105. {
  106. return $this->quote->getId();
  107. }
  108. /**
  109. * Returns order grand total amount
  110. *
  111. * @return null
  112. */
  113. public function getGrandTotalAmount()
  114. {
  115. return null;
  116. }
  117. /**
  118. * Returns list of line items in the cart
  119. *
  120. * @return \Magento\Quote\Api\Data\CartItemInterface[]|null
  121. */
  122. public function getItems()
  123. {
  124. return $this->quote->getItems();
  125. }
  126. /**
  127. * Gets the remote IP address for the order.
  128. *
  129. * @return string|null Remote IP address.
  130. */
  131. public function getRemoteIp()
  132. {
  133. return null;
  134. }
  135. }