Quote.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Payment\Model\Cart\SalesModel;
  7. /**
  8. * Wrapper for \Magento\Quote\Model\Quote sales model
  9. */
  10. class Quote implements \Magento\Payment\Model\Cart\SalesModel\SalesModelInterface
  11. {
  12. /**
  13. * Sales quote model instance
  14. *
  15. * @var \Magento\Quote\Model\Quote
  16. */
  17. protected $_salesModel;
  18. /**
  19. * @var \Magento\Quote\Model\Quote\Address
  20. */
  21. protected $_address;
  22. /**
  23. * @param \Magento\Quote\Model\Quote $salesModel
  24. */
  25. public function __construct(\Magento\Quote\Model\Quote $salesModel)
  26. {
  27. $this->_salesModel = $salesModel;
  28. $this->_address = $this
  29. ->_salesModel
  30. ->getIsVirtual() ? $this
  31. ->_salesModel
  32. ->getBillingAddress() : $this
  33. ->_salesModel
  34. ->getShippingAddress();
  35. }
  36. /**
  37. * {@inheritdoc}
  38. */
  39. public function getAllItems()
  40. {
  41. $resultItems = [];
  42. foreach ($this->_salesModel->getAllItems() as $item) {
  43. $resultItems[] = new \Magento\Framework\DataObject(
  44. [
  45. 'parent_item' => $item->getParentItem(),
  46. 'name' => $item->getName(),
  47. 'qty' => (int)$item->getTotalQty(),
  48. 'price' => (double)$item->getBaseCalculationPrice(),
  49. 'original_item' => $item,
  50. ]
  51. );
  52. }
  53. return $resultItems;
  54. }
  55. /**
  56. * {@inheritdoc}
  57. */
  58. public function getBaseSubtotal()
  59. {
  60. return $this->_salesModel->getBaseSubtotal();
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function getBaseTaxAmount()
  66. {
  67. return $this->_address->getBaseTaxAmount();
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function getBaseShippingAmount()
  73. {
  74. return $this->_address->getBaseShippingAmount();
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function getBaseDiscountAmount()
  80. {
  81. return $this->_address->getBaseDiscountAmount();
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function getDataUsingMethod($key, $args = null)
  87. {
  88. return $this->_salesModel->getDataUsingMethod($key, $args);
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function getTaxContainer()
  94. {
  95. return $this->_salesModel
  96. ->getIsVirtual() ? $this
  97. ->_salesModel
  98. ->getBillingAddress() : $this
  99. ->_salesModel
  100. ->getShippingAddress();
  101. }
  102. }