-
-
Notifications
You must be signed in to change notification settings - Fork 32
/
Extension.php
206 lines (179 loc) · 7.08 KB
/
Extension.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
<?php
namespace Igniter\Cart;
use Admin\Models\Orders_model;
use Igniter\Cart\Middleware\CartMiddleware;
use Igniter\Cart\Models\Cart as CartStore;
use Igniter\Cart\Models\CartSettings;
use Igniter\Flame\Cart\Facades\Cart;
use Igniter\Local\Facades\Location;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Event;
use Main\Facades\Auth;
use System\Classes\BaseExtension;
class Extension extends BaseExtension
{
public function register()
{
$this->app->register(\Igniter\Flame\Cart\CartServiceProvider::class);
AliasLoader::getInstance()->alias('Cart', \Igniter\Flame\Cart\Facades\Cart::class);
}
public function boot()
{
if (!$this->app->runningInAdmin()) {
$this->app['router']->pushMiddlewareToGroup('web', CartMiddleware::class);
}
$this->bindCartEvents();
$this->bindCheckoutEvents();
$this->bindOrderStatusEvent();
Orders_model::extend(function ($model) {
$model->implement[] = 'Igniter\Cart\Actions\OrderAction';
});
}
public function registerCartConditions()
{
return [
\Igniter\Cart\CartConditions\PaymentFee::class => [
'name' => 'paymentFee',
'label' => 'lang:igniter.cart::default.text_payment_fee',
'description' => 'lang:igniter.cart::default.help_payment_fee',
],
\Igniter\Cart\CartConditions\Tax::class => [
'name' => 'tax',
'label' => 'lang:igniter.cart::default.text_vat',
'description' => 'lang:igniter.cart::default.help_tax_condition',
],
\Igniter\Cart\CartConditions\Tip::class => [
'name' => 'tip',
'label' => 'lang:igniter.cart::default.text_tip',
'description' => 'lang:igniter.cart::default.help_tip_condition',
],
];
}
public function registerAutomationRules()
{
return [
'events' => [
'admin.order.paymentProcessed' => \Igniter\Cart\AutomationRules\Events\OrderPlaced::class,
'igniter.cart.orderStatusAdded' => \Igniter\Cart\AutomationRules\Events\NewOrderStatus::class,
'igniter.cart.orderAssigned' => \Igniter\Cart\AutomationRules\Events\OrderAssigned::class,
],
'actions' => [],
'conditions' => [
\Igniter\Cart\AutomationRules\Conditions\OrderAttribute::class,
\Igniter\Cart\AutomationRules\Conditions\OrderStatusAttribute::class,
],
];
}
public function registerComponents()
{
return [
\Igniter\Cart\Components\CartBox::class => [
'code' => 'cartBox',
'name' => 'lang:igniter.cart::default.text_component_title',
'description' => 'lang:igniter.cart::default.text_component_desc',
],
\Igniter\Cart\Components\Checkout::class => [
'code' => 'checkout',
'name' => 'lang:igniter.cart::default.text_checkout_component_title',
'description' => 'lang:igniter.cart::default.text_checkout_component_desc',
],
\Igniter\Cart\Components\Orders::class => [
'code' => 'accountOrders',
'name' => 'lang:igniter.cart::default.orders.component_title',
'description' => 'lang:igniter.cart::default.orders.component_desc',
],
\Igniter\Cart\Components\Order::class => [
'code' => 'orderPage',
'name' => 'lang:igniter.cart::default.orders.order_component_title',
'description' => 'lang:igniter.cart::default.orders.order_component_desc',
],
];
}
public function registerPermissions()
{
return [
'Module.CartModule' => [
'description' => 'Manage cart extension settings',
'group' => 'module',
],
];
}
public function registerSettings()
{
return [
'settings' => [
'label' => 'Cart Settings',
'description' => 'Manage cart conditions and tipping settings.',
'icon' => 'fa fa-gear',
'model' => \Igniter\Cart\Models\CartSettings::class,
'permissions' => ['Module.CartModule'],
],
];
}
public function registerMailTemplates()
{
return [
'igniter.cart::mail.order' => 'lang:igniter.cart::default.text_mail_order',
'igniter.cart::mail.order_alert' => 'lang:igniter.cart::default.text_mail_order_alert',
];
}
public function registerActivityTypes()
{
return [
ActivityTypes\OrderCreated::class => 'orderCreated',
];
}
protected function bindCartEvents()
{
Event::listen('cart.beforeRegister', function () {
Config::set('cart.model', CartStore::class);
Config::set('cart.abandonedCart', CartSettings::get('abandoned_cart'));
});
Event::listen('cart.afterRegister', function ($cart, $instance) {
if (Location::current())
$cart->instance('location-'.Location::getId());
});
Event::listen('igniter.user.login', function () {
if (CartSettings::get('abandoned_cart')
&& Cart::content()->isEmpty()
) {
Cart::restore(Auth::getId());
}
});
Event::listen('igniter.user.logout', function () {
if (CartSettings::get('destroy_on_logout'))
Cart::destroy();
});
}
protected function bindCheckoutEvents()
{
Event::listen('admin.order.paymentProcessed', function (Orders_model $model) {
ActivityTypes\OrderCreated::log($model);
$model->mailSend('igniter.cart::mail.order', 'customer');
$model->mailSend('igniter.cart::mail.order_alert', 'location');
$model->mailSend('igniter.cart::mail.order_alert', 'admin');
});
Event::listen('admin.order.beforePaymentProcessed', function (Orders_model $model) {
$model->subtractStock();
});
}
protected function bindOrderStatusEvent()
{
Event::listen('admin.statusHistory.beforeAddStatus', function ($model, $object, $statusId, $previousStatus) {
if (!$object instanceof Orders_model)
return;
Event::fire('igniter.cart.beforeAddOrderStatus', [$model, $object, $statusId, $previousStatus], true);
});
Event::listen('admin.statusHistory.added', function ($model, $statusHistory) {
if (!$model instanceof Orders_model)
return;
Event::fire('igniter.cart.orderStatusAdded', [$model, $statusHistory], true);
});
Event::listen('admin.assignable.assigned', function ($model) {
if (!$model instanceof Orders_model)
return;
Event::fire('igniter.cart.orderAssigned', [$model], true);
});
}
}