-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlugin.php
146 lines (131 loc) · 3.81 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php namespace Octommerce\Courier;
use Event;
use Backend;
use System\Classes\PluginBase;
use Octommerce\Courier\Classes\CourierManager;
use RainLab\User\Models\User;
use Octommerce\Courier\Models\Settings;
/**
* courier Plugin Information File
*/
class Plugin extends PluginBase
{
public $require = ['RainLab.User', 'Octommerce.Octommerce'];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'octommerce.courier::lang.plugin.name',
'description' => 'octommerce.courier::lang.plugin.description',
'author' => 'Surahman',
'icon' => 'icon-ship'
];
}
public function registerSettings()
{
return [
'courier' => [
'label' => 'Courier',
'description' => 'Manage courier plugin by octommerce',
'category' => 'Courier',
'icon' => 'icon-truck',
'class' => 'Octommerce\Courier\Models\Settings',
'order' => 500,
'keywords' => 'courier shipping'
]
];
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
CourierManager::instance()->addCourier('Octommerce\Courier\Couriers\Jne');
User::extend(function($model) {
$model->hasOne['location'] = [
'Octommerce\Courier\Models\Location',
'key' => 'code',
'otherKey' => 'location_code'
];
});
Event::listen('cms.page.beforeDisplay', function($controller, $url, $page) {
$controller->vars['oc_courier_settings'] = Settings::instance();
});
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return [
'Octommerce\Courier\Components\Cost' => 'cost',
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return []; // Remove this line to activate
return [
'octommerce.courier.some_permission' => [
'tab' => 'courier',
'label' => 'Some permission'
],
];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
public function registerNavigation()
{
return []; // Remove this line to activate
return [
'courier' => [
'label' => 'courier',
'url' => Backend::url('octommerce/courier/mycontroller'),
'icon' => 'icon-leaf',
'permissions' => ['octommerce.courier.*'],
'order' => 500,
],
];
}
/**
* Register new Twig variables
* @return array
*/
public function registerMarkupTags()
{
return [
'functions' => [
'form_select_province' => ['Octommerce\Courier\Models\Location', 'formSelectProvince'],
'form_select_city' => ['Octommerce\Courier\Models\Location', 'formSelectCity'],
'form_select_district' => ['Octommerce\Courier\Models\Location', 'formSelectDistrict'],
'form_select_subdistrict' => ['Octommerce\Courier\Models\Location', 'formSelectSubdistrict'],
'json_decode' => function($json, $assoc = false) {
return json_decode($json, $assoc);
}
]
];
}
}