|
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 Hossein Azizabadi ([email protected]) |
|
21
|
|
|
*/ |
|
22
|
|
|
|
|
23
|
|
|
use XoopsModules\Oledrion; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Class DeliveryHandler |
|
27
|
|
|
*/ |
|
28
|
|
|
class DeliveryHandler extends OledrionPersistableObjectHandler |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* DeliveryHandler constructor. |
|
32
|
|
|
* @param \XoopsDatabase|null $db |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(\XoopsDatabase $db = null) |
|
35
|
|
|
{ |
|
36
|
|
|
// Table Classe Id |
|
37
|
|
|
parent::__construct($db, 'oledrion_delivery', Delivery::class, 'delivery_id'); |
|
|
|
|
|
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param Parameters $parameters |
|
42
|
|
|
* @return array |
|
43
|
|
|
*/ |
|
44
|
|
|
public function getAllDelivery(Parameters $parameters) |
|
45
|
|
|
{ |
|
46
|
|
|
$parameters = $parameters->extend(new Oledrion\Parameters([ |
|
47
|
|
|
'start' => 0, |
|
48
|
|
|
'limit' => 0, |
|
49
|
|
|
'sort' => 'delivery_id', |
|
50
|
|
|
'order' => 'ASC', |
|
51
|
|
|
])); |
|
52
|
|
|
$critere = new \Criteria('delivery_id', 0, '<>'); |
|
53
|
|
|
$critere->setLimit($parameters['limit']); |
|
54
|
|
|
$critere->setStart($parameters['start']); |
|
55
|
|
|
$critere->setSort($parameters['sort']); |
|
56
|
|
|
$critere->setOrder($parameters['order']); |
|
57
|
|
|
$categories = []; |
|
|
|
|
|
|
58
|
|
|
$categories = $this->getObjects($critere); |
|
59
|
|
|
|
|
60
|
|
|
return $categories; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* @param Parameters $parameters |
|
65
|
|
|
* @return array |
|
66
|
|
|
*/ |
|
67
|
|
|
public function getLocationDelivery(Parameters $parameters) |
|
68
|
|
|
{ |
|
69
|
|
|
global $locationDeliveryHandler; |
|
70
|
|
|
$ret = []; |
|
71
|
|
|
$parameters = $parameters->extend(new Oledrion\Parameters([ |
|
72
|
|
|
'start' => 0, |
|
73
|
|
|
'limit' => 0, |
|
74
|
|
|
'sort' => 'delivery_id', |
|
75
|
|
|
'order' => 'ASC', |
|
76
|
|
|
'location' => '', |
|
77
|
|
|
])); |
|
78
|
|
|
$location_delivery = $locationDeliveryHandler->getLocationDeliveryId($parameters); |
|
79
|
|
|
|
|
80
|
|
|
$critere = new \CriteriaCompo(); |
|
81
|
|
|
$critere->setLimit($parameters['limit']); |
|
82
|
|
|
$critere->setStart($parameters['start']); |
|
83
|
|
|
$critere->setSort($parameters['sort']); |
|
84
|
|
|
$critere->setOrder($parameters['order']); |
|
85
|
|
|
$obj = $this->getObjects($critere); |
|
86
|
|
|
if ($obj) { |
|
|
|
|
|
|
87
|
|
|
foreach ($obj as $root) { |
|
88
|
|
|
// $tab = []; |
|
89
|
|
|
$tab = $root->toArray(); |
|
90
|
|
|
if (isset($location_delivery[$root->getVar('delivery_id')]['ld_delivery']) && $location_delivery[$root->getVar('delivery_id')]['ld_delivery'] == $root->getVar('delivery_id')) { |
|
91
|
|
|
$tab['ld_id']['delivery_select'] = 1; |
|
92
|
|
|
$tab['ld_id']['ld_id'] = $location_delivery[$root->getVar('delivery_id')]['ld_id']; |
|
93
|
|
|
$tab['ld_id']['ld_location'] = $location_delivery[$root->getVar('delivery_id')]['ld_location']; |
|
94
|
|
|
$tab['ld_id']['ld_delivery'] = $location_delivery[$root->getVar('delivery_id')]['ld_delivery']; |
|
95
|
|
|
$tab['ld_id']['ld_price'] = $location_delivery[$root->getVar('delivery_id')]['ld_price']; |
|
96
|
|
|
$tab['ld_id']['ld_delivery_time'] = $location_delivery[$root->getVar('delivery_id')]['ld_delivery_time']; |
|
97
|
|
|
} |
|
98
|
|
|
$ret[] = $tab; |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $ret; |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @param $location_id |
|
107
|
|
|
* @return array |
|
108
|
|
|
*/ |
|
109
|
|
|
public function getThisLocationDelivery($location_id) |
|
110
|
|
|
{ |
|
111
|
|
|
global $locationDeliveryHandler; |
|
112
|
|
|
$oledrionCurrency = Oledrion\Currency::getInstance(); |
|
113
|
|
|
$ret = []; |
|
114
|
|
|
$parameters = ['location' => $location_id]; |
|
115
|
|
|
$location_delivery = $locationDeliveryHandler->getLocationDeliveryId($parameters); |
|
116
|
|
|
foreach ($location_delivery as $location) { |
|
117
|
|
|
$id[] = $location['ld_delivery']; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$critere = new \CriteriaCompo(); |
|
121
|
|
|
$critere->add(new \Criteria('delivery_id', '(' . implode(',', $id) . ')', 'IN')); |
|
|
|
|
|
|
122
|
|
|
$critere->add(new \Criteria('delivery_online', 1)); |
|
123
|
|
|
$obj = $this->getObjects($critere); |
|
124
|
|
|
if ($obj) { |
|
|
|
|
|
|
125
|
|
|
foreach ($obj as $root) { |
|
126
|
|
|
$tab = []; |
|
|
|
|
|
|
127
|
|
|
$tab = $root->toArray(); |
|
128
|
|
|
$tab['delivery_price'] = $location_delivery[$root->getVar('delivery_id')]['ld_price']; |
|
129
|
|
|
$tab['delivery_price_fordisplay'] = $oledrionCurrency->amountForDisplay($tab['delivery_price']); |
|
130
|
|
|
$tab['delivery_time'] = $location_delivery[$root->getVar('delivery_id')]['ld_delivery_time']; |
|
131
|
|
|
$ret[] = $tab; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
return $ret; |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
/** |
|
139
|
|
|
* @param $location_id |
|
140
|
|
|
* @param $delivery_id |
|
141
|
|
|
* @return array |
|
142
|
|
|
*/ |
|
143
|
|
|
public function getThisLocationThisDelivery($location_id, $delivery_id) |
|
144
|
|
|
{ |
|
145
|
|
|
global $locationDeliveryHandler; |
|
146
|
|
|
$location_delivery = $locationDeliveryHandler->getDelivery($location_id, $delivery_id); |
|
147
|
|
|
$ret = []; |
|
|
|
|
|
|
148
|
|
|
$obj = $this->get($location_id); |
|
149
|
|
|
$ret = $obj->toArray(); |
|
150
|
|
|
$ret['delivery_price'] = $location_delivery['ld_price']; |
|
151
|
|
|
$ret['delivery_time'] = $location_delivery['ld_delivery_time']; |
|
152
|
|
|
|
|
153
|
|
|
return $ret; |
|
154
|
|
|
} |
|
155
|
|
|
} |
|
156
|
|
|
|