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
|
|
|
use XoopsModules\Oledrion; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Gestion des options (attributs) produits dans les commandes |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Class CaddyAttributesHandler |
31
|
|
|
*/ |
32
|
|
|
class CaddyAttributesHandler extends OledrionPersistableObjectHandler |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* CaddyAttributesHandler constructor. |
36
|
|
|
* @param \XoopsDatabase|null $db |
37
|
|
|
*/ |
38
|
|
|
public function __construct(\XoopsDatabase $db = null) |
39
|
|
|
{ |
40
|
|
|
// Table Classe Id |
41
|
|
|
parent::__construct($db, 'oledrion_caddy_attributes', CaddyAttributes::class, 'ca_id'); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Retourne le nombre d'attributs liés à un caddy |
46
|
|
|
* |
47
|
|
|
* @param int $ca_caddy_id L'ID du caddy concerné |
48
|
|
|
* @return int |
49
|
|
|
* @since 2.3.2009.03.23 |
50
|
|
|
*/ |
51
|
|
|
public function getAttributesCountForCaddy($ca_caddy_id) |
52
|
|
|
{ |
53
|
|
|
return $this->getCount(new \Criteria('ca_caddy_id', $ca_caddy_id, '=')); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Retourne la liste formatée des attributs liés à un caddy |
58
|
|
|
* |
59
|
|
|
* @param int $ca_caddy_id L'identifiant de caddy |
60
|
|
|
* @param Products $product Le produit concerné par le caddy |
61
|
|
|
* @return array |
62
|
|
|
* @since 2.3.2009.03.23 |
63
|
|
|
*/ |
64
|
|
|
public function getFormatedAttributesForCaddy($ca_caddy_id, Products $product) |
65
|
|
|
{ |
66
|
|
|
// $handlers = HandlerManager::getInstance(); |
67
|
|
|
$attributes = $ret = []; |
68
|
|
|
$attributes = $this->getObjects(new \Criteria('ca_caddy_id', $ca_caddy_id, '=')); |
69
|
|
|
if (0 === count($attributes)) { |
70
|
|
|
return $ret; |
71
|
|
|
} |
72
|
|
|
foreach ($attributes as $caddyAttribute) { |
73
|
|
|
$data = []; |
74
|
|
|
$attribute = null; |
75
|
|
|
$attribute = $attributesHandler->get($caddyAttribute->getVar('ca_attribute_id')); |
76
|
|
|
if (is_object($attribute)) { |
77
|
|
|
$data = $attribute->toArray(); |
78
|
|
|
} |
79
|
|
|
$data['attribute_options'] = $caddyAttribute->renderForInvoice($product); |
80
|
|
|
$ret[] = $data; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
return $ret; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Retourne le nombre de caddy attributs liés à un attribut |
88
|
|
|
* |
89
|
|
|
* @param int $ca_attribute_id L'Identifiant de l'attribut concerné |
90
|
|
|
* @return int |
91
|
|
|
* @since 2.3.2009.03.23 |
92
|
|
|
*/ |
93
|
|
|
public function getCaddyCountFromAttributeId($ca_attribute_id) |
94
|
|
|
{ |
95
|
|
|
return $this->getCount(new \Criteria('ca_attribute_id', $ca_attribute_id, '=')); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Retourne la liste des numéros de commandes "liés" à un attribut |
100
|
|
|
* |
101
|
|
|
* @param int $ca_attribute_id |
102
|
|
|
* @return array |
103
|
|
|
*/ |
104
|
|
|
public function getCommandIdFromAttribute($ca_attribute_id) |
105
|
|
|
{ |
106
|
|
|
$ret = $ordersIds = []; |
107
|
|
|
$criteria = new \Criteria('ca_attribute_id', $ca_attribute_id, '='); |
108
|
|
|
$ordersIds = $this->getObjects($criteria, false, true, 'ca_cmd_id', false); |
109
|
|
|
foreach ($ordersIds as $order) { |
110
|
|
|
$ret[] = $order->ca_cmd_id; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return $ret; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Supprime les caddies associés à une commande |
118
|
|
|
* |
119
|
|
|
* @param $ca_cmd_id |
120
|
|
|
* @return bool |
121
|
|
|
* @internal param int $caddy_cmd_id |
122
|
|
|
*/ |
123
|
|
|
public function removeCartsFromOrderId($ca_cmd_id) |
124
|
|
|
{ |
125
|
|
|
$ca_cmd_id = (int)$ca_cmd_id; |
126
|
|
|
|
127
|
|
|
return $this->deleteAll(new \Criteria('ca_cmd_id', $ca_cmd_id, '=')); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|