Boolean condition check code refactored
This commit is contained in:
parent
2e23a17257
commit
b4b0c8df2d
|
|
@ -146,7 +146,7 @@ class AddressDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'closure' => function ($row) {
|
'closure' => function ($row) {
|
||||||
if ($row->default_address == 1) {
|
if ($row->default_address) {
|
||||||
return '<span class="badge badge-md badge-success"">' . trans('admin::app.customers.addresses.yes') . '</span>';
|
return '<span class="badge badge-md badge-success"">' . trans('admin::app.customers.addresses.yes') . '</span>';
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.customers.addresses.dash');
|
return trans('admin::app.customers.addresses.dash');
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class AttributeDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->is_required == 1) {
|
if ($value->is_required) {
|
||||||
return trans('admin::app.datagrid.true');
|
return trans('admin::app.datagrid.true');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.false');
|
return trans('admin::app.datagrid.false');
|
||||||
|
|
@ -105,7 +105,7 @@ class AttributeDataGrid extends DataGrid
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->is_unique == 1) {
|
if ($value->is_unique) {
|
||||||
return trans('admin::app.datagrid.true');
|
return trans('admin::app.datagrid.true');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.false');
|
return trans('admin::app.datagrid.false');
|
||||||
|
|
@ -121,7 +121,7 @@ class AttributeDataGrid extends DataGrid
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->value_per_locale == 1) {
|
if ($value->value_per_locale) {
|
||||||
return trans('admin::app.datagrid.true');
|
return trans('admin::app.datagrid.true');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.false');
|
return trans('admin::app.datagrid.false');
|
||||||
|
|
@ -137,7 +137,7 @@ class AttributeDataGrid extends DataGrid
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->value_per_channel == 1) {
|
if ($value->value_per_channel) {
|
||||||
return trans('admin::app.datagrid.true');
|
return trans('admin::app.datagrid.true');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.false');
|
return trans('admin::app.datagrid.false');
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class CampaignDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.active');
|
return trans('admin::app.datagrid.active');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.inactive');
|
return trans('admin::app.datagrid.inactive');
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class CartRuleCouponsDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->end_other_rules == 1) {
|
if ($value->end_other_rules) {
|
||||||
return trans('admin::app.datagrid.true');
|
return trans('admin::app.datagrid.true');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.false');
|
return trans('admin::app.datagrid.false');
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ class CatalogRuleDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.active');
|
return trans('admin::app.datagrid.active');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.inactive');
|
return trans('admin::app.datagrid.inactive');
|
||||||
|
|
|
||||||
|
|
@ -128,7 +128,7 @@ class CategoryDataGrid extends DataGrid
|
||||||
'searchable' => true,
|
'searchable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.active');
|
return trans('admin::app.datagrid.active');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.inactive');
|
return trans('admin::app.datagrid.inactive');
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ class CategoryProductDataGrid extends DataGrid
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.active');
|
return trans('admin::app.datagrid.active');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.inactive');
|
return trans('admin::app.datagrid.inactive');
|
||||||
|
|
|
||||||
|
|
@ -145,13 +145,13 @@ class CustomerDataGrid extends DataGrid
|
||||||
'closure' => function ($row) {
|
'closure' => function ($row) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
if ($row->status == 1) {
|
if ($row->status) {
|
||||||
$html .= '<span class="badge badge-md badge-success">' . trans('admin::app.customers.customers.active') . '</span>';
|
$html .= '<span class="badge badge-md badge-success">' . trans('admin::app.customers.customers.active') . '</span>';
|
||||||
} else {
|
} else {
|
||||||
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.customers.customers.inactive') . '</span>';
|
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.customers.customers.inactive') . '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($row->is_suspended == 1) {
|
if ($row->is_suspended) {
|
||||||
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.customers.customers.suspended') . '</span>';
|
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.customers.customers.suspended') . '</span>';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -86,7 +86,7 @@ class InventorySourcesDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.active');
|
return trans('admin::app.datagrid.active');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.inactive');
|
return trans('admin::app.datagrid.inactive');
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ class NewsLetterDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status === 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.true');
|
return trans('admin::app.datagrid.true');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.false');
|
return trans('admin::app.datagrid.false');
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ class ProductDataGrid extends DataGrid
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
$html = '';
|
$html = '';
|
||||||
|
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
$html .= '<span class="badge badge-md badge-success">' . trans('admin::app.datagrid.active') . '</span>';
|
$html .= '<span class="badge badge-md badge-success">' . trans('admin::app.datagrid.active') . '</span>';
|
||||||
} else {
|
} else {
|
||||||
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.datagrid.inactive') . '</span>';
|
$html .= '<span class="badge badge-md badge-danger">' . trans('admin::app.datagrid.inactive') . '</span>';
|
||||||
|
|
|
||||||
|
|
@ -81,7 +81,7 @@ class UserDataGrid extends DataGrid
|
||||||
'sortable' => true,
|
'sortable' => true,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return trans('admin::app.datagrid.active');
|
return trans('admin::app.datagrid.active');
|
||||||
} else {
|
} else {
|
||||||
return trans('admin::app.datagrid.inactive');
|
return trans('admin::app.datagrid.inactive');
|
||||||
|
|
|
||||||
|
|
@ -138,7 +138,7 @@ class AddressController extends Controller
|
||||||
|
|
||||||
session()->flash('success', trans('admin::app.customers.addresses.success-update'));
|
session()->flash('success', trans('admin::app.customers.addresses.success-update'));
|
||||||
|
|
||||||
return redirect()->route('admin.customer.addresses.index', ['id' => $address->customer_id]);
|
return redirect()->route('admin.customer.addresses.index', ['id' => $customerAddress->customer_id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -577,10 +577,6 @@ class Booking
|
||||||
*/
|
*/
|
||||||
public function isCartItemInactive(\Webkul\Checkout\Contracts\CartItem $item): bool
|
public function isCartItemInactive(\Webkul\Checkout\Contracts\CartItem $item): bool
|
||||||
{
|
{
|
||||||
if ($item->product->status === 0) {
|
return ! $item->product->status;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -278,7 +278,7 @@ class Cart
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$item->product
|
$item->product
|
||||||
&& $item->product->status === 0
|
&& ! $item->product->status
|
||||||
) {
|
) {
|
||||||
throw new Exception(__('shop::app.checkout.cart.item.inactive'));
|
throw new Exception(__('shop::app.checkout.cart.item.inactive'));
|
||||||
}
|
}
|
||||||
|
|
@ -330,7 +330,7 @@ class Cart
|
||||||
if ($cartItem = $cart->items()->find($itemId)) {
|
if ($cartItem = $cart->items()->find($itemId)) {
|
||||||
$cartItem->delete();
|
$cartItem->delete();
|
||||||
|
|
||||||
if ($cart->items()->get()->count() == 0) {
|
if (! $cart->items()->get()->count()) {
|
||||||
$this->removeCart($cart);
|
$this->removeCart($cart);
|
||||||
} else {
|
} else {
|
||||||
Shipping::collectRates();
|
Shipping::collectRates();
|
||||||
|
|
@ -383,7 +383,7 @@ class Cart
|
||||||
if ($this->isCartItemInactive($item)) {
|
if ($this->isCartItemInactive($item)) {
|
||||||
$this->cartItemRepository->delete($item->id);
|
$this->cartItemRepository->delete($item->id);
|
||||||
|
|
||||||
if ($cart->items->count() == 0) {
|
if (! $cart->items->count()) {
|
||||||
$this->removeCart($cart);
|
$this->removeCart($cart);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -621,7 +621,7 @@ class Cart
|
||||||
|
|
||||||
$cartItems = $cart->items()->get();
|
$cartItems = $cart->items()->get();
|
||||||
|
|
||||||
if (count($cartItems) === 0) {
|
if (! count($cartItems)) {
|
||||||
$this->removeCart($cart);
|
$this->removeCart($cart);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ class Cart extends Model implements CartContract
|
||||||
public function hasGuestCheckoutItems(): bool
|
public function hasGuestCheckoutItems(): bool
|
||||||
{
|
{
|
||||||
foreach ($this->items as $item) {
|
foreach ($this->items as $item) {
|
||||||
if ($item->product->getAttribute('guest_checkout') === 0) {
|
if (! $item->product->getAttribute('guest_checkout')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -917,7 +917,7 @@ class Core
|
||||||
*/
|
*/
|
||||||
public function isCountryRequired()
|
public function isCountryRequired()
|
||||||
{
|
{
|
||||||
return $this->getConfigData('customer.address.requirements.country') == 1;
|
return (bool) $this->getConfigData('customer.address.requirements.country');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -927,7 +927,7 @@ class Core
|
||||||
*/
|
*/
|
||||||
public function isStateRequired()
|
public function isStateRequired()
|
||||||
{
|
{
|
||||||
return $this->getConfigData('customer.address.requirements.state') == 1;
|
return (bool) $this->getConfigData('customer.address.requirements.state');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -937,7 +937,7 @@ class Core
|
||||||
*/
|
*/
|
||||||
public function isPostCodeRequired()
|
public function isPostCodeRequired()
|
||||||
{
|
{
|
||||||
return $this->getConfigData('customer.address.requirements.postcode') == 1;
|
return (bool) $this->getConfigData('customer.address.requirements.postcode');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ class SessionController extends Controller
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth()->guard('customer')->user()->status == 0) {
|
if (! auth()->guard('customer')->user()->status) {
|
||||||
auth()->guard('customer')->logout();
|
auth()->guard('customer')->logout();
|
||||||
|
|
||||||
session()->flash('warning', trans('shop::app.customer.login-form.not-activated'));
|
session()->flash('warning', trans('shop::app.customer.login-form.not-activated'));
|
||||||
|
|
@ -61,7 +61,7 @@ class SessionController extends Controller
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth()->guard('customer')->user()->is_verified == 0) {
|
if (! auth()->guard('customer')->user()->is_verified) {
|
||||||
session()->flash('info', trans('shop::app.customer.login-form.verify-first'));
|
session()->flash('info', trans('shop::app.customer.login-form.verify-first'));
|
||||||
|
|
||||||
Cookie::queue(Cookie::make('enable-resend', 'true', 1));
|
Cookie::queue(Cookie::make('enable-resend', 'true', 1));
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class RedirectIfNotCustomer
|
||||||
if (! Auth::guard($guard)->check()) {
|
if (! Auth::guard($guard)->check()) {
|
||||||
return redirect()->route('customer.session.index');
|
return redirect()->route('customer.session.index');
|
||||||
} else {
|
} else {
|
||||||
if (Auth::guard($guard)->user()->status == 0) {
|
if (! Auth::guard($guard)->user()->status) {
|
||||||
Auth::guard($guard)->logout();
|
Auth::guard($guard)->logout();
|
||||||
|
|
||||||
session()->flash('warning', trans('shop::app.customer.login-form.not-activated'));
|
session()->flash('warning', trans('shop::app.customer.login-form.not-activated'));
|
||||||
|
|
|
||||||
|
|
@ -1024,14 +1024,14 @@ abstract class AbstractType
|
||||||
*/
|
*/
|
||||||
public function isCartItemInactive(\Webkul\Checkout\Contracts\CartItem $item): bool
|
public function isCartItemInactive(\Webkul\Checkout\Contracts\CartItem $item): bool
|
||||||
{
|
{
|
||||||
if ($item->product->status === 0) {
|
if (! $item->product->status) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch ($item->product->type) {
|
switch ($item->product->type) {
|
||||||
case 'bundle':
|
case 'bundle':
|
||||||
foreach ($item->children as $child) {
|
foreach ($item->children as $child) {
|
||||||
if ($child->product->status === 0) {
|
if (! $child->product->status) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1040,7 +1040,7 @@ abstract class AbstractType
|
||||||
case 'configurable':
|
case 'configurable':
|
||||||
if (
|
if (
|
||||||
$item->child
|
$item->child
|
||||||
&& $item->child->product->status === 0
|
&& ! $item->child->product->status
|
||||||
) {
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class Validator
|
||||||
|
|
||||||
$totalConditionCount++;
|
$totalConditionCount++;
|
||||||
|
|
||||||
if ($rule->condition_type == 1) {
|
if ($rule->condition_type) {
|
||||||
if (! $this->validateObject($condition, $entity)) {
|
if (! $this->validateObject($condition, $entity)) {
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ class SubscriptionController extends Controller
|
||||||
if (isset($subscriber)) {
|
if (isset($subscriber)) {
|
||||||
if (
|
if (
|
||||||
$subscriber->count() > 0
|
$subscriber->count() > 0
|
||||||
&& $subscriber->is_subscribed == 1
|
&& $subscriber->is_subscribed
|
||||||
&& $subscriber->update(['is_subscribed' => 0])
|
&& $subscriber->update(['is_subscribed' => 0])
|
||||||
) {
|
) {
|
||||||
session()->flash('info', trans('shop::app.subscription.unsubscribed'));
|
session()->flash('info', trans('shop::app.subscription.unsubscribed'));
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ class SessionController extends Controller
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auth()->guard('admin')->user()->status == 0) {
|
if (! auth()->guard('admin')->user()->status) {
|
||||||
session()->flash('warning', trans('admin::app.users.users.activate-warning'));
|
session()->flash('warning', trans('admin::app.users.users.activate-warning'));
|
||||||
|
|
||||||
auth()->guard('admin')->logout();
|
auth()->guard('admin')->logout();
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@ class UserController extends Controller
|
||||||
*/
|
*/
|
||||||
$data['status'] = isset($data['status']);
|
$data['status'] = isset($data['status']);
|
||||||
|
|
||||||
$isStatusChangedToInactive = (int) $data['status'] === 0 && (int) $user->status === 1;
|
$isStatusChangedToInactive = ! $data['status'] && (bool) $user->status;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
$isStatusChangedToInactive
|
$isStatusChangedToInactive
|
||||||
|
|
|
||||||
|
|
@ -84,7 +84,7 @@ class ContentDataGrid extends DataGrid
|
||||||
'searchable' => false,
|
'searchable' => false,
|
||||||
'filterable' => true,
|
'filterable' => true,
|
||||||
'closure' => function ($value) {
|
'closure' => function ($value) {
|
||||||
if ($value->status == 1) {
|
if ($value->status) {
|
||||||
return 'Active';
|
return 'Active';
|
||||||
} else {
|
} else {
|
||||||
return 'Inactive';
|
return 'Inactive';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue