Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement #359 done. #381

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Docs/Shop/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
* )
Expand Down
65 changes: 65 additions & 0 deletions src/Docs/Shop/Controllers/Customer/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
}
33 changes: 33 additions & 0 deletions src/Http/Controllers/V1/Shop/Customer/OrderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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),
]);
}
}
3 changes: 2 additions & 1 deletion src/Resources/lang/ar/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'تم إلغاء الطلب بنجاح.',

'error' => [
'cancel-error' => 'لا يمكن إلغاء الطلب.',
'cancel-error' => 'لا يمكن إلغاء الطلب.',
'reorder-error' => 'لا يمكن إعادة الطلب.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/bn/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'অর্ডার সফলভাবে বাতিল করা হয়েছে।',

'error' => [
'cancel-error' => 'অর্ডার বাতিল করা যাবে না।',
'cancel-error' => 'অর্ডার বাতিল করা সম্ভব নয়।',
'reorder-error' => 'অর্ডার পুনরায় করা সম্ভব নয়।',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/de/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/es/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/fa/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'سفارش با موفقیت لغو شد.',

'error' => [
'cancel-error' => 'امکان لغو سفارش وجود ندارد.',
'cancel-error' => 'امکان لغو سفارش وجود ندارد.',
'reorder-error' => 'سفارش قابل تجدید نیست.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/fr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/he/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'ההזמנה בוטלה בהצלחה.',

'error' => [
'cancel-error' => 'לא ניתן לבטל את ההזמנה.',
'cancel-error' => 'לא ניתן לבטל את ההזמנה.',
'reorder-error' => 'לא ניתן להזמין מחדש.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/hi_IN/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'आदेश सफलतापूर्वक रद्द किया गया।',

'error' => [
'cancel-error' => 'आदेश को रद्द नहीं किया जा सकता है।',
'cancel-error' => 'ऑर्डर रद्द नहीं किया जा सकता।',
'reorder-error' => 'ऑर्डर दोबारा नहीं किया जा सकता।',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/it/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/ja/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => '注文が正常にキャンセルされました。',

'error' => [
'cancel-error' => '注文をキャンセルできません。',
'cancel-error' => '注文をキャンセルできません。',
'reorder-error' => '注文を再注文できません。',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/nl/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/pl/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/pt_BR/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/ru/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'Заказ успешно отменен.',

'error' => [
'cancel-error' => 'Заказ не может быть отменен.',
'cancel-error' => 'Заказ не может быть отменен.',
'reorder-error' => 'Заказ не может быть повторён.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/sin/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'ඇණවුම සාර්ථකව අවලංගු කරන ලදි.',

'error' => [
'cancel-error' => 'ඇණවුම අවලංගු කළ නොහැක.',
'cancel-error' => 'ඇණවුම අවලංගු කළ නොහැක.',
'reorder-error' => 'ඇනවුම නැවත ලබා ගත නොහැක.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/tr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/uk/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => 'Замовлення скасовано успішно.',

'error' => [
'cancel-error' => 'Замовлення не може бути скасоване.',
'cancel-error' => 'Замовлення не може бути скасоване.',
'reorder-error' => 'Замовлення не може бути повторно здійснене.',
],
],
],
Expand Down
3 changes: 2 additions & 1 deletion src/Resources/lang/zh_CN/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,8 @@
'cancel' => '订单取消成功。',

'error' => [
'cancel-error' => '订单无法取消。',
'cancel-error' => '订单无法取消。',
'reorder-error' => 'Замовлення не може бути повторно здійснене.',
],
],
],
Expand Down
2 changes: 2 additions & 0 deletions src/Routes/V1/Shop/customers-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
Route::get('{id}', 'getResource');

Route::post('{id}/cancel', 'cancel');

Route::get('reorder/{id}', 'reorder');
});

/**
Expand Down