From 4055b01f656f265028f45223bae09b5813e92c2c Mon Sep 17 00:00:00 2001 From: Sam <6567634+sampoyigi@users.noreply.github.com> Date: Thu, 16 Mar 2023 14:53:08 +0000 Subject: [PATCH] Move order & reservation cancel logic to model Signed-off-by: Sam <6567634+sampoyigi@users.noreply.github.com> --- components/Order.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/components/Order.php b/components/Order.php index c8e0602..5c50e75 100644 --- a/components/Order.php +++ b/components/Order.php @@ -3,7 +3,6 @@ namespace Igniter\Cart\Components; use Admin\Models\Orders_model; -use Admin\Models\Statuses_model; use Exception; use Igniter\Cart\Classes\CartManager; use Igniter\Cart\Classes\OrderManager; @@ -94,16 +93,10 @@ public function showCancelButton($order = null) if (is_null($order) && !$order = $this->getOrder()) return false; - if ($order->hasStatus(setting('canceled_order_status'))) + if ($order->isCanceled()) return false; - if (!$timeout = $order->location->getOrderCancellationTimeout($order->order_type)) - return false; - - if (!$order->order_datetime->isFuture()) - return false; - - return $order->order_datetime->diffInRealMinutes() > $timeout; + return $order->isCancelable(); } public function onRun() @@ -162,7 +155,7 @@ public function onCancel() if (!$this->showCancelButton($order)) throw new ApplicationException(lang('igniter.cart::default.orders.alert_cancel_failed')); - if (!$order->addStatusHistory(Statuses_model::find(setting('canceled_order_status')))) + if (!$order->markAsCanceled()) throw new ApplicationException(lang('igniter.cart::default.orders.alert_cancel_failed')); flash()->success(lang('igniter.cart::default.orders.alert_cancel_success'));