Quote.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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\ResourceModel;
  11. use Magento\Quote\Api\Data\CartInterface as MageQuoteInterface;
  12. /**
  13. * Class Quote
  14. *
  15. * @package Klarna\Kp\Model\ResourceModel
  16. */
  17. class Quote extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  18. {
  19. /**
  20. * Get quote identifier by client_token
  21. *
  22. * @param string $clientToken
  23. * @return int|false
  24. */
  25. public function getIdByClientToken($clientToken)
  26. {
  27. $connection = $this->getConnection();
  28. $select = $connection->select()->from($this->getMainTable(), 'payments_quote_id')
  29. ->where('client_token = :client_token');
  30. $bind = [':client_token' => (string)$clientToken];
  31. return $connection->fetchOne($select, $bind);
  32. }
  33. /**
  34. * Get quote identifier by client_token
  35. *
  36. * @param string $sessionId
  37. * @return int|false
  38. */
  39. public function getIdBySessionId($sessionId)
  40. {
  41. $connection = $this->getConnection();
  42. $select = $connection->select()->from($this->getMainTable(), 'payments_quote_id')
  43. ->where('session_id = :session_id');
  44. $bind = [':session_id' => (string)$sessionId];
  45. return $connection->fetchOne($select, $bind);
  46. }
  47. /**
  48. * Get quote identifier by active Magento quote
  49. *
  50. * @param MageQuoteInterface $mageQuote
  51. * @return int|false
  52. * @throws \Magento\Framework\Exception\NoSuchEntityException
  53. * @throws \Magento\Framework\Exception\LocalizedException
  54. */
  55. public function getActiveByQuote(MageQuoteInterface $mageQuote)
  56. {
  57. $connection = $this->getConnection();
  58. $select = $connection->select()->from($this->getMainTable(), 'payments_quote_id')->where('is_active = 1')
  59. ->where('quote_id = :quote_id');
  60. $bind = [':quote_id' => (string)$mageQuote->getId()];
  61. return $connection->fetchOne($select, $bind);
  62. }
  63. /**
  64. * Constructor
  65. *
  66. * @codeCoverageIgnore
  67. * @codingStandardsIgnoreLine
  68. */
  69. protected function _construct()
  70. {
  71. $this->_init('klarna_payments_quote', 'payments_quote_id');
  72. }
  73. }