forked from PululuK/democustomfields17
/
ProductCustomFields.php
68 lines (57 loc) · 1.7 KB
/
ProductCustomFields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace PrestaShop\Module\PconConfiguratorUrl\Model;
use ObjectModel;
use DbQuery;
use Db;
class ProductCustomFields extends ObjectModel {
/** @var int ID */
public $id;
/** @var int product ID */
public $id_product;
/** @var string */
public $pconconfiguratorurl_field;
/** @var string Object creation date */
public $date_add;
/** @var string Object last modification date */
public $date_upd;
/**
* @see ObjectModel::$definition
*/
public static $definition = [
'table' => 'pconconfiguratorurl',
'primary' => 'id_pconconfiguratorurl',
'multilang' => false,
'multilang_shop' => false,
'fields' => [
'id_product' => [
'type' => self::TYPE_INT,
'validate' => 'isUnsignedId'
],
'pconconfiguratorurl_field' => [
'type' => self::TYPE_STRING,
'validate' => 'isAbsoluteUrl'
],
'date_add' => [
'type' => self::TYPE_DATE,
'validate' => 'isDate'
],
'date_upd' => [
'type' => self::TYPE_DATE,
'validate' => 'isDate'
],
],
];
public static function getInstanceByProductId(
int $idProduct,
?int $idLang = null,
?int $idShop = null
) : self
{
$sql = new DbQuery();
$sql->select(self::$definition['primary']);
$sql->from(self::$definition['table'], 'b');
$sql->where('b.id_product = '.(int)$idProduct);
$idObject = (int)Db::getInstance()->getValue($sql);
return (new self($idObject, $idLang, $idShop));
}
}