|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Richdynamix\PersonalisedProducts\Model; |
|
4
|
|
|
|
|
5
|
|
|
use \Richdynamix\PersonalisedProducts\Api\Data\ExportInterface; |
|
6
|
|
|
use \Magento\Framework\Model\AbstractModel; |
|
7
|
|
|
use \Magento\Catalog\Model\ProductFactory as ProductFactory; |
|
8
|
|
|
use \Richdynamix\PersonalisedProducts\Model\ExportFactory; |
|
9
|
|
|
use \Richdynamix\PersonalisedProducts\Logger\PersonalisedProductsLogger; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class Export |
|
13
|
|
|
* |
|
14
|
|
|
* @category Richdynamix |
|
15
|
|
|
* @package PersonalisedProducts |
|
16
|
|
|
* @author Steven Richardson ([email protected]) @mage_gizmo |
|
17
|
|
|
*/ |
|
18
|
|
|
class Export extends AbstractModel implements ExportInterface |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @var ProductFactory |
|
22
|
|
|
*/ |
|
23
|
|
|
private $_productFactory; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @var \Richdynamix\PersonalisedProducts\Model\ExportFactory |
|
27
|
|
|
*/ |
|
28
|
|
|
private $_exportFactory; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var PersonalisedProductsLogger |
|
32
|
|
|
*/ |
|
33
|
|
|
protected $_logger; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Export constructor. |
|
37
|
|
|
* @param ProductFactory $productFactory |
|
38
|
|
|
* @param \Magento\Framework\Model\Context $context |
|
39
|
|
|
* @param \Magento\Framework\Registry $registry |
|
40
|
|
|
* @param \Magento\Framework\Model\ResourceModel\AbstractResource|null $resource |
|
41
|
|
|
* @param \Magento\Framework\Data\Collection\AbstractDb|null $resourceCollection |
|
42
|
|
|
* @param array $data |
|
43
|
|
|
*/ |
|
44
|
|
|
public function __construct( |
|
45
|
|
|
ProductFactory $productFactory, |
|
46
|
|
|
\Magento\Framework\Model\Context $context, |
|
47
|
|
|
\Magento\Framework\Registry $registry, |
|
48
|
|
|
ExportFactory $exportFactory, |
|
49
|
|
|
PersonalisedProductsLogger $logger, |
|
50
|
|
|
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null, |
|
51
|
|
|
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null, |
|
52
|
|
|
array $data = [] |
|
53
|
|
|
) { |
|
54
|
|
|
$this->_productFactory = $productFactory; |
|
55
|
|
|
$this->_exportFactory = $exportFactory; |
|
56
|
|
|
$this->_logger = $logger; |
|
57
|
|
|
|
|
58
|
|
|
parent::__construct( |
|
59
|
|
|
$context, |
|
60
|
|
|
$registry, |
|
61
|
|
|
$resource, |
|
62
|
|
|
$resourceCollection, |
|
63
|
|
|
$data |
|
64
|
|
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Export constructor |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function _construct() |
|
71
|
|
|
{ |
|
72
|
|
|
$this->_init('Richdynamix\PersonalisedProducts\Model\ResourceModel\Export'); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* Get table increment ID |
|
77
|
|
|
* |
|
78
|
|
|
* @return mixed |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getId() |
|
81
|
|
|
{ |
|
82
|
|
|
return $this->getData(self::INCREMENT_ID); |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Get product ID |
|
87
|
|
|
* |
|
88
|
|
|
* @return mixed |
|
89
|
|
|
*/ |
|
90
|
|
|
public function getProductId() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->getData(self::PRODUCT_ID); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get created time |
|
97
|
|
|
* |
|
98
|
|
|
* @return mixed |
|
99
|
|
|
*/ |
|
100
|
|
|
public function getCreationTime() |
|
101
|
|
|
{ |
|
102
|
|
|
return $this->getData(self::CREATION_TIME); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Get updated time |
|
107
|
|
|
* |
|
108
|
|
|
* @return mixed |
|
109
|
|
|
*/ |
|
110
|
|
|
public function getUpdateTime() |
|
111
|
|
|
{ |
|
112
|
|
|
return $this->getData(self::UPDATE_TIME); |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Check product is exported |
|
117
|
|
|
* |
|
118
|
|
|
* @return bool |
|
119
|
|
|
*/ |
|
120
|
|
|
public function isExported() |
|
121
|
|
|
{ |
|
122
|
|
|
return (bool) $this->getData(self::IS_EXPORTED); |
|
123
|
|
|
} |
|
124
|
|
|
|
|
125
|
|
|
/** |
|
126
|
|
|
* Set table row increment ID |
|
127
|
|
|
* |
|
128
|
|
|
* @param mixed $id |
|
|
|
|
|
|
129
|
|
|
* @return $this |
|
130
|
|
|
*/ |
|
131
|
|
|
public function setId($incrementId) |
|
132
|
|
|
{ |
|
133
|
|
|
return $this->setData(self::INCREMENT_ID, $incrementId); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* Set row product ID |
|
138
|
|
|
* |
|
139
|
|
|
* @param $productId |
|
140
|
|
|
* @return $this |
|
141
|
|
|
*/ |
|
142
|
|
|
public function setProductId($productId) |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->setData(self::PRODUCT_ID, $productId); |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* Set row created time |
|
149
|
|
|
* |
|
150
|
|
|
* @param $creationTime |
|
151
|
|
|
* @return $this |
|
152
|
|
|
*/ |
|
153
|
|
|
public function setCreationTime($creationTime) |
|
154
|
|
|
{ |
|
155
|
|
|
return $this->setData(self::CREATION_TIME, $creationTime); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Set row updated time |
|
160
|
|
|
* |
|
161
|
|
|
* @param $updatedTime |
|
162
|
|
|
* @return $this |
|
163
|
|
|
*/ |
|
164
|
|
|
public function setUpdateTime($updatedTime) |
|
165
|
|
|
{ |
|
166
|
|
|
return $this->setData(self::UPDATE_TIME, $updatedTime); |
|
167
|
|
|
} |
|
168
|
|
|
|
|
169
|
|
|
/** |
|
170
|
|
|
* Set product as being exported |
|
171
|
|
|
* |
|
172
|
|
|
* @param $isExported |
|
173
|
|
|
* @return $this |
|
174
|
|
|
*/ |
|
175
|
|
|
public function setIsExported($isExported) |
|
176
|
|
|
{ |
|
177
|
|
|
return $this->setData(self::IS_ACTIVE, $isExported); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
/** |
|
181
|
|
|
* Get category ID's of the product |
|
182
|
|
|
* |
|
183
|
|
|
* @return array |
|
184
|
|
|
*/ |
|
185
|
|
|
public function getCategoryIds() |
|
186
|
|
|
{ |
|
187
|
|
|
$product = $this->_productFactory->create(); |
|
188
|
|
|
$product->load($this->getData(self::PRODUCT_ID)); |
|
189
|
|
|
|
|
190
|
|
|
return $product->getCategoryIds(); |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Save the new export item with Product Id |
|
195
|
|
|
* |
|
196
|
|
|
* @param $productId |
|
197
|
|
|
* @return Export |
|
198
|
|
|
*/ |
|
199
|
|
View Code Duplication |
public function saveProductForExport($productId) |
|
|
|
|
|
|
200
|
|
|
{ |
|
201
|
|
|
$exportItem = $this->_exportFactory->create(); |
|
202
|
|
|
$exportItem->setData('product_id', $productId); |
|
203
|
|
|
try { |
|
204
|
|
|
$exportItem->save(); |
|
205
|
|
|
} catch (\Exception $e) { |
|
206
|
|
|
$this->_logger->addError($e->getMessage()); |
|
207
|
|
|
} |
|
208
|
|
|
|
|
209
|
|
|
return $exportItem; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.