Quote.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /**
  3. * This file is part of the Klarna KP module
  4. *
  5. * (c) Klarna Bank AB (publ)
  6. *
  7. * For the full copyright and license information, please view the NOTICE
  8. * and LICENSE files that were distributed with this source code.
  9. */
  10. namespace Klarna\Kp\Model;
  11. use Klarna\Kp\Api\QuoteInterface;
  12. use Magento\Framework\DataObject\IdentityInterface;
  13. use Magento\Framework\Model\AbstractModel;
  14. /**
  15. * Class Quote
  16. *
  17. * @package Klarna\Core\Model
  18. * @method getId():int
  19. * @method getKlarnaCheckoutId():int
  20. */
  21. class Quote extends AbstractModel implements QuoteInterface, IdentityInterface
  22. {
  23. const CACHE_TAG = 'klarna_payments_quote';
  24. /**
  25. * @return array
  26. */
  27. public function getIdentities()
  28. {
  29. return [self::CACHE_TAG . '_' . $this->getId()];
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getSessionId()
  35. {
  36. return $this->_getData('session_id');
  37. }
  38. /**
  39. * {@inheritdoc}
  40. */
  41. public function setIsActive($active)
  42. {
  43. $this->setData('is_active', $active);
  44. return $this;
  45. }
  46. /**
  47. * {@inheritdoc}
  48. */
  49. public function setClientToken($token)
  50. {
  51. $this->setData('client_token', $token);
  52. return $this;
  53. }
  54. /**
  55. * {@inheritdoc}
  56. */
  57. public function getClientToken()
  58. {
  59. return $this->_getData('client_token');
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function setSessionId($sessionId)
  65. {
  66. $this->setData('session_id', $sessionId);
  67. return $this;
  68. }
  69. /**
  70. * {@inheritdoc}
  71. */
  72. public function getIsActive()
  73. {
  74. return $this->_getData('is_active');
  75. }
  76. /**
  77. * {@inheritdoc}
  78. */
  79. public function isActive()
  80. {
  81. return (bool)$this->_getData('is_active');
  82. }
  83. /**
  84. * {@inheritdoc}
  85. */
  86. public function getAuthorizationToken()
  87. {
  88. return $this->_getData('authorization_token');
  89. }
  90. /**
  91. * {@inheritdoc}
  92. */
  93. public function setAuthorizationToken($token)
  94. {
  95. $this->setData('authorization_token', $token);
  96. return $this;
  97. }
  98. /**
  99. * {@inheritdoc}
  100. */
  101. public function setQuoteId($quoteId)
  102. {
  103. $this->setData('quote_id', $quoteId);
  104. return $this;
  105. }
  106. /**
  107. * {@inheritdoc}
  108. */
  109. public function getQuoteId()
  110. {
  111. return $this->_getData('quote_id');
  112. }
  113. /**
  114. * {@inheritdoc}
  115. */
  116. public function getPaymentMethods()
  117. {
  118. $methods = $this->_getData('payment_methods');
  119. if (empty($methods)) {
  120. return [];
  121. }
  122. return explode(',', $methods);
  123. }
  124. /**
  125. * {@inheritdoc}
  126. */
  127. public function setPaymentMethods($methods)
  128. {
  129. if (!is_array($methods)) {
  130. $methods = [$methods];
  131. }
  132. $this->setData('payment_methods', implode(',', $methods));
  133. return $this;
  134. }
  135. /**
  136. * {@inheritdoc}
  137. */
  138. public function setPaymentMethodInfo($methodinfo)
  139. {
  140. if (!is_array($methodinfo)) {
  141. $methodinfo = [$methodinfo];
  142. }
  143. $this->setData('payment_method_info', json_encode($methodinfo));
  144. return $this;
  145. }
  146. /**
  147. * {@inheritdoc}
  148. */
  149. public function getPaymentMethodInfo()
  150. {
  151. $methods = $this->_getData('payment_method_info');
  152. if (empty($methods)) {
  153. return [];
  154. }
  155. return json_decode($methods);
  156. }
  157. /**
  158. * Constructor
  159. *
  160. * @codeCoverageIgnore
  161. * @codingStandardsIgnoreLine
  162. */
  163. protected function _construct()
  164. {
  165. $this->_init(\Klarna\Kp\Model\ResourceModel\Quote::class);
  166. }
  167. }