This repository has been archived by the owner on Apr 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPlugin.php
229 lines (216 loc) · 7.33 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
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
188
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
226
227
228
229
<?php namespace Bedard\Shop;
use Backend;
use RainLab\User\Models\User;
use System\Classes\PluginBase;
/**
* Shop Plugin Information File.
*/
class Plugin extends PluginBase
{
/**
* @var array Plugin dependencies
*/
public $require = [
'RainLab.User',
];
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'bedard.shop::lang.plugin.name',
'description' => 'bedard.shop::lang.plugin.description',
'author' => 'Bedard',
'icon' => 'icon-shopping-cart',
];
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
$this->extendRainLabUser();
}
/**
* Extend RainLab.User plugin.
*
* @return void
*/
protected function extendRainLabUser()
{
User::extend(function ($model) {
$model->belongsToMany['addresses'] = [
'Bedard\Shop\Models\Address',
'table' => 'bedard_shop_address_user',
];
});
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
$this->registerConsoleCommand('shop.abandon', 'Bedard\Shop\Console\Abandon');
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return []; // Remove this line to activate
return [
'Bedard\Shop\Components\MyComponent' => 'myComponent',
];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
public function registerNavigation()
{
return [
'shop' => [
'icon' => 'icon-shopping-cart',
'label' => 'bedard.shop::lang.plugin.name',
'order' => 500,
'permissions' => ['bedard.shop.*'],
'url' => Backend::url('bedard/shop/carts'),
'sideMenu' => [
'carts' => [
'icon' => 'icon-shopping-cart',
'label' => 'bedard.shop::lang.carts.plural',
'permissions' => ['bedard.shop.carts.*'],
'url' => Backend::url('bedard/shop/carts'),
],
'statuses' => [
'icon' => 'icon-tags',
'label' => 'bedard.shop::lang.statuses.plural',
'permissions' => ['bedard.shop.statuses.*'],
'url' => Backend::url('bedard/shop/statuses'),
],
'products' => [
'icon' => 'icon-cubes',
'label' => 'bedard.shop::lang.products.plural',
'permissions' => ['bedard.shop.products.*'],
'url' => Backend::url('bedard/shop/products'),
],
'categories' => [
'icon' => 'icon-folder-o',
'label' => 'bedard.shop::lang.categories.plural',
'permissions' => ['bedard.shop.categories.*'],
'url' => Backend::url('bedard/shop/categories'),
],
'settings' => [
'icon' => 'icon-cog',
'label' => 'bedard.shop::lang.settings.plural',
'permissions' => ['bedard.shop.settings.*'],
'url' => Backend::url('system/settings/update/bedard/shop/general'),
],
],
],
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return [
'bedard.shop.carts.manage' => [
'label' => 'bedard.shop::lang.plugin.permissions.carts',
'tab' => 'bedard.shop::lang.plugin.name',
],
'bedard.shop.categories.manage' => [
'label' => 'bedard.shop::lang.plugin.permissions.categories',
'tab' => 'bedard.shop::lang.plugin.name',
],
'bedard.shop.products.manage' => [
'label' => 'bedard.shop::lang.plugin.permissions.products',
'tab' => 'bedard.shop::lang.plugin.name',
],
'bedard.shop.settings.manage' => [
'label' => 'bedard.shop::lang.plugin.permissions.settings',
'tab' => 'bedard.shop::lang.plugin.name',
],
'bedard.shop.statuses.manage' => [
'label' => 'bedard.shop::lang.plugin.permissions.statuses',
'tab' => 'bedard.shop::lang.plugin.name',
],
];
}
/**
* Register scheduled tasks.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
public function registerSchedule($schedule)
{
$schedule->command('shop:abandon')->everyTenMinutes();
}
/**
* Register settings models.
*
* @return array
*/
public function registerSettings()
{
return [
'general' => [
'category' => 'bedard.shop::lang.plugin.name',
'class' => 'Bedard\Shop\Models\Settings',
'description' => 'bedard.shop::lang.settings.title',
'icon' => 'icon-cog',
'label' => 'bedard.shop::lang.settings.label',
'order' => 100,
'permissions' => ['bedard.shop.settings.manage'],
],
'api' => [
'category' => 'bedard.shop::lang.plugin.name',
'class' => 'Bedard\Shop\Models\ApiSettings',
'description' => 'bedard.shop::lang.api.title',
'icon' => 'icon-code',
'label' => 'bedard.shop::lang.api.label',
'order' => 200,
'permissions' => ['bedard.shop.settings.manage'],
],
'payment' => [
'category' => 'bedard.shop::lang.plugin.name',
'class' => 'Bedard\Shop\Models\PaymentDrivers',
'description' => 'bedard.shop::lang.payment.title',
'icon' => 'icon-money',
'label' => 'bedard.shop::lang.payment.label',
'order' => 300,
'permissions' => ['bedard.shop.settings.manage'],
],
];
}
/**
* Register drivers.
*
* @return array
*/
public function registerShopDrivers()
{
return [
'nopayment' => [
'class' => 'Bedard\Shop\Drivers\NoPayment',
'name' => 'bedard.shop::lang.drivers.nopayment.name',
'thumbnail' => null,
'type' => 'payment',
],
];
}
}