2022-03-09 10:39:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Sarga\API\Http\Controllers;
|
|
|
|
|
|
2022-03-10 07:59:50 +00:00
|
|
|
use Sarga\API\Http\Resources\Customer\OrderResource;
|
2022-03-20 12:54:55 +00:00
|
|
|
use Sarga\Shop\Repositories\OrderItemRepository;
|
|
|
|
|
use Sarga\Shop\Repositories\OrderRepository;
|
2022-03-09 10:39:22 +00:00
|
|
|
use Webkul\RestApi\Http\Controllers\V1\Shop\Customer\OrderController;
|
2022-03-10 07:59:50 +00:00
|
|
|
|
2022-03-09 10:39:22 +00:00
|
|
|
|
|
|
|
|
class Orders extends OrderController
|
|
|
|
|
{
|
2022-04-23 12:17:55 +00:00
|
|
|
protected $requestException = ['page', 'limit', 'pagination', 'sort', 'order', 'token','locale'];
|
2022-04-15 10:24:28 +00:00
|
|
|
public function __construct(protected OrderRepository $orderRepository,
|
|
|
|
|
protected OrderItemRepository $orderItemRepository)
|
2022-03-20 12:54:55 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-09 10:39:22 +00:00
|
|
|
/**
|
|
|
|
|
* Resource class name.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function resource()
|
|
|
|
|
{
|
|
|
|
|
return OrderResource::class;
|
|
|
|
|
}
|
2022-03-14 10:38:15 +00:00
|
|
|
|
2022-03-20 12:54:55 +00:00
|
|
|
public function cancelItem($order_id,$item_id){
|
|
|
|
|
$order = request()->user()->all_orders()->findOrFail($order_id);
|
|
|
|
|
|
|
|
|
|
$orderItem = $this->orderItemRepository->with('order')
|
|
|
|
|
->findOrFail($item_id);
|
|
|
|
|
|
|
|
|
|
if($this->orderItemRepository->cancel($orderItem))
|
|
|
|
|
{
|
|
|
|
|
$order = $this->orderRepository->calculateTotals($order,$orderItem);
|
|
|
|
|
$order = $this->orderRepository->updateOrderStatus($order);
|
2022-03-14 10:38:15 +00:00
|
|
|
|
2022-03-20 12:54:55 +00:00
|
|
|
return response(['data'=>[
|
|
|
|
|
'order' => new OrderResource($order)],
|
2022-04-23 09:23:37 +00:00
|
|
|
'success' => true,
|
|
|
|
|
'message' => trans('admin::app.response.cancel-success', ['name' => 'Order Item'])
|
2022-03-20 12:54:55 +00:00
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return response([
|
|
|
|
|
'success'=>false,
|
|
|
|
|
'message'=>trans('admin::app.response.cancel-error', ['name' => 'Order Item'])
|
|
|
|
|
]);
|
|
|
|
|
}
|
2022-03-14 10:38:15 +00:00
|
|
|
}
|
2022-03-09 10:39:22 +00:00
|
|
|
}
|