-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
72 lines (57 loc) · 2.19 KB
/
Plugin.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
69
70
71
72
<?php namespace Octommerce\ShippingAPI;
use System\Classes\PluginBase;
use RainLab\User\Models\User;
use Octommerce\Octommerce\Models\Cart;
use Octommerce\Octommerce\Models\Order;
use Octobro\OAuth2\Transformers\UserTransformer;
use Octommerce\API\Transformers\CartTransformer;
use Octommerce\API\Transformers\OrderTransformer;
use Octommerce\ShippingAPI\Transformers\AddressTransformer;
class Plugin extends PluginBase
{
public $require = ['Octobro.API', 'Octommerce.Shipping'];
public function registerComponents()
{
}
public function registerSettings()
{
}
public function boot()
{
CartTransformer::extend(function($transformer) {
$transformer->addField('shipping_cost', function(Cart $cart) {
return (float) $cart->shipping_cost;
});
$transformer->addFields(['shipping_courier', 'shipping_service']);
});
OrderTransformer::extend(function($transformer) {
$transformer->addField('shipping_cost', function(Order $order) {
return (float) $order->shipping_cost;
});
$transformer->addField('is_cod', function(Order $order) {
return (Boolean) $order->is_cod;
});
$transformer->addField('shipping_latitude', function(Order $order) {
return (float) $order->shipping_latitude;
});
$transformer->addField('shipping_longitude', function(Order $order) {
return (float) $order->shipping_longitude;
});
$transformer->addFields([
'shipping_courier',
'shipping_service',
]);
$transformer->addInclude('os_shipping_address', function(Order $order) use ($transformer) {
return $transformer->item($order->os_shipping_address, new AddressTransformer);
});
});
UserTransformer::extend(function($transformer) {
$transformer->addInclude('addresses', function(User $user) use ($transformer) {
return $transformer->collection($user->addresses, new AddressTransformer);
});
$transformer->addField('addresses_count', function(User $user) {
return $user->addresses()->count();
});
});
}
}