first upload all files
This commit is contained in:
39
Modules/Order/Http/Controllers/Admin/OrderController.php
Normal file
39
Modules/Order/Http/Controllers/Admin/OrderController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Admin\Traits\HasCrudActions;
|
||||
|
||||
class OrderController
|
||||
{
|
||||
use HasCrudActions;
|
||||
|
||||
/**
|
||||
* Model for the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Order::class;
|
||||
|
||||
/**
|
||||
* The relations to eager load on every query.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = ['products', 'coupon', 'taxes'];
|
||||
|
||||
/**
|
||||
* Label of the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $label = 'order::orders.order';
|
||||
|
||||
/**
|
||||
* View path of the resource.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $viewPath = 'order::admin.orders';
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Checkout\Mail\Invoice;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
|
||||
class OrderEmailController
|
||||
{
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $order
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Order $order)
|
||||
{
|
||||
Mail::to($order->customer_email)
|
||||
->send(new Invoice($order));
|
||||
|
||||
return back()->with('success', trans('order::messages.invoice_sent'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
|
||||
class OrderPrintController
|
||||
{
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $order
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(Order $order)
|
||||
{
|
||||
$order->load('products', 'coupon', 'taxes');
|
||||
|
||||
return view('order::admin.orders.print.show', compact('order'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Order\Entities\OrderProduct;
|
||||
use Modules\Order\Events\OrderStatusChanged;
|
||||
|
||||
class OrderStatusController
|
||||
{
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Order $order)
|
||||
{
|
||||
$this->adjustStock($order);
|
||||
|
||||
$order->update(['status' => request('status')]);
|
||||
|
||||
$message = trans('order::messages.status_updated');
|
||||
|
||||
event(new OrderStatusChanged($order));
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
private function adjustStock(Order $order)
|
||||
{
|
||||
if ($this->canceledOrRefunded(request('status'))) {
|
||||
$this->restoreStock($order);
|
||||
}
|
||||
|
||||
if ($this->canceledOrRefunded($order->status)) {
|
||||
$this->reduceStock($order);
|
||||
}
|
||||
}
|
||||
|
||||
private function canceledOrRefunded($status)
|
||||
{
|
||||
return in_array($status, [Order::CANCELED, Order::REFUNDED]);
|
||||
}
|
||||
|
||||
private function restoreStock(Order $order)
|
||||
{
|
||||
$order->products->each(function (OrderProduct $orderProduct) {
|
||||
if ($orderProduct->product->manage_stock) {
|
||||
$orderProduct->product->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty > 0) {
|
||||
$orderProduct->product->markAsInStock();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private function reduceStock(Order $order)
|
||||
{
|
||||
$order->products->each(function (OrderProduct $orderProduct) {
|
||||
if (
|
||||
$orderProduct->product->manage_stock
|
||||
&& $orderProduct->product->qty !== 0
|
||||
) {
|
||||
$orderProduct->product->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty === 0) {
|
||||
$orderProduct->product->markAsOutOfStock();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user