|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Richdynamix\PersonalisedProducts\Model\ResourceModel; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* Class Export |
|
7
|
|
|
* |
|
8
|
|
|
* @category Richdynamix |
|
9
|
|
|
* @package PersonalisedProducts |
|
10
|
|
|
* @author Steven Richardson ([email protected]) @mage_gizmo |
|
11
|
|
|
*/ |
|
12
|
|
|
class Export extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* @var \Magento\Framework\Stdlib\DateTime\DateTime |
|
16
|
|
|
*/ |
|
17
|
|
|
private $_date; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Export constructor. |
|
21
|
|
|
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context |
|
22
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date |
|
23
|
|
|
* @param null $resourcePrefix |
|
24
|
|
|
*/ |
|
25
|
|
|
public function __construct( |
|
26
|
|
|
\Magento\Framework\Model\ResourceModel\Db\Context $context, |
|
27
|
|
|
\Magento\Framework\Stdlib\DateTime\DateTime $date, |
|
28
|
|
|
$resourcePrefix = null |
|
29
|
|
|
) { |
|
30
|
|
|
parent::__construct($context, $resourcePrefix); |
|
31
|
|
|
$this->_date = $date; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Export constructor |
|
36
|
|
|
*/ |
|
37
|
|
|
protected function _construct() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->_init('rp_export_products', 'increment_id'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Before saving the object, add the created or updated times |
|
44
|
|
|
* |
|
45
|
|
|
* @param \Magento\Framework\Model\AbstractModel $object |
|
46
|
|
|
* @return $this |
|
47
|
|
|
*/ |
|
48
|
|
|
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) |
|
49
|
|
|
{ |
|
50
|
|
|
|
|
51
|
|
|
if ($object->isObjectNew() && !$object->hasCreationTime()) { |
|
52
|
|
|
$object->setCreationTime($this->_date->gmtDate()); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
$object->setUpdateTime($this->_date->gmtDate()); |
|
56
|
|
|
|
|
57
|
|
|
return parent::_beforeSave($object); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Default select items not yet exported |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $field |
|
64
|
|
|
* @param mixed $value |
|
65
|
|
|
* @param \Magento\Framework\Model\AbstractModel $object |
|
66
|
|
|
* @return \Magento\Framework\DB\Select |
|
67
|
|
|
*/ |
|
68
|
|
|
protected function _getLoadSelect($field, $value, $object) |
|
69
|
|
|
{ |
|
70
|
|
|
$select = parent::_getLoadSelect($field, $value, $object); |
|
71
|
|
|
|
|
72
|
|
|
$select->where( |
|
73
|
|
|
'is_exported = ?', |
|
74
|
|
|
0 |
|
75
|
|
|
)->limit( |
|
76
|
|
|
1 |
|
77
|
|
|
); |
|
78
|
|
|
|
|
79
|
|
|
return $select; |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
|