Order.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace Dotdigitalgroup\Email\Model\ResourceModel;
  3. use Dotdigitalgroup\Email\Setup\Schema;
  4. class Order extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  5. {
  6. /**
  7. * Initialize resource.
  8. *
  9. * @return null
  10. */
  11. public function _construct()
  12. {
  13. $this->_init(Schema::EMAIL_ORDER_TABLE, 'email_order_id');
  14. }
  15. /**
  16. * Reset the email order for re-import.
  17. *
  18. * @param string|null $from
  19. * @param string|null $to
  20. *
  21. * @return int
  22. *
  23. */
  24. public function resetOrders($from = null, $to = null)
  25. {
  26. $conn = $this->getConnection();
  27. if ($from && $to) {
  28. $where = [
  29. 'created_at >= ?' => $from . ' 00:00:00',
  30. 'created_at <= ?' => $to . ' 23:59:59',
  31. 'email_imported is ?' => new \Zend_Db_Expr('not null')
  32. ];
  33. } else {
  34. $where = $conn->quoteInto(
  35. 'email_imported is ?',
  36. new \Zend_Db_Expr('not null')
  37. );
  38. }
  39. $num = $conn->update(
  40. $this->getTable(Schema::EMAIL_ORDER_TABLE),
  41. [
  42. 'email_imported' => new \Zend_Db_Expr('null'),
  43. 'modified' => new \Zend_Db_Expr('null'),
  44. ],
  45. $where
  46. );
  47. return $num;
  48. }
  49. /**
  50. * Mark the connector orders to be imported.
  51. *
  52. * @param array $ids
  53. *
  54. * @return null
  55. */
  56. public function setImported($ids)
  57. {
  58. if (empty($ids)) {
  59. return;
  60. }
  61. $connection = $this->getConnection();
  62. $tableName = $this->getTable(Schema::EMAIL_ORDER_TABLE);
  63. $connection->update(
  64. $tableName,
  65. [
  66. 'modified' => new \Zend_Db_Expr('null'),
  67. 'email_imported' => '1',
  68. 'updated_at' => gmdate('Y-m-d H:i:s')
  69. ],
  70. ["order_id IN (?)" => $ids]
  71. );
  72. }
  73. }