Skip to content

Commit

Permalink
Move order & reservation cancel logic to model
Browse files Browse the repository at this point in the history
Signed-off-by: Sam <[email protected]>
  • Loading branch information
sampoyigi committed Mar 16, 2023
1 parent 8bd5d45 commit 4055b01
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions components/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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'));
Expand Down

0 comments on commit 4055b01

Please sign in to comment.