Skip to content

Commit a625cdf

Browse files
committed
Code refactor
Signed-off-by: Sam Poyigi <[email protected]>
1 parent 02e0f0e commit a625cdf

File tree

2 files changed

+31
-39
lines changed

2 files changed

+31
-39
lines changed

src/Extension.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,17 @@ public function boot()
7878
$this->defineRoutes();
7979
$this->configureRateLimiting();
8080

81-
Event::listen('igniter.user.register', function (Customer $customer, array $data) {
81+
Event::listen('igniter.user.register', function(Customer $customer, array $data) {
8282
Notifications\CustomerRegisteredNotification::make()->subject($customer)->broadcast();
8383
});
8484

8585
$this->registerAdminUserPanel();
8686

87-
Location::extend(function ($model) {
87+
Location::extend(function($model) {
8888
$model->relation['morphedByMany']['users'] = [User::class, 'name' => 'locationable'];
8989
});
9090

91-
Template::registerHook('endBody', function () {
91+
Template::registerHook('endBody', function() {
9292
return view('igniter.user::_partials.impersonate_banner');
9393
});
9494
}
@@ -135,7 +135,7 @@ public function registerNavigation(): array
135135
'system' => [
136136
'child' => [
137137
'users' => [
138-
'priority' => 0,
138+
'priority' => 1,
139139
'class' => 'users',
140140
'href' => admin_url('users'),
141141
'title' => lang('igniter.user::default.text_side_menu_user'),
@@ -148,7 +148,7 @@ public function registerNavigation(): array
148148

149149
public function registerSystemSettings()
150150
{
151-
Settings::registerCallback(function (Settings $manager) {
151+
Settings::registerCallback(function(Settings $manager) {
152152
$manager->registerSettingItems('core', [
153153
'user' => [
154154
'label' => 'lang:igniter.user::default.text_tab_user',
@@ -211,7 +211,7 @@ public function registerFormWidgets(): array
211211
protected function registerEventGlobalParams()
212212
{
213213
if (class_exists(\Igniter\Automation\Classes\EventManager::class)) {
214-
resolve(\Igniter\Automation\Classes\EventManager::class)->registerCallback(function ($manager) {
214+
resolve(\Igniter\Automation\Classes\EventManager::class)->registerCallback(function($manager) {
215215
$manager->registerGlobalParams([
216216
'customer' => Auth::customer(),
217217
]);
@@ -221,8 +221,8 @@ protected function registerEventGlobalParams()
221221

222222
protected function registerRequestRebindHandler()
223223
{
224-
$this->app->rebinding('request', function ($app, $request) {
225-
$request->setUserResolver(function () use ($app) {
224+
$this->app->rebinding('request', function($app, $request) {
225+
$request->setUserResolver(function() use ($app) {
226226
if (!Igniter::runningInAdmin()) {
227227
return $app['admin.auth']->getUser();
228228
}
@@ -234,7 +234,7 @@ protected function registerRequestRebindHandler()
234234

235235
protected function configureRateLimiting()
236236
{
237-
RateLimiter::for('web', function (\Illuminate\Http\Request $request) {
237+
RateLimiter::for('web', function(\Illuminate\Http\Request $request) {
238238
return Limit::perMinute(60)->by(optional($request->user())->getKey() ?: $request->ip());
239239
});
240240

@@ -245,7 +245,7 @@ protected function configureRateLimiting()
245245
$this->app->make(\Illuminate\Contracts\Http\Kernel::class)
246246
->appendMiddlewareToGroup('web', \Igniter\User\Http\Middleware\ThrottleRequests::class);
247247

248-
Event::listen('igniter.user.beforeThrottleRequest', function ($request, $params) {
248+
Event::listen('igniter.user.beforeThrottleRequest', function($request, $params) {
249249
$handler = str_after($request->header('x-igniter-request-handler'), '::');
250250
if (in_array($handler, [
251251
'onLogin',
@@ -264,18 +264,18 @@ protected function configureRateLimiting()
264264

265265
protected function registerBladeDirectives()
266266
{
267-
$this->callAfterResolving('blade.compiler', function ($compiler, $app) {
267+
$this->callAfterResolving('blade.compiler', function($compiler, $app) {
268268
(new BladeExtension())->register();
269269
});
270270
}
271271

272272
protected function registerGuards(): void
273273
{
274-
$this->app->singleton('main.auth', function () {
274+
$this->app->singleton('main.auth', function() {
275275
return resolve('auth')->guard(config('igniter-auth.guards.web', 'web'));
276276
});
277277

278-
$this->app->singleton('admin.auth', function () {
278+
$this->app->singleton('admin.auth', function() {
279279
return resolve('auth')->guard(config('igniter-auth.guards.admin', 'web'));
280280
});
281281
}
@@ -286,7 +286,7 @@ protected function registerAdminUserPanel()
286286
return;
287287
}
288288

289-
AdminMenu::registerCallback(function (Navigation $manager) {
289+
AdminMenu::registerCallback(function(Navigation $manager) {
290290
$manager->registerMainItems([
291291
MainMenuItem::widget('notifications', \Igniter\User\MainMenuWidgets\NotificationList::class)
292292
->priority(15)
@@ -320,7 +320,7 @@ protected function defineRoutes()
320320
return;
321321
}
322322

323-
Route::group([], function ($router) {
323+
Route::group([], function($router) {
324324
(new Classes\RouteRegistrar($router))->all();
325325
});
326326
}

src/Models/Customer.php

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public function getCustomerName()
130130

131131
public function listAddresses()
132132
{
133-
return $this->addresses()->get()->groupBy(function ($address) {
133+
return $this->addresses()->get()->groupBy(function($address) {
134134
return $address->getKey();
135135
});
136136
}
@@ -228,32 +228,24 @@ public function deleteCustomerAddress(string|int $addressId)
228228
*/
229229
public function saveCustomerGuestOrder()
230230
{
231-
$query = false;
232-
233-
if (is_numeric($this->customer_id) && !empty($this->email)) {
234-
$customer_id = $this->customer_id;
235-
$customer_email = $this->email;
236-
$update = ['customer_id' => $customer_id];
237-
238-
Order::where('email', $customer_email)->update($update);
239-
if ($orders = Order::where('email', $customer_email)->get()) {
240-
foreach ($orders as $row) {
241-
if (empty($row['order_id'])) {
242-
continue;
243-
}
244-
245-
if ($row['order_type'] == '1' && !empty($row['address_id'])) {
246-
Address::where('address_id', $row['address_id'])->update($update);
247-
}
248-
}
249-
}
231+
$update = ['customer_id' => $this->customer_id];
250232

251-
Reservation::where('email', $customer_email)->update($update);
233+
Reservation::where('email', $this->email)
234+
->whereNull('customer_id')
235+
->orWhere('customer_id', 0)
236+
->update($update);
252237

253-
$query = true;
254-
}
238+
Order::where('email', $this->email)
239+
->whereNull('customer_id')
240+
->orWhere('customer_id', 0)
241+
->update($update);
242+
243+
Address::whereIn('address_id', Order::where('email', $this->email)
244+
->whereNotNull('address_id')
245+
->pluck('address_id')->all()
246+
)->update($update);
255247

256-
return $query;
248+
return true;
257249
}
258250

259251
protected function sendInviteGetTemplateCode(): string

0 commit comments

Comments
 (0)