Skip to content

Commit

Permalink
[FIX] include disabled models #1120
Browse files Browse the repository at this point in the history
  • Loading branch information
SamBrishes committed May 2, 2024
1 parent 91f8a60 commit 4dce009
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
10 changes: 8 additions & 2 deletions models/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,14 @@ class Cart extends Model
'products' => [CartProduct::class, 'deleted' => true],
];
public $belongsTo = [
'shipping_method' => ShippingMethod::class,
'payment_method' => PaymentMethod::class,
'shipping_method' => [
ShippingMethod::class,
'scope' => 'all'
],
'payment_method' => [
PaymentMethod::class,
'scope' => 'all'
],
'shipping_address' => [Address::class, 'localKey' => 'shipping_address_id', 'deleted' => true],
'billing_address' => [Address::class, 'localKey' => 'billing_address_id', 'deleted' => true],
'customer' => [Customer::class, 'deleted' => true],
Expand Down
18 changes: 15 additions & 3 deletions models/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,21 @@ class Order extends Model
'payment_logs' => [PaymentLog::class, 'order' => 'created_at DESC'],
];
public $belongsTo = [
'payment_method' => [PaymentMethod::class, 'deleted' => true],
'customer_payment_method' => [CustomerPaymentMethod::class, 'deleted' => true],
'order_state' => [OrderState::class, 'deleted' => true],
'payment_method' => [
PaymentMethod::class,
'deleted' => true,
'scope' => 'all'
],
'customer_payment_method' => [
CustomerPaymentMethod::class,
'deleted' => true,
'scope' => 'all'
],
'order_state' => [
OrderState::class,
'deleted' => true,
'scope' => 'all'
],
'customer' => [Customer::class, 'deleted' => true],
'cart' => [Cart::class, 'deleted' => true],
];
Expand Down
16 changes: 15 additions & 1 deletion models/OrderState.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace OFFLINE\Mall\Models;

use Illuminate\Database\Eloquent\Builder;
use Lang;
use Model;
use October\Rain\Database\Traits\SoftDelete;
Expand Down Expand Up @@ -118,7 +119,6 @@ class OrderState extends Model

/**
* Return the available translated orderState flag options.
*
* @return array
*/
public function getFlagOptions(): array
Expand All @@ -128,6 +128,20 @@ public function getFlagOptions(): array
}, static::$availableFlagOptions);
}

/**
* Include all payment methods, even disabled ones.
* @param Builder $query
* @return void
*/
public function scopeAll(Builder $query)
{
return $query->withDisabled();
}

/**
* Undocumented function
* @return void
*/
public function beforeDelete()
{
if (!empty($this->flag)) {
Expand Down
11 changes: 11 additions & 0 deletions models/PaymentMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DB;
use Model;
use Cms\Classes\Theme;
use Illuminate\Database\Eloquent\Builder;
use October\Rain\Database\Traits\Nullable;
use October\Rain\Database\Traits\Sluggable;
use October\Rain\Database\Traits\SoftDelete;
Expand Down Expand Up @@ -201,6 +202,16 @@ static public function getDefault(): ?self
return $default;
}

/**
* Include all payment methods, even disabled ones.
* @param Builder $query
* @return void
*/
public function scopeAll(Builder $query)
{
return $query->withDisabled();
}

/**
* Hook after model has been deleted.
* @return void
Expand Down
11 changes: 11 additions & 0 deletions models/ShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use DB;
use Event;
use Model;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Session;
use October\Rain\Database\Collection;
use October\Rain\Database\Traits\Sortable;
Expand Down Expand Up @@ -280,6 +281,16 @@ static public function getAvailability($countryId, $total, $cart = null, $wishli
return $availableShippingMethods;
}

/**
* Include all shipping methods, even disabled ones.
* @param Builder $query
* @return void
*/
public function scopeAll(Builder $query)
{
return $query->withDisabled();
}

/**
* JSON serialize class.
* @return array
Expand Down

0 comments on commit 4dce009

Please sign in to comment.