1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace XoopsModules\Oledrion; |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
You may not change or alter any portion of this comment or credits |
7
|
|
|
of supporting developers from this source code or any supporting source code |
8
|
|
|
which is considered copyrighted (c) material of the original comment or credit authors. |
9
|
|
|
|
10
|
|
|
This program is distributed in the hope that it will be useful, |
11
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* oledrion |
17
|
|
|
* |
18
|
|
|
* @copyright {@link https://xoops.org/ XOOPS Project} |
19
|
|
|
* @license {@link http://www.fsf.org/copyleft/gpl.html GNU public license} |
20
|
|
|
* @author Hervé Thouzard (http://www.herve-thouzard.com/) |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Gestion des produits mis en vente |
25
|
|
|
*/ |
26
|
|
|
|
27
|
|
|
use XoopsModules\Oledrion; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class Products |
31
|
|
|
*/ |
32
|
|
|
class Products extends OledrionObject |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* constructor |
36
|
|
|
* |
37
|
|
|
* normally, this is called from child classes only |
38
|
|
|
*/ |
39
|
|
|
public function __construct() |
40
|
|
|
{ |
41
|
|
|
$this->initVar('product_id', XOBJ_DTYPE_INT, null, false); |
42
|
|
|
$this->initVar('product_cid', XOBJ_DTYPE_INT, null, false); |
43
|
|
|
$this->initVar('product_title', XOBJ_DTYPE_TXTBOX, null, false); |
44
|
|
|
$this->initVar('product_vendor_id', XOBJ_DTYPE_INT, null, false); |
45
|
|
|
$this->initVar('product_sku', XOBJ_DTYPE_TXTBOX, null, false); |
46
|
|
|
$this->initVar('product_extraid', XOBJ_DTYPE_TXTBOX, null, false); |
47
|
|
|
$this->initVar('product_width', XOBJ_DTYPE_TXTBOX, null, false); |
48
|
|
|
$this->initVar('product_length', XOBJ_DTYPE_TXTBOX, null, false); |
49
|
|
|
$this->initVar('product_unitmeasure1', XOBJ_DTYPE_TXTBOX, null, false); |
50
|
|
|
$this->initVar('product_url', XOBJ_DTYPE_TXTBOX, null, false); |
51
|
|
|
$this->initVar('product_url2', XOBJ_DTYPE_TXTBOX, null, false); |
52
|
|
|
$this->initVar('product_url3', XOBJ_DTYPE_TXTBOX, null, false); |
53
|
|
|
$this->initVar('product_image_url', XOBJ_DTYPE_TXTBOX, null, false); |
54
|
|
|
$this->initVar('product_thumb_url', XOBJ_DTYPE_TXTBOX, null, false); |
55
|
|
|
$this->initVar('product_submitter', XOBJ_DTYPE_INT, null, false); |
56
|
|
|
$this->initVar('product_online', XOBJ_DTYPE_INT, null, false); |
57
|
|
|
// B.R. Start |
58
|
|
|
$this->initVar('skip_packing', XOBJ_DTYPE_INT, null, false); |
59
|
|
|
$this->initVar('skip_location', XOBJ_DTYPE_INT, null, false); |
60
|
|
|
$this->initVar('skip_delivery', XOBJ_DTYPE_INT, null, false); |
61
|
|
|
// B.R. End |
62
|
|
|
$this->initVar('product_date', XOBJ_DTYPE_TXTBOX, null, false); |
63
|
|
|
$this->initVar('product_submitted', XOBJ_DTYPE_INT, null, false); |
64
|
|
|
$this->initVar('product_hits', XOBJ_DTYPE_INT, null, false); |
65
|
|
|
$this->initVar('product_rating', XOBJ_DTYPE_INT, null, false); |
66
|
|
|
$this->initVar('product_votes', XOBJ_DTYPE_INT, null, false); |
67
|
|
|
$this->initVar('product_comments', XOBJ_DTYPE_INT, null, false); |
68
|
|
|
$this->initVar('product_price', XOBJ_DTYPE_TXTBOX, 0, false); |
69
|
|
|
$this->initVar('product_shipping_price', XOBJ_DTYPE_TXTBOX, 0, false); |
70
|
|
|
$this->initVar('product_discount_price', XOBJ_DTYPE_TXTBOX, 0, false); |
71
|
|
|
$this->initVar('product_stock', XOBJ_DTYPE_INT, null, false); |
72
|
|
|
$this->initVar('product_alert_stock', XOBJ_DTYPE_INT, null, false); |
73
|
|
|
$this->initVar('product_summary', XOBJ_DTYPE_OTHER, null, false); |
74
|
|
|
$this->initVar('product_description', XOBJ_DTYPE_OTHER, null, false); |
75
|
|
|
$this->initVar('product_attachment', XOBJ_DTYPE_TXTBOX, null, false); |
76
|
|
|
$this->initVar('product_weight', XOBJ_DTYPE_TXTBOX, null, false); |
77
|
|
|
$this->initVar('product_unitmeasure2', XOBJ_DTYPE_TXTBOX, null, false); |
78
|
|
|
$this->initVar('product_vat_id', XOBJ_DTYPE_INT, null, false); |
79
|
|
|
$this->initVar('product_download_url', XOBJ_DTYPE_TXTBOX, null, false); |
80
|
|
|
$this->initVar('product_recommended', XOBJ_DTYPE_TXTBOX, null, false); |
81
|
|
|
$this->initVar('product_metakeywords', XOBJ_DTYPE_TXTBOX, null, false); |
82
|
|
|
$this->initVar('product_metadescription', XOBJ_DTYPE_TXTBOX, null, false); |
83
|
|
|
$this->initVar('product_metatitle', XOBJ_DTYPE_TXTBOX, null, false); |
84
|
|
|
$this->initVar('product_delivery_time', XOBJ_DTYPE_INT, null, false); |
85
|
|
|
$this->initVar('product_ecotaxe', XOBJ_DTYPE_TXTBOX, 0, false); |
86
|
|
|
$this->initVar('product_property1', XOBJ_DTYPE_TXTBOX, null, false); |
87
|
|
|
$this->initVar('product_property2', XOBJ_DTYPE_TXTBOX, null, false); |
88
|
|
|
$this->initVar('product_property3', XOBJ_DTYPE_TXTBOX, null, false); |
89
|
|
|
$this->initVar('product_property4', XOBJ_DTYPE_TXTBOX, null, false); |
90
|
|
|
$this->initVar('product_property5', XOBJ_DTYPE_TXTBOX, null, false); |
91
|
|
|
$this->initVar('product_property6', XOBJ_DTYPE_TXTBOX, null, false); |
92
|
|
|
$this->initVar('product_property7', XOBJ_DTYPE_TXTBOX, null, false); |
93
|
|
|
$this->initVar('product_property8', XOBJ_DTYPE_TXTBOX, null, false); |
94
|
|
|
$this->initVar('product_property9', XOBJ_DTYPE_TXTBOX, null, false); |
95
|
|
|
$this->initVar('product_property10', XOBJ_DTYPE_TXTBOX, null, false); |
96
|
|
|
|
97
|
|
|
// Pour autoriser le html |
98
|
|
|
$this->initVar('dohtml', XOBJ_DTYPE_INT, 1, false); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Indique si le produit courant est visible (périmé, encore en stock, en ligne etc) |
103
|
|
|
* |
104
|
|
|
* @return bool |
105
|
|
|
* @since 2.3.2009.03.17 |
106
|
|
|
*/ |
107
|
|
|
public function isProductVisible() |
108
|
|
|
{ |
109
|
|
|
$isAdmin = Oledrion\Utility::isAdmin(); |
110
|
|
|
if (0 == $this->getVar('product_online')) { |
111
|
|
|
if (!$isAdmin) { |
112
|
|
|
return false; |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
if (0 == Oledrion\Utility::getModuleOption('show_unpublished') && $this->getVar('product_submitted') > time()) { |
116
|
|
|
if (!$isAdmin) { |
117
|
|
|
return false; |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
if (0 == Oledrion\Utility::getModuleOption('nostock_display') && 0 == $this->getVar('product_stock')) { |
121
|
|
|
if (!$isAdmin) { |
122
|
|
|
return false; |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return true; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Retourne l'URL de l'image du produit courant |
131
|
|
|
* |
132
|
|
|
* @return string L'URL |
133
|
|
|
*/ |
134
|
|
|
public function getPictureUrl() |
135
|
|
|
{ |
136
|
|
|
if ('' !== xoops_trim($this->getVar('product_image_url'))) { |
137
|
|
|
return OLEDRION_PICTURES_URL . '/' . $this->getVar('product_image_url'); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
return ''; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Retourne le chemin de l'image du produit courant |
145
|
|
|
* |
146
|
|
|
* @return string Le chemin |
147
|
|
|
*/ |
148
|
|
|
public function getPicturePath() |
149
|
|
|
{ |
150
|
|
|
if ('' !== xoops_trim($this->getVar('product_image_url'))) { |
151
|
|
|
return OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_image_url'); |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
return ''; |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Retourne l'URL de la vignette du produit courant |
159
|
|
|
* |
160
|
|
|
* @return string L'URL |
161
|
|
|
*/ |
162
|
|
|
public function getThumbUrl() |
163
|
|
|
{ |
164
|
|
|
if ('' !== xoops_trim($this->getVar('product_thumb_url'))) { |
165
|
|
|
return OLEDRION_PICTURES_URL . '/' . $this->getVar('product_thumb_url'); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
return ''; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Retourne l'URL de la vignette du produit courant |
173
|
|
|
* |
174
|
|
|
* @return string L'URL |
175
|
|
|
*/ |
176
|
|
|
public function getThumbPath() |
177
|
|
|
{ |
178
|
|
|
if ('' !== xoops_trim($this->getVar('product_thumb_url'))) { |
179
|
|
|
return OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_thumb_url'); |
180
|
|
|
} |
181
|
|
|
|
182
|
|
|
return ''; |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Indique si l'image du produit existe |
187
|
|
|
* |
188
|
|
|
* @return bool Vrai si l'image existe sinon faux |
189
|
|
|
*/ |
190
|
|
|
public function pictureExists() |
191
|
|
|
{ |
192
|
|
|
$return = false; |
193
|
|
|
if ('' !== xoops_trim($this->getVar('product_image_url')) && file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_image_url'))) { |
194
|
|
|
$return = true; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
return $return; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Indique si la vignette du produit existe |
202
|
|
|
* |
203
|
|
|
* @return bool Vrai si l'image existe sinon faux |
204
|
|
|
*/ |
205
|
|
|
public function thumbExists() |
206
|
|
|
{ |
207
|
|
|
$return = false; |
208
|
|
|
if ('' !== xoops_trim($this->getVar('product_thumb_url')) && file_exists(OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_thumb_url'))) { |
209
|
|
|
$return = true; |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
return $return; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
/** |
216
|
|
|
* Supprime l'image associée à un produit |
217
|
|
|
*/ |
218
|
|
|
public function deletePicture() |
219
|
|
|
{ |
220
|
|
|
if ($this->pictureExists()) { |
221
|
|
|
if (false === @unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_image_url'))) { |
222
|
|
|
throw new \RuntimeException('The picture ' . OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_image_url') . ' could not be deleted.'); |
223
|
|
|
} |
224
|
|
|
} |
225
|
|
|
$this->setVar('product_image_url', ''); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Indique si le fichier attaché à un produit existe |
230
|
|
|
* |
231
|
|
|
* @return bool |
232
|
|
|
*/ |
233
|
|
|
public function attachmentExists() |
234
|
|
|
{ |
235
|
|
|
$return = false; |
236
|
|
|
if ('' !== xoops_trim($this->getVar('product_attachment')) && file_exists(OLEDRION_ATTACHED_FILES_PATH . '/' . $this->getVar('product_attachment'))) { |
237
|
|
|
$return = true; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
return $return; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
/** |
244
|
|
|
* Supprime le fichier attaché |
245
|
|
|
*/ |
246
|
|
|
public function deleteAttachment() |
247
|
|
|
{ |
248
|
|
|
if ($this->attachmentExists()) { |
249
|
|
|
if (false === @unlink(OLEDRION_ATTACHED_FILES_PATH . '/' . $this->getVar('product_attachment'))) { |
250
|
|
|
throw new \RuntimeException('The file ' . OLEDRION_ATTACHED_FILES_PATH . '/' . $this->getVar('product_attachment') . ' could not be deleted.'); |
251
|
|
|
} |
252
|
|
|
} |
253
|
|
|
$this->setVar('product_attachment', ''); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
257
|
|
|
* Supprime la miniature associée à un produit |
258
|
|
|
*/ |
259
|
|
|
public function deleteThumb() |
260
|
|
|
{ |
261
|
|
|
if ($this->thumbExists()) { |
262
|
|
|
if (false === @unlink(OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_thumb_url'))) { |
263
|
|
|
throw new \RuntimeException('The thumb ' . OLEDRION_PICTURES_PATH . '/' . $this->getVar('product_thumb_url') . ' could not be deleted.'); |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
$this->setVar('product_thumb_url', ''); |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Supprime les 2 images (raccourcis) |
271
|
|
|
*/ |
272
|
|
|
public function deletePictures() |
273
|
|
|
{ |
274
|
|
|
$this->deletePicture(); |
275
|
|
|
$this->deleteThumb(); |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Retourne le prix TTC du prix réduit du produit courant |
280
|
|
|
* |
281
|
|
|
* @return float Le montant TTC du prix réduit |
282
|
|
|
*/ |
283
|
|
|
public function getDiscountTTC() |
284
|
|
|
{ |
285
|
|
|
return Oledrion\Utility::getAmountWithVat($this->getVar('product_discount_price', 'e'), $this->getVar('product_vat_id')); |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* Retourne le montant TTC du prix normal du produit |
290
|
|
|
* |
291
|
|
|
* @return float |
292
|
|
|
*/ |
293
|
|
|
public function getTTC() |
294
|
|
|
{ |
295
|
|
|
return Oledrion\Utility::getAmountWithVat($this->getVar('product_price', 'e'), $this->getVar('product_vat_id')); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* Indique si le produit courant est recommandé. |
300
|
|
|
* |
301
|
|
|
* @param bool $withDescription |
302
|
|
|
* @return bool Vrai si le produit est recommandé sinon faux |
303
|
|
|
*/ |
304
|
|
|
public function isRecommended($withDescription = false) |
305
|
|
|
{ |
306
|
|
|
if ('0000-00-00' != $this->getVar('product_recommended')) { |
307
|
|
|
return $withDescription ? _YES : true; |
|
|
|
|
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
return $withDescription ? _NO : false; |
|
|
|
|
311
|
|
|
} |
312
|
|
|
|
313
|
|
|
/** |
314
|
|
|
* Place le produit courant dans l'état "recommandé" |
315
|
|
|
*/ |
316
|
|
|
public function setRecommended() |
317
|
|
|
{ |
318
|
|
|
$this->setVar('product_recommended', date('Y-m-d')); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Enlève "l'attribut" recommandé d'un produit |
323
|
|
|
*/ |
324
|
|
|
public function unsetRecommended() |
325
|
|
|
{ |
326
|
|
|
$this->setVar('product_recommended', '0000-00-00'); |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* Retourne l'image qui indique si le produit est recommandé ou pas |
331
|
|
|
* |
332
|
|
|
* @return string La chaine à utiliser pour voir l'image |
333
|
|
|
*/ |
334
|
|
|
public function recommendedPicture() |
335
|
|
|
{ |
336
|
|
|
if ($this->isRecommended()) { |
337
|
|
|
return '<img src="' . OLEDRION_IMAGES_URL . 'heart.png" alt="' . _OLEDRION_IS_RECOMMENDED . '"> '; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
return '<img src="' . OLEDRION_IMAGES_URL . 'blank.gif" alt="">'; |
341
|
|
|
} |
342
|
|
|
|
343
|
|
|
/** |
344
|
|
|
* Retourne le lien du produit courant en tenant compte de l'URL Rewriting |
345
|
|
|
* |
346
|
|
|
* @param int $product_id L'identifiant du produit |
347
|
|
|
* @param string $product_title Le titre du produit |
348
|
|
|
* @param bool $shortVersion Indique si on veut la version avec l'url complpète ou la version avec juste la page et le paramètre |
349
|
|
|
* @return string |
350
|
|
|
*/ |
351
|
|
|
public function getLink($product_id = 0, $product_title = '', $shortVersion = false) |
352
|
|
|
{ |
353
|
|
|
$url = ''; |
354
|
|
|
if (0 == $product_id && '' === $product_title) { |
355
|
|
|
$product_id = $this->getVar('product_id'); |
356
|
|
|
$product_title = $this->getVar('product_title', 'n'); |
357
|
|
|
// B.R. New |
358
|
|
|
$product_url = $this->getVar('product_url3', 'n'); |
359
|
|
|
// End New |
360
|
|
|
} |
361
|
|
|
// B.R. New |
362
|
|
|
if (empty($product_url)) { |
363
|
|
|
// End New |
364
|
|
|
if (1 == Oledrion\Utility::getModuleOption('urlrewriting')) { |
365
|
|
|
// On utilise l'url rewriting |
366
|
|
|
if (!$shortVersion) { |
367
|
|
|
$url = OLEDRION_URL . 'product-' . $product_id . Oledrion\Utility::makeSeoUrl($product_title) . '.html'; |
368
|
|
|
} else { |
369
|
|
|
$url = 'product-' . $product_id . Oledrion\Utility::makeSeoUrl($product_title) . '.html'; |
370
|
|
|
} |
371
|
|
|
} else { |
372
|
|
|
// Pas d'utilisation de l'url rewriting |
373
|
|
|
if (!$shortVersion) { |
374
|
|
|
$url = OLEDRION_URL . 'product.php?product_id=' . $product_id; |
375
|
|
|
} else { |
376
|
|
|
$url = 'product.php?product_id=' . $product_id; |
377
|
|
|
} |
378
|
|
|
} |
379
|
|
|
// B.R. New |
380
|
|
|
} else { |
381
|
|
|
$url = '../' . $product_url; |
382
|
|
|
} |
383
|
|
|
// B.R. End New |
384
|
|
|
return $url; |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
/** |
388
|
|
|
* Retourne le nombre d'attributs du produit courant |
389
|
|
|
* |
390
|
|
|
* @return int |
391
|
|
|
* @since 2.3.2009.03.19 |
392
|
|
|
*/ |
393
|
|
|
public function productAttributesCount() |
394
|
|
|
{ |
395
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
396
|
|
|
$attributesHandler = new Oledrion\AttributesHandler($db); |
397
|
|
|
|
398
|
|
|
return $attributesHandler->getProductAttributesCount($this->getVar('product_id')); |
399
|
|
|
} |
400
|
|
|
|
401
|
|
|
/** |
402
|
|
|
* Retourne le nombre d'attributs obligatoires d'un produit |
403
|
|
|
* |
404
|
|
|
* @note : La fonction est "doublée", elle se trouve içi et dans la classe des attributs pour des raisons de facilité (et de logique) |
405
|
|
|
* |
406
|
|
|
* @return int |
407
|
|
|
* @since 2.3.2009.03.20 |
408
|
|
|
*/ |
409
|
|
|
public function getProductMandatoryAttributesCount() |
410
|
|
|
{ |
411
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
412
|
|
|
$attributesHandler = new Oledrion\AttributesHandler($db); |
413
|
|
|
|
414
|
|
|
return $attributesHandler->getProductMandatoryAttributesCount($this); |
415
|
|
|
} |
416
|
|
|
|
417
|
|
|
/** |
418
|
|
|
* Retourne la liste des attributs obligatoires du produit |
419
|
|
|
* |
420
|
|
|
* @return array |
421
|
|
|
* @since 2.3.2009.03.20 |
422
|
|
|
*/ |
423
|
|
|
public function getProductMandatoryFieldsList() |
424
|
|
|
{ |
425
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
426
|
|
|
$attributesHandler = new Oledrion\AttributesHandler($db); |
427
|
|
|
|
428
|
|
|
return $attributesHandler->getProductMandatoryFieldsList($this); |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
/** |
432
|
|
|
* Retourne la liste des attributs du produit courant |
433
|
|
|
* |
434
|
|
|
* @param null $attributesIds |
|
|
|
|
435
|
|
|
* @return array Objets de type Oledrion_attributes |
436
|
|
|
* @since 2.3.2009.03.20 |
437
|
|
|
*/ |
438
|
|
|
public function getProductsAttributesList($attributesIds = null) |
439
|
|
|
{ |
440
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
441
|
|
|
$attributesHandler = new Oledrion\AttributesHandler($db); |
442
|
|
|
|
443
|
|
|
return $attributesHandler->getProductsAttributesList($this->getVar('product_id'), $attributesIds); |
|
|
|
|
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Retourne le montant HT initial des options |
448
|
|
|
* |
449
|
|
|
* @return float |
450
|
|
|
*/ |
451
|
|
|
public function getInitialOptionsPrice() |
452
|
|
|
{ |
453
|
|
|
$db = \XoopsDatabaseFactory::getDatabaseConnection(); |
454
|
|
|
$attributesHandler = new Oledrion\AttributesHandler($db); |
455
|
|
|
|
456
|
|
|
return $attributesHandler->getInitialOptionsPrice($this); |
457
|
|
|
} |
458
|
|
|
|
459
|
|
|
/** |
460
|
|
|
* @return int |
461
|
|
|
*/ |
462
|
|
|
public function isNewProduct() |
463
|
|
|
{ |
464
|
|
|
$time = time() - (60 * 60 * 24 * 10); |
465
|
|
|
if ($this->getVar('product_submitted') > $time) { |
466
|
|
|
return 1; |
467
|
|
|
} |
468
|
|
|
|
469
|
|
|
return 0; |
470
|
|
|
} |
471
|
|
|
|
472
|
|
|
/** |
473
|
|
|
* Retourne les éléments du produits formatés pour affichage |
474
|
|
|
* |
475
|
|
|
* @param string $format Le format à utiliser |
476
|
|
|
* @return array Les informations formatées |
477
|
|
|
*/ |
478
|
|
|
public function toArray($format = 's') |
479
|
|
|
{ |
480
|
|
|
$ret = []; |
|
|
|
|
481
|
|
|
$ret = parent::toArray($format); |
482
|
|
|
$oledrionCurrency = Oledrion\Currency::getInstance(); |
483
|
|
|
$ttc = $finalPriceTTC = $this->getTTC(); |
484
|
|
|
$finalPriceHT = (float)$this->getVar('product_price'); |
485
|
|
|
|
486
|
|
|
$ret['product_ecotaxe_formated'] = $oledrionCurrency->amountForDisplay($this->getVar('product_ecotaxe')); |
487
|
|
|
|
488
|
|
|
$ret['product_price_formated'] = $oledrionCurrency->amountForDisplay($this->getVar('product_price', 'e')); |
489
|
|
|
$ret['product_shipping_price_formated'] = $oledrionCurrency->amountForDisplay($this->getVar('product_shipping_price', 'e')); |
490
|
|
|
$ret['product_discount_price_formated'] = $oledrionCurrency->amountForDisplay($this->getVar('product_discount_price', 'e')); |
491
|
|
|
$ret['product_price_ttc'] = $oledrionCurrency->amountForDisplay($ttc); |
492
|
|
|
$ret['product_price_ttc_long'] = $oledrionCurrency->amountForDisplay($ttc, 'l'); |
493
|
|
|
|
494
|
|
|
if ((int)$this->getVar('product_discount_price') > 0) { |
495
|
|
|
//geeker |
496
|
|
|
$finalPriceTTC = $this->getDiscountTTC(); |
497
|
|
|
$finalPriceHT = (float)$this->getVar('product_discount_price', 'e'); |
498
|
|
|
$ret['product_discount_price_ttc'] = $oledrionCurrency->amountForDisplay($this->getDiscountTTC()); |
499
|
|
|
$ret['product_discount_price_ttc_long'] = $oledrionCurrency->amountForDisplay($this->getDiscountTTC(), 'l'); |
500
|
|
|
} else { |
501
|
|
|
$ret['product_discount_price_ttc'] = ''; |
502
|
|
|
$ret['product_discount_price_ttc_long'] = ''; |
503
|
|
|
} |
504
|
|
|
// Les informations sur les attributs |
505
|
|
|
$attributesCount = $this->productAttributesCount(); |
506
|
|
|
$ret['product_attributes_count'] = $attributesCount; |
507
|
|
|
if ($attributesCount > 0) { |
508
|
|
|
$optionsPrice = $this->getInitialOptionsPrice(); |
509
|
|
|
$ret['product_price_formated'] = $oledrionCurrency->amountForDisplay((float)$this->getVar('product_price', 'e') + $optionsPrice); |
510
|
|
|
$ret['product_discount_price_formated'] = $oledrionCurrency->amountForDisplay((float)$this->getVar('product_discount_price', 'e') + $optionsPrice); |
511
|
|
|
$ret['product_price_ttc'] = $oledrionCurrency->amountForDisplay($ttc + $optionsPrice); |
512
|
|
|
$ret['product_price_ttc_long'] = $oledrionCurrency->amountForDisplay($ttc + $optionsPrice, 'l'); |
513
|
|
|
if (0 != (int)$this->getVar('product_discount_price')) { |
514
|
|
|
$finalPriceTTC = $this->getDiscountTTC() + $optionsPrice; |
515
|
|
|
$finalPriceHT = (float)$this->getVar('product_discount_price', 'e') + $optionsPrice; |
516
|
|
|
$ret['product_discount_price_ttc'] = $oledrionCurrency->amountForDisplay((float)$this->getDiscountTTC() + $optionsPrice); |
517
|
|
|
$ret['product_discount_price_ttc_long'] = $oledrionCurrency->amountForDisplay((float)$this->getDiscountTTC() + $optionsPrice, 'l'); |
518
|
|
|
} |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
$ret['product_final_price_ht_formated_long'] = $oledrionCurrency->amountForDisplay($finalPriceHT, 'l'); |
522
|
|
|
$ret['product_final_price_ttc'] = $finalPriceTTC; |
523
|
|
|
$ret['product_final_price_ttc_javascript'] = Oledrion\Utility::formatFloatForDB($finalPriceTTC); |
524
|
|
|
$ret['product_final_price_ttc_formated'] = $oledrionCurrency->amountForDisplay($finalPriceTTC); |
525
|
|
|
$ret['product_final_price_ttc_formated_long'] = $oledrionCurrency->amountForDisplay($finalPriceTTC, 'l'); |
526
|
|
|
$ret['product_vat_amount_formated_long'] = $oledrionCurrency->amountForDisplay($finalPriceHT - $finalPriceTTC); |
527
|
|
|
|
528
|
|
|
$ret['product_tooltip'] = Oledrion\Utility::makeInfotips($this->getVar('product_description')); |
529
|
|
|
$ret['product_url_rewrited'] = $this->getLink(); |
530
|
|
|
$ret['product_href_title'] = Oledrion\Utility::makeHrefTitle($this->getVar('product_title')); |
|
|
|
|
531
|
|
|
$ret['product_recommended'] = $this->isRecommended(); |
532
|
|
|
$ret['product_recommended_picture'] = $this->recommendedPicture(); |
533
|
|
|
|
534
|
|
|
$ret['product_image_full_url'] = $this->getPictureUrl(); |
535
|
|
|
$ret['product_thumb_full_url'] = $this->getThumbUrl(); |
536
|
|
|
$ret['product_image_full_path'] = $this->getPicturePath(); |
537
|
|
|
$ret['product_thumb_full_path'] = $this->getThumbPath(); |
538
|
|
|
|
539
|
|
|
$ret['product_shorten_summary'] = Oledrion\Utility::truncate_tagsafe($this->getVar('product_summary'), OLEDRION_SUMMARY_MAXLENGTH); |
540
|
|
|
$ret['product_shorten_description'] = Oledrion\Utility::truncate_tagsafe($this->getVar('product_description'), OLEDRION_SUMMARY_MAXLENGTH); |
541
|
|
|
$ret['product_new'] = $this->isNewProduct(); |
542
|
|
|
|
543
|
|
|
return $ret; |
544
|
|
|
} |
545
|
|
|
} |
546
|
|
|
|