diff --git a/packages/Sarga/API/Http/Controllers/CMSController.php b/packages/Sarga/API/Http/Controllers/CMSController.php new file mode 100644 index 000000000..d91565a02 --- /dev/null +++ b/packages/Sarga/API/Http/Controllers/CMSController.php @@ -0,0 +1,40 @@ +categoryRepository->with(['filterableAttributes','brands'])->find($id); + $category = $this->categoryRepository->with(['filterableAttributes','brands','children'])->find($id); if($category) return response([ + 'subcategories' =>$category->children, 'attributes' =>Attribute::collection($category->filterableAttributes), 'brands' => Brand::collection($category->brands), ]); diff --git a/packages/Sarga/API/Http/Controllers/Wishlists.php b/packages/Sarga/API/Http/Controllers/Wishlists.php new file mode 100644 index 000000000..f5fbdb6a0 --- /dev/null +++ b/packages/Sarga/API/Http/Controllers/Wishlists.php @@ -0,0 +1,107 @@ +user(); + + return response([ + 'data' => WishListResource::collection($customer->wishlist_items()->get()), + ]); + } + + /** + * Add or remote item from wishlist. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function addOrRemove(Request $request, $id) + { + $customer = $request->user(); + + $wishlistItem = $this->wishlistRepository->findOneWhere([ + 'channel_id' => core()->getCurrentChannel()->id, + 'product_id' => $id, + 'customer_id' => $customer->id, + ]); + + if ($wishlistItem) { + $this->wishlistRepository->delete($wishlistItem->id); + + return response([ + 'data' => null, + 'message' => 'Item removed from wishlist successfully.', + ]); + } + + $wishlistItem = $this->wishlistRepository->create([ + 'channel_id' => core()->getCurrentChannel()->id, + 'product_id' => $id, + 'customer_id' => $customer->id, + ]); + + return response([ + 'data' => new WishListResource($wishlistItem), + 'message' => __('rest-api::app.common-response.success.add', ['name' => 'Wishlist']), + ]); + } + + /** + * Move product from wishlist to cart. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return \Illuminate\Http\Response + */ + public function moveToCart(Request $request, $id) + { + $customer = $request->user(); + + $wishlistItem = $this->wishlistRepository->findOneWhere([ + 'channel_id' => core()->getCurrentChannel()->id, + 'product_id' => $id, + 'customer_id' => $customer->id, + ]); + + if ($wishlistItem->customer_id != $customer->user()->id) { + return response([ + 'message' => __('rest-api::app.common-response.error.security-warning'), + ], 400); + } + + $result = Cart::moveToCart($wishlistItem); + + if ($result) { + Cart::collectTotals(); + + $cart = Cart::getCart(); + + return response([ + 'data' => $cart ? new CartResource($cart) : null, + 'message' => __('rest-api::app.wishlist.moved'), + ]); + } + + return response([ + 'message' => __('rest-api::app.wishlist.option-missing'), + ], 400); + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Core/CMSResource.php b/packages/Sarga/API/Http/Resources/Core/CMSResource.php new file mode 100644 index 000000000..b8ee537f9 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Core/CMSResource.php @@ -0,0 +1,21 @@ + $this->id, + 'content' => $this->content, + 'page_title' => $this->page_title, + 'html_content' => $this->html_content, + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Customer/WishListResource.php b/packages/Sarga/API/Http/Resources/Customer/WishListResource.php new file mode 100644 index 000000000..9dc6991d1 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Customer/WishListResource.php @@ -0,0 +1,25 @@ + $this->id, + 'product' => new Product($this->product), + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + ]; + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/routes.php b/packages/Sarga/API/Http/routes.php index 3b71b78a4..704240e9d 100644 --- a/packages/Sarga/API/Http/routes.php +++ b/packages/Sarga/API/Http/routes.php @@ -11,6 +11,7 @@ use Sarga\API\Http\Controllers\IntegrationController; use Sarga\API\Http\Controllers\Orders; use Sarga\API\Http\Controllers\Vendors; use Sarga\API\Http\Controllers\Products; +use Sarga\API\Http\Controllers\Wishlists; use Sarga\Shop\Repositories\CategoryRepository; use Webkul\API\Http\Controllers\Shop\ResourceController; use Webkul\Attribute\Repositories\AttributeOptionRepository; @@ -72,11 +73,9 @@ Route::group(['prefix' => 'api'], function () { /** * Customer wishlist routes. */ - Route::get('wishlist', [WishlistController::class, 'index']); - - Route::post('wishlist/{id}', [WishlistController::class, 'addOrRemove']); - - Route::post('wishlist/{id}/move-to-cart', [WishlistController::class, 'moveToCart']); + Route::get('wishlist', [Wishlists::class, 'index']); + Route::post('wishlist/{id}', [Wishlists::class, 'addOrRemove']); + Route::post('wishlist/{id}/move-to-cart', [Wishlists::class, 'moveToCart']); /** * Recipients */ @@ -89,55 +88,35 @@ Route::group(['prefix' => 'api'], function () { * Customer cart routes. */ Route::get('cart', [Carts::class, 'get']); - Route::post('cart/add/{productId}', [Carts::class, 'add']); - Route::put('cart/update', [Carts::class, 'update']); - Route::delete('cart/remove/{cartItemId}', [Carts::class, 'removeItem']); - Route::delete('cart/empty', [Carts::class, 'empty']); - Route::post('cart/move-to-wishlist/{cartItemId}', [Carts::class, 'moveToWishlist']); - Route::post('cart/coupon', [Carts::class, 'applyCoupon']); - Route::delete('cart/coupon', [Carts::class, 'removeCoupon']); /** * Customer checkout routes. */ Route::get('checkout', [Checkout::class, 'index']); - Route::post('checkout/save-shipping', [Checkout::class, 'saveShipping']); - Route::post('checkout/save-payment', [Checkout::class, 'savePayment']); - Route::post('checkout/check-minimum-order', [Checkout::class, 'checkMinimumOrder']); - Route::post('checkout/save-order', [Checkout::class, 'saveOrder']); /** * Customer sale routes. */ Route::get('orders', [Orders::class, 'allResources']); - Route::get('orders/{id}', [Orders::class, 'getResource']); - Route::post('orders/{id}/cancel', [Orders::class, 'cancel']); - Route::post('orders/{id}/cancel/{item_id}', [Orders::class, 'cancelItem']); - Route::get('invoices', [InvoiceController::class, 'allResources']); - Route::get('invoices/{id}', [InvoiceController::class, 'getResource']); - Route::get('shipments', [ShipmentController::class, 'allResources']); - Route::get('shipments/{id}', [ShipmentController::class, 'getResource']); - Route::get('transactions', [TransactionController::class, 'allResources']); - Route::get('transactions/{id}', [TransactionController::class, 'getResource']); }); }); @@ -149,5 +128,4 @@ Route::group(['prefix' => 'api'], function () { Route::put('create',[IntegrationController::class,'create']); }); - });