Newer
Older
<?php
/**
* This class contains \QUI\ERP\Shipping\Shipping
*/
namespace QUI\ERP\Shipping;
use QUI;
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
use QUI\ERP\Shipping\Types\Factory;
use QUI\ERP\Shipping\Api\AbstractShippingProvider;
use QUI\ERP\Shipping\Api\AbstractShippingEntry;
/**
* Shipping
*
* @author www.pcsg.de (Henning Leutz)
*/
class Shipping extends QUI\Utils\Singleton
{
/**
* @var array
*/
protected $shipping = [];
/**
* Return all available shipping provider
*
* @return array
*/
public function getShippingProviders()
{
$cacheProvider = 'package/quiqqer/shipping/provider';
try {
$providers = QUI\Cache\Manager::get($cacheProvider);
} catch (QUI\Cache\Exception $Exception) {
$packages = \array_map(function ($package) {
return $package['name'];
}, QUI::getPackageManager()->getInstalled());
$providers = [];
foreach ($packages as $package) {
try {
$Package = QUI::getPackage($package);
if ($Package->isQuiqqerPackage()) {
$providers = array_merge($providers, $Package->getProvider('shipping'));
}
} catch (QUI\Exception $Exception) {
}
}
try {
QUI\Cache\Manager::set($cacheProvider, $providers);
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
// filter provider
$result = [];
foreach ($providers as $provider) {
if (!class_exists($provider)) {
continue;
}
$Provider = new $provider();
if (!($Provider instanceof AbstractShippingProvider)) {
continue;
}
$result[] = $Provider;
}
return $result;
}
/**
* Return all available Shipping methods
*
* @return array
*/
public function getShippingTypes()
{
$shipping = [];
$providers = $this->getShippingProviders();
foreach ($providers as $Provider) {
foreach ($types as $type) {
if (!\class_exists($type)) {
if ($ShippingType instanceof QUI\ERP\Shipping\Api\ShippingTypeInterface) {
$shipping[$ShippingType->getType()] = $ShippingType;
}
}
}
return $shipping;
}
/**
* Return a wanted shipping type
*
* @param string $shippingType - type of the shipping type
* @return QUI\ERP\Shipping\Api\ShippingTypeInterface
if (empty($shippingType)) {
throw new Exception([
'quiqqer/shipping',
'exception.shipping.type.not.found',
['shippingType' => '']
]);
}
/* @var $Shipping QUI\ERP\Shipping\Api\ShippingTypeInterface */
return $Shipping;
}
}
throw new Exception([
'quiqqer/shipping',
'exception.shipping.type.not.found',
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
]);
}
/**
* Return a shipping
*
* @param int|string $shippingId - ID of the shipping type
* @return QUI\ERP\Shipping\Api\AbstractShippingEntry
*
* @throws Exception
*/
public function getShippingEntry($shippingId)
{
try {
return Factory::getInstance()->getChild($shippingId);
} catch (QUI\Exception $Exception) {
throw new Exception([
'quiqqer/shipping',
'exception.shipping.not.found'
]);
}
}
/**
* Return all active shipping
*
* @param array $queryParams
* @return QUI\ERP\Shipping\Types\ShippingEntry[]
*/
public function getShippingList($queryParams = [])
{
if (!isset($queryParams['order'])) {
$queryParams['order'] = 'priority ASC';
}
try {
return Factory::getInstance()->getChildren($queryParams);
} catch (QUi\Exception $Exception) {
return [];
}
}
/**
* Return all shipping entries for the user
*
* @param \QUI\Interfaces\Users\User|null $User - optional
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
*/
public function getUserShipping($User = null)
{
if ($User === null) {
$User = QUI::getUserBySession();
}
$shipping = \array_filter($this->getShippingList(), function ($Shipping) use ($User) {
/* @var $Shipping QUI\ERP\Shipping\Types\ShippingEntry */
return $Shipping->canUsedBy($User);
});
return $shipping;
}
/**
* @return bool|string
*/
public function getHost()
{
try {
$Project = QUI::getRewrite()->getProject();
} catch (QUI\Exception $Exception) {
try {
$Project = QUI::getProjectManager()->getStandard();
} catch (QUI\Exception $Exception) {
QUI\System\Log::writeException($Exception);
return '';
}
}
$host = $Project->getVHost(true, true);
$host = trim($host, '/');
return $host;
}
/**
* @param QUI\ERP\Order\Order|
* QUI\ERP\Order\OrderInProcess|
* QUI\ERP\Accounting\Invoice\Invoice|
* QUI\ERP\Accounting\Invoice\InvoiceTemporary
* $Order
*/
public function getShippingByObject($Object)
{
}
public function getShippingByOrderId($orderId)
{
}