Order.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * This file is part of the Klarna Core 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\Core\Model\ResourceModel;
  11. use Magento\Framework\Model\ResourceModel\Db\AbstractDb;
  12. use Magento\Sales\Api\Data\OrderInterface as MageOrder;
  13. /**
  14. * Class Order
  15. *
  16. * @package Klarna\Core\Model\ResourceModel
  17. */
  18. class Order extends AbstractDb
  19. {
  20. /**
  21. * Get order identifier by Reservation
  22. *
  23. * @param string $reservationId
  24. * @return false|int
  25. */
  26. public function getIdByReservationId($reservationId)
  27. {
  28. $connection = $this->getConnection();
  29. $select = $connection->select()->from($this->getMainTable(), 'id')
  30. ->where('reservation_id = :reservation_id');
  31. $bind = [':reservation_id' => (string)$reservationId];
  32. return $connection->fetchOne($select, $bind);
  33. }
  34. /**
  35. * Get order identifier by Klarna Order ID
  36. *
  37. * @param string $klarnaOrderId
  38. * @return int|false
  39. */
  40. public function getIdByKlarnaOrderId($klarnaOrderId)
  41. {
  42. $connection = $this->getConnection();
  43. $select = $connection->select()->from($this->getMainTable(), 'id')
  44. ->where('klarna_order_id = :klarna_order_id');
  45. $bind = [':klarna_order_id' => (string)$klarnaOrderId];
  46. return $connection->fetchOne($select, $bind);
  47. }
  48. /**
  49. * Get order identifier by order
  50. *
  51. * @param MageOrder $mageOrder
  52. * @return false|int
  53. */
  54. public function getIdByOrder(MageOrder $mageOrder)
  55. {
  56. $connection = $this->getConnection();
  57. $select = $connection->select()->from($this->getMainTable(), 'id')
  58. ->where('order_id = :order_id');
  59. $bind = [':order_id' => (string)$mageOrder->getId()];
  60. return $connection->fetchOne($select, $bind);
  61. }
  62. /**
  63. * Get order ID by Session ID
  64. *
  65. * @param string $sessionId
  66. * @return string
  67. */
  68. public function getIdBySessionId($sessionId)
  69. {
  70. $connection = $this->getConnection();
  71. $select = $connection->select()->from($this->getMainTable(), 'id')
  72. ->where('session_id = :session_id');
  73. $bind = [':session_id' => (string)$sessionId];
  74. return $connection->fetchOne($select, $bind);
  75. }
  76. /**
  77. * Constructor
  78. *
  79. * @codeCoverageIgnore
  80. * @codingStandardsIgnoreLine
  81. */
  82. protected function _construct()
  83. {
  84. $this->_init('klarna_core_order', 'id');
  85. }
  86. }