diff --git a/src/Docs/Shop/Controllers/Controller.php b/src/Docs/Shop/Controllers/Controller.php index 2136768..bb7497f 100755 --- a/src/Docs/Shop/Controllers/Controller.php +++ b/src/Docs/Shop/Controllers/Controller.php @@ -67,6 +67,10 @@ * description="API Endpoints of Order" * ) * @OA\Tag( + * name="ReOrder", + * description="API Endpoints of Re Order" + * ) + * @OA\Tag( * name="Invoices", * description="API Endpoints of Invoice" * ) diff --git a/src/Docs/Shop/Controllers/Customer/OrderController.php b/src/Docs/Shop/Controllers/Customer/OrderController.php index d336c56..6650a5b 100755 --- a/src/Docs/Shop/Controllers/Customer/OrderController.php +++ b/src/Docs/Shop/Controllers/Customer/OrderController.php @@ -181,4 +181,69 @@ public function get() public function cancel() { } + + /** + * @OA\Get( + * path="/api/v1/customer/orders/reorder/{id}", + * operationId="ReOrder", + * tags={"ReOrder"}, + * summary="Customer Re Order", + * description="This endpoint adds order items to the customer's cart for reordering. After successfully adding items to the cart, the customer should proceed with the checkout process via the checkout APIs.", + * security={ {"sanctum": {} }}, + * + * @OA\Parameter( + * name="id", + * description="Order id", + * required=true, + * in="path", + * @OA\Schema( + * type="integer" + * ) + * ), + * + * @OA\Response( + * response=200, + * description="Successful operation", + * @OA\JsonContent( + * @OA\Property( + * property="message", + * type="string", + * example="Order canceled successfully." + * ) + * ) + * ), + * + * @OA\Response( + * response=404, + * description="Something went wrong!", + * @OA\JsonContent( + * @OA\Property( + * property="title", + * type="string", + * example="404 Page Not Found" + * ), + * @OA\Property( + * property="message", + * type="string", + * example="Oops! The page you're looking for is on vacation. It seems we couldn't find what you were searching for." + * ) + * ) + * ), + * + * @OA\Response( + * response=405, + * description="Method not allowed", + * @OA\JsonContent( + * @OA\Property( + * property="message", + * type="string", + * example="Order can not be reordered" + * ) + * ) + * ), + * ) + */ + public function reorder() + { + } } diff --git a/src/Http/Controllers/V1/Shop/Customer/OrderController.php b/src/Http/Controllers/V1/Shop/Customer/OrderController.php index 337a295..7af8349 100755 --- a/src/Http/Controllers/V1/Shop/Customer/OrderController.php +++ b/src/Http/Controllers/V1/Shop/Customer/OrderController.php @@ -5,6 +5,8 @@ use Illuminate\Http\Request; use Webkul\RestApi\Http\Resources\V1\Shop\Sales\OrderResource; use Webkul\Sales\Repositories\OrderRepository; +use Webkul\Checkout\Facades\Cart; +use Webkul\RestApi\Http\Resources\V1\Shop\Checkout\CartResource; class OrderController extends CustomerController { @@ -41,4 +43,35 @@ public function cancel(Request $request, int $id): \Illuminate\Http\Response 'message' => trans('rest-api::app.shop.sales.orders.error.cancel-error'), ]); } + + /** + * Reorder the specified resource. + */ + public function reorder(Request $request, int $id): \Illuminate\Http\Response + { + $order = $this->resolveShopUser($request)->orders()->findOrFail($id); + + if ( + ! $order->canReorder() + || ! core()->getConfigData('sales.order_settings.reorder.shop') + ) { + return response([ + 'message' => trans('rest-api::app.shop.sales.orders.error.reorder-error'), + ], 405); + } + + foreach ($order->items as $item) { + try { + $cart = Cart::addProduct($item->product, $item->additional); + } catch (\Exception $e) { + return response([ + 'message' => trans('rest-api::app.shop.sales.orders.error.reorder-error'), + ], 405); + } + } + + return response([ + 'data' => new CartResource($cart), + ]); + } } diff --git a/src/Resources/lang/ar/app.php b/src/Resources/lang/ar/app.php index b833f64..1c1810b 100644 --- a/src/Resources/lang/ar/app.php +++ b/src/Resources/lang/ar/app.php @@ -503,7 +503,8 @@ 'cancel' => 'تم إلغاء الطلب بنجاح.', 'error' => [ - 'cancel-error' => 'لا يمكن إلغاء الطلب.', + 'cancel-error' => 'لا يمكن إلغاء الطلب.', + 'reorder-error' => 'لا يمكن إعادة الطلب.', ], ], ], diff --git a/src/Resources/lang/bn/app.php b/src/Resources/lang/bn/app.php index 1cb1975..421d49c 100644 --- a/src/Resources/lang/bn/app.php +++ b/src/Resources/lang/bn/app.php @@ -503,7 +503,8 @@ 'cancel' => 'অর্ডার সফলভাবে বাতিল করা হয়েছে।', 'error' => [ - 'cancel-error' => 'অর্ডার বাতিল করা যাবে না।', + 'cancel-error' => 'অর্ডার বাতিল করা সম্ভব নয়।', + 'reorder-error' => 'অর্ডার পুনরায় করা সম্ভব নয়।', ], ], ], diff --git a/src/Resources/lang/de/app.php b/src/Resources/lang/de/app.php index 7fc7a54..6e131f2 100755 --- a/src/Resources/lang/de/app.php +++ b/src/Resources/lang/de/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Bestellung erfolgreich storniert.', 'error' => [ - 'cancel-error' => 'Bestellung kann nicht storniert werden.', + 'cancel-error' => 'Bestellung kann nicht storniert werden.', + 'reorder-error' => 'Bestellung kann nicht nachbestellt werden.', ], ], ], diff --git a/src/Resources/lang/en/app.php b/src/Resources/lang/en/app.php index 26ce590..3645299 100755 --- a/src/Resources/lang/en/app.php +++ b/src/Resources/lang/en/app.php @@ -504,7 +504,8 @@ 'cancel' => 'Order canceled successfully.', 'error' => [ - 'cancel-error' => 'Order can not be canceled.', + 'cancel-error' => 'Order can not be canceled.', + 'reorder-error' => 'Order can not be reordered.', ], ], ], diff --git a/src/Resources/lang/es/app.php b/src/Resources/lang/es/app.php index 6deecb8..eabbb46 100644 --- a/src/Resources/lang/es/app.php +++ b/src/Resources/lang/es/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Pedido cancelado correctamente.', 'error' => [ - 'cancel-error' => 'No se puede cancelar el pedido.', + 'cancel-error' => 'No se puede cancelar el pedido.', + 'reorder-error' => 'El pedido no puede ser reordenado.', ], ], ], diff --git a/src/Resources/lang/fa/app.php b/src/Resources/lang/fa/app.php index e0269c2..de5e437 100644 --- a/src/Resources/lang/fa/app.php +++ b/src/Resources/lang/fa/app.php @@ -503,7 +503,8 @@ 'cancel' => 'سفارش با موفقیت لغو شد.', 'error' => [ - 'cancel-error' => 'امکان لغو سفارش وجود ندارد.', + 'cancel-error' => 'امکان لغو سفارش وجود ندارد.', + 'reorder-error' => 'سفارش قابل تجدید نیست.', ], ], ], diff --git a/src/Resources/lang/fr/app.php b/src/Resources/lang/fr/app.php index 857a005..2c82e4f 100755 --- a/src/Resources/lang/fr/app.php +++ b/src/Resources/lang/fr/app.php @@ -502,7 +502,8 @@ 'cancel' => 'Commande annulée avec succès.', 'error' => [ - 'cancel-error' => 'La commande ne peut pas être annulée.', + 'cancel-error' => 'La commande ne peut pas être annulée.', + 'reorder-error' => 'La commande ne peut pas être réorganisée.', ], ], ], diff --git a/src/Resources/lang/he/app.php b/src/Resources/lang/he/app.php index 281395a..761caaf 100644 --- a/src/Resources/lang/he/app.php +++ b/src/Resources/lang/he/app.php @@ -503,7 +503,8 @@ 'cancel' => 'ההזמנה בוטלה בהצלחה.', 'error' => [ - 'cancel-error' => 'לא ניתן לבטל את ההזמנה.', + 'cancel-error' => 'לא ניתן לבטל את ההזמנה.', + 'reorder-error' => 'לא ניתן להזמין מחדש.', ], ], ], diff --git a/src/Resources/lang/hi_IN/app.php b/src/Resources/lang/hi_IN/app.php index 428405d..c63b0dc 100644 --- a/src/Resources/lang/hi_IN/app.php +++ b/src/Resources/lang/hi_IN/app.php @@ -503,7 +503,8 @@ 'cancel' => 'आदेश सफलतापूर्वक रद्द किया गया।', 'error' => [ - 'cancel-error' => 'आदेश को रद्द नहीं किया जा सकता है।', + 'cancel-error' => 'ऑर्डर रद्द नहीं किया जा सकता।', + 'reorder-error' => 'ऑर्डर दोबारा नहीं किया जा सकता।', ], ], ], diff --git a/src/Resources/lang/it/app.php b/src/Resources/lang/it/app.php index 10e7f8f..5471c27 100644 --- a/src/Resources/lang/it/app.php +++ b/src/Resources/lang/it/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Ordine annullato con successo.', 'error' => [ - 'cancel-error' => 'L\'ordine non può essere annullato.', + 'cancel-error' => 'L\'ordine non può essere annullato.', + 'reorder-error' => 'L\'ordine non può essere riordinato.', ], ], ], diff --git a/src/Resources/lang/ja/app.php b/src/Resources/lang/ja/app.php index e4ee44a..cceeb6f 100644 --- a/src/Resources/lang/ja/app.php +++ b/src/Resources/lang/ja/app.php @@ -503,7 +503,8 @@ 'cancel' => '注文が正常にキャンセルされました。', 'error' => [ - 'cancel-error' => '注文をキャンセルできません。', + 'cancel-error' => '注文をキャンセルできません。', + 'reorder-error' => '注文を再注文できません。', ], ], ], diff --git a/src/Resources/lang/nl/app.php b/src/Resources/lang/nl/app.php index 0c8afa2..188489f 100644 --- a/src/Resources/lang/nl/app.php +++ b/src/Resources/lang/nl/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Bestelling succesvol geannuleerd.', 'error' => [ - 'cancel-error' => 'Bestelling kan niet worden geannuleerd.', + 'cancel-error' => 'Bestelling kan niet worden geannuleerd.', + 'reorder-error' => 'Bestelling kan niet opnieuw besteld worden.', ], ], ], diff --git a/src/Resources/lang/pl/app.php b/src/Resources/lang/pl/app.php index e6690f2..2ce65b8 100644 --- a/src/Resources/lang/pl/app.php +++ b/src/Resources/lang/pl/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Zamówienie zostało pomyślnie anulowane.', 'error' => [ - 'cancel-error' => 'Zamówienie nie może być anulowane.', + 'cancel-error' => 'Zamówienie nie może być anulowane.', + 'reorder-error' => 'Zamówienie nie może zostać ponownie złożone.', ], ], ], diff --git a/src/Resources/lang/pt_BR/app.php b/src/Resources/lang/pt_BR/app.php index 0065fbf..85986f5 100755 --- a/src/Resources/lang/pt_BR/app.php +++ b/src/Resources/lang/pt_BR/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Pedido cancelado com sucesso.', 'error' => [ - 'cancel-error' => 'Pedido não pode ser cancelado.', + 'cancel-error' => 'Pedido não pode ser cancelado.', + 'reorder-error' => 'O pedido não pode ser reordenado.', ], ], ], diff --git a/src/Resources/lang/ru/app.php b/src/Resources/lang/ru/app.php index 7942d53..667ccdf 100644 --- a/src/Resources/lang/ru/app.php +++ b/src/Resources/lang/ru/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Заказ успешно отменен.', 'error' => [ - 'cancel-error' => 'Заказ не может быть отменен.', + 'cancel-error' => 'Заказ не может быть отменен.', + 'reorder-error' => 'Заказ не может быть повторён.', ], ], ], diff --git a/src/Resources/lang/sin/app.php b/src/Resources/lang/sin/app.php index 0a92864..4195d38 100644 --- a/src/Resources/lang/sin/app.php +++ b/src/Resources/lang/sin/app.php @@ -503,7 +503,8 @@ 'cancel' => 'ඇණවුම සාර්ථකව අවලංගු කරන ලදි.', 'error' => [ - 'cancel-error' => 'ඇණවුම අවලංගු කළ නොහැක.', + 'cancel-error' => 'ඇණවුම අවලංගු කළ නොහැක.', + 'reorder-error' => 'ඇනවුම නැවත ලබා ගත නොහැක.', ], ], ], diff --git a/src/Resources/lang/tr/app.php b/src/Resources/lang/tr/app.php index 579bd9b..39d74cd 100644 --- a/src/Resources/lang/tr/app.php +++ b/src/Resources/lang/tr/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Sipariş başarıyla iptal edildi.', 'error' => [ - 'cancel-error' => 'Sipariş iptal edilemiyor.', + 'cancel-error' => 'Sipariş iptal edilemiyor.', + 'reorder-error' => 'Sipariş tekrar verilemez.', ], ], ], diff --git a/src/Resources/lang/uk/app.php b/src/Resources/lang/uk/app.php index ff52f3b..09356ae 100644 --- a/src/Resources/lang/uk/app.php +++ b/src/Resources/lang/uk/app.php @@ -503,7 +503,8 @@ 'cancel' => 'Замовлення скасовано успішно.', 'error' => [ - 'cancel-error' => 'Замовлення не може бути скасоване.', + 'cancel-error' => 'Замовлення не може бути скасоване.', + 'reorder-error' => 'Замовлення не може бути повторно здійснене.', ], ], ], diff --git a/src/Resources/lang/zh_CN/app.php b/src/Resources/lang/zh_CN/app.php index d9c8e4e..abf60f1 100644 --- a/src/Resources/lang/zh_CN/app.php +++ b/src/Resources/lang/zh_CN/app.php @@ -503,7 +503,8 @@ 'cancel' => '订单取消成功。', 'error' => [ - 'cancel-error' => '订单无法取消。', + 'cancel-error' => '订单无法取消。', + 'reorder-error' => 'Замовлення не може бути повторно здійснене.', ], ], ], diff --git a/src/Routes/V1/Shop/customers-routes.php b/src/Routes/V1/Shop/customers-routes.php index 33bdd7c..c2fedc5 100755 --- a/src/Routes/V1/Shop/customers-routes.php +++ b/src/Routes/V1/Shop/customers-routes.php @@ -62,6 +62,8 @@ Route::get('{id}', 'getResource'); Route::post('{id}/cancel', 'cancel'); + + Route::get('reorder/{id}', 'reorder'); }); /**