From 510840bf8bf930f6804a3d9ba1a9f6ee5a076d41 Mon Sep 17 00:00:00 2001 From: Devansh Date: Tue, 26 Oct 2021 12:47:35 +0530 Subject: [PATCH] Improvised Routes --- .../src/Providers/ShopServiceProvider.php | 4 +- .../Shop/src/{Http => Routes}/breadcrumbs.php | 0 .../Shop/src/Routes/checkout-routes.php | 75 +++++++ .../routes.php => Routes/customer-routes.php} | 202 ++---------------- .../Shop/src/Routes/store-front-routes.php | 85 ++++++++ packages/Webkul/Shop/src/Routes/web.php | 18 ++ 6 files changed, 199 insertions(+), 185 deletions(-) rename packages/Webkul/Shop/src/{Http => Routes}/breadcrumbs.php (100%) create mode 100644 packages/Webkul/Shop/src/Routes/checkout-routes.php rename packages/Webkul/Shop/src/{Http/routes.php => Routes/customer-routes.php} (59%) mode change 100755 => 100644 create mode 100644 packages/Webkul/Shop/src/Routes/store-front-routes.php create mode 100644 packages/Webkul/Shop/src/Routes/web.php diff --git a/packages/Webkul/Shop/src/Providers/ShopServiceProvider.php b/packages/Webkul/Shop/src/Providers/ShopServiceProvider.php index 781bdcafc..e31510ec2 100755 --- a/packages/Webkul/Shop/src/Providers/ShopServiceProvider.php +++ b/packages/Webkul/Shop/src/Providers/ShopServiceProvider.php @@ -27,7 +27,7 @@ class ShopServiceProvider extends ServiceProvider ]); /* loaders */ - $this->loadRoutesFrom(__DIR__ . '/../Http/routes.php'); + $this->loadRoutesFrom(__DIR__ . '/../Routes/web.php'); $this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations'); $this->loadTranslationsFrom(__DIR__ . '/../Resources/lang', 'shop'); $this->loadViewsFrom(__DIR__ . '/../Resources/views', 'shop'); @@ -45,7 +45,7 @@ class ShopServiceProvider extends ServiceProvider Paginator::defaultSimpleView('shop::partials.pagination'); /* breadcrumbs */ - require __DIR__ . '/../Http/breadcrumbs.php'; + require __DIR__ . '/../Routes/breadcrumbs.php'; } /** diff --git a/packages/Webkul/Shop/src/Http/breadcrumbs.php b/packages/Webkul/Shop/src/Routes/breadcrumbs.php similarity index 100% rename from packages/Webkul/Shop/src/Http/breadcrumbs.php rename to packages/Webkul/Shop/src/Routes/breadcrumbs.php diff --git a/packages/Webkul/Shop/src/Routes/checkout-routes.php b/packages/Webkul/Shop/src/Routes/checkout-routes.php new file mode 100644 index 000000000..5f7c23da5 --- /dev/null +++ b/packages/Webkul/Shop/src/Routes/checkout-routes.php @@ -0,0 +1,75 @@ + ['web', 'locale', 'theme', 'currency']], function () { + /** + * Country-State selector. + */ + Route::get('get/countries', [CountryStateController::class, 'getCountries'])->defaults('_config', [ + 'view' => 'shop::test' + ])->name('get.countries'); + + /** + * Get States when Country is passed. + */ + Route::get('get/states/{country}', [CountryStateController::class, 'getStates'])->defaults('_config', [ + 'view' => 'shop::test' + ])->name('get.states'); + + /** + * Cart routes. + */ + Route::get('checkout/cart', [CartController::class, 'index'])->defaults('_config', [ + 'view' => 'shop::checkout.cart.index' + ])->name('shop.checkout.cart.index'); + + Route::post('checkout/cart/add/{id}', [CartController::class, 'add'])->defaults('_config', [ + 'redirect' => 'shop.checkout.cart.index' + ])->name('cart.add'); + + Route::get('checkout/cart/remove/{id}', [CartController::class, 'remove'])->name('cart.remove'); + + Route::post('/checkout/cart', [CartController::class, 'updateBeforeCheckout'])->defaults('_config', [ + 'redirect' => 'shop.checkout.cart.index' + ])->name('shop.checkout.cart.update'); + + Route::get('/checkout/cart/remove/{id}', [CartController::class, 'remove'])->defaults('_config', [ + 'redirect' => 'shop.checkout.cart.index' + ])->name('shop.checkout.cart.remove'); + + Route::post('move/wishlist/{id}', [CartController::class, 'moveToWishlist'])->name('shop.movetowishlist'); + + /** + * Coupon routes. + */ + Route::post('checkout/cart/coupon', [CartController::class, 'applyCoupon'])->name('shop.checkout.cart.coupon.apply'); + + Route::delete('checkout/cart/coupon', [CartController::class, 'removeCoupon'])->name('shop.checkout.coupon.remove.coupon'); + + /** + * Checkout routes. + */ + Route::get('/checkout/onepage', [OnepageController::class, 'index'])->defaults('_config', [ + 'view' => 'shop::checkout.onepage' + ])->name('shop.checkout.onepage.index'); + + Route::get('/checkout/summary', [OnepageController::class, 'summary'])->name('shop.checkout.summary'); + + Route::post('/checkout/save-address', [OnepageController::class, 'saveAddress'])->name('shop.checkout.save-address'); + + Route::post('/checkout/save-shipping', [OnepageController::class, 'saveShipping'])->name('shop.checkout.save-shipping'); + + Route::post('/checkout/save-payment', [OnepageController::class, 'savePayment'])->name('shop.checkout.save-payment'); + + Route::post('/checkout/check-minimum-order', [OnepageController::class, 'checkMinimumOrder'])->name('shop.checkout.check-minimum-order'); + + Route::post('/checkout/save-order', [OnepageController::class, 'saveOrder'])->name('shop.checkout.save-order'); + + Route::get('/checkout/success', [OnepageController::class, 'success'])->defaults('_config', [ + 'view' => 'shop::checkout.success' + ])->name('shop.checkout.success'); +}); diff --git a/packages/Webkul/Shop/src/Http/routes.php b/packages/Webkul/Shop/src/Routes/customer-routes.php old mode 100755 new mode 100644 similarity index 59% rename from packages/Webkul/Shop/src/Http/routes.php rename to packages/Webkul/Shop/src/Routes/customer-routes.php index 0a9aeb5cd..096e3259f --- a/packages/Webkul/Shop/src/Http/routes.php +++ b/packages/Webkul/Shop/src/Routes/customer-routes.php @@ -1,8 +1,6 @@ ['web', 'locale', 'theme', 'currency']], function () { - /** - * Store front home. - */ - Route::get('/', [HomeController::class, 'index'])->defaults('_config', [ - 'view' => 'shop::home.index' - ])->name('shop.home.index'); - - /** - * Store front search. - */ - Route::get('/search', [SearchController::class, 'index'])->defaults('_config', [ - 'view' => 'shop::search.search' - ])->name('shop.search.index'); - - Route::post('/upload-search-image', [HomeController::class, 'upload'])->name('shop.image.search.upload'); - - /** - * Subscription. - */ - Route::get('/subscribe', [SubscriptionController::class, 'subscribe'])->name('shop.subscribe'); - - Route::get('/unsubscribe/{token}', [SubscriptionController::class, 'unsubscribe'])->name('shop.unsubscribe'); - - /** - * Country-State selector. - */ - Route::get('get/countries', [CountryStateController::class, 'getCountries'])->defaults('_config', [ - 'view' => 'shop::test' - ])->name('get.countries'); - - /** - * Get States when Country is passed. - */ - Route::get('get/states/{country}', [CountryStateController::class, 'getStates'])->defaults('_config', [ - 'view' => 'shop::test' - ])->name('get.states'); - - /** - * Cart, coupons and checkout. - */ - // Cart items listing. - Route::get('checkout/cart', [CartController::class, 'index'])->defaults('_config', [ - 'view' => 'shop::checkout.cart.index' - ])->name('shop.checkout.cart.index'); - - // Add cart items. - Route::post('checkout/cart/add/{id}', [CartController::class, 'add'])->defaults('_config', [ - 'redirect' => 'shop.checkout.cart.index' - ])->name('cart.add'); - - // Cart items remove. - Route::get('checkout/cart/remove/{id}', [CartController::class, 'remove'])->name('cart.remove'); - - // Cart update before checkout. - Route::post('/checkout/cart', [CartController::class, 'updateBeforeCheckout'])->defaults('_config', [ - 'redirect' => 'shop.checkout.cart.index' - ])->name('shop.checkout.cart.update'); - - // Cart items remove. - Route::get('/checkout/cart/remove/{id}', [CartController::class, 'remove'])->defaults('_config', [ - 'redirect' => 'shop.checkout.cart.index' - ])->name('shop.checkout.cart.remove'); - - // Move item to wishlist from cart. - Route::post('move/wishlist/{id}', [CartController::class, 'moveToWishlist'])->name('shop.movetowishlist'); - - // Apply coupons. - Route::post('checkout/cart/coupon', [CartController::class, 'applyCoupon'])->name('shop.checkout.cart.coupon.apply'); - - // Remove coupons. - Route::delete('checkout/cart/coupon', [CartController::class, 'removeCoupon'])->name('shop.checkout.coupon.remove.coupon'); - - // Checkout index page. - Route::get('/checkout/onepage', [OnepageController::class, 'index'])->defaults('_config', [ - 'view' => 'shop::checkout.onepage' - ])->name('shop.checkout.onepage.index'); - - // Checkout get summary. - Route::get('/checkout/summary',[OnepageController::class, 'summary'])->name('shop.checkout.summary'); - - // Checkout save address form. - Route::post('/checkout/save-address', [OnepageController::class, 'saveAddress'])->name('shop.checkout.save-address'); - - // Checkout save shipping address form. - Route::post('/checkout/save-shipping', [OnepageController::class, 'saveShipping'])->name('shop.checkout.save-shipping'); - - // Checkout save payment method form. - Route::post('/checkout/save-payment', [OnepageController::class, 'savePayment'])->name('shop.checkout.save-payment'); - - // Check minimum order. - Route::post('/checkout/check-minimum-order', [OnepageController::class, 'checkMinimumOrder'])->name('shop.checkout.check-minimum-order'); - - // Checkout save order. - Route::post('/checkout/save-order', [OnepageController::class, 'saveOrder'])->name('shop.checkout.save-order'); - - // Checkout order successful. - Route::get('/checkout/success', [OnepageController::class, 'success'])->defaults('_config', [ - 'view' => 'shop::checkout.success' - ])->name('shop.checkout.success'); - - /** - * Product reviews. - */ - // Show product review form. - Route::get('/reviews/{slug}', [ReviewController::class, 'show'])->defaults('_config', [ - 'view' => 'shop::products.reviews.index' - ])->name('shop.reviews.index'); - - // Show product review listing. - Route::get('/product/{slug}/review', [ReviewController::class, 'create'])->defaults('_config', [ - 'view' => 'shop::products.reviews.create' - ])->name('shop.reviews.create'); - - // Store product review. - Route::post('/product/{slug}/review', [ReviewController::class, 'store'])->defaults('_config', [ - 'redirect' => 'shop.home.index' - ])->name('shop.reviews.store'); - - /** - * Downloadable products. - */ - Route::get('/downloadable/download-sample/{type}/{id}', [ProductController::class, 'downloadSample'])->name('shop.downloadable.download_sample'); - - Route::get('/product/{id}/{attribute_id}', [ProductController::class, 'download'])->defaults('_config', [ - 'view' => 'shop.products.index' - ])->name('shop.product.file.download'); - - /** - * Product related attributes. - */ - Route::get('products/get-filter-attributes/{categoryId}', [ProductController::class, 'getFilterAttributes'])->name('admin.catalog.products.get-filter-attributes'); - - Route::get('products/get-category-product-maximum-price/{categoryId}', [ProductController::class, 'getCategoryProductMaximumPrice'])->name('admin.catalog.products.get-category-product-maximum-price'); - - /** - * These are the routes which are used during checkout for checking the customer. - * So, placed outside the cart merger middleware. - */ - Route::prefix('customer')->group(function () { - // For customer exist check. - Route::post('/customer/exist', [OnepageController::class, 'checkExistCustomer'])->name('customer.checkout.exist'); - - // For customer login checkout. - Route::post('/customer/checkout/login', [OnepageController::class, 'loginForCheckout'])->name('customer.checkout.login'); - }); - /** * Cart merger middleware. This middleware will take care of the items * which are deactivated at the time of buy now functionality. If somehow @@ -178,40 +23,31 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function * group. */ Route::group(['middleware' => ['cart.merger']], function () { - /** - * Customer routes. - */ Route::prefix('customer')->group(function () { /** * Forgot password routes. */ - // Show forgot password form. Route::get('/forgot-password', [ForgotPasswordController::class, 'create'])->defaults('_config', [ 'view' => 'shop::customers.signup.forgot-password' ])->name('customer.forgot-password.create'); - // Store forgot password. Route::post('/forgot-password', [ForgotPasswordController::class, 'store'])->name('customer.forgot-password.store'); - // Reset password form. Route::get('/reset-password/{token}', [ResetPasswordController::class, 'create'])->defaults('_config', [ 'view' => 'shop::customers.signup.reset-password' ])->name('customer.reset-password.create'); - // Store reset password. - Route::post('/reset-password',[ResetPasswordController::class, 'store'])->defaults('_config', [ + Route::post('/reset-password', [ResetPasswordController::class, 'store'])->defaults('_config', [ 'redirect' => 'customer.profile.index' ])->name('customer.reset-password.store'); /** * Login routes. */ - // Login form. Route::get('login', [SessionController::class, 'show'])->defaults('_config', [ 'view' => 'shop::customers.session.index', ])->name('customer.session.index'); - // Login. Route::post('login', [SessionController::class, 'create'])->defaults('_config', [ 'redirect' => 'customer.profile.index' ])->name('customer.session.create'); @@ -219,24 +55,23 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function /** * Registration routes. */ - // Show registration form. Route::get('register', [RegistrationController::class, 'show'])->defaults('_config', [ 'view' => 'shop::customers.signup.index' ])->name('customer.register.index'); - // Store new registered user. Route::post('register', [RegistrationController::class, 'create'])->defaults('_config', [ 'redirect' => 'customer.session.index', ])->name('customer.register.create'); - // Verify account. + /** + * Customer verification routes. + */ Route::get('/verify-account/{token}', [RegistrationController::class, 'verifyAccount'])->name('customer.verify'); - // Resend verification email. Route::get('/resend/verification/{email}', [RegistrationController::class, 'resendVerificationEmail'])->name('customer.resend.verification-email'); /** - * Customer authented routes. All the below routes only be accessible + * Customer authenticated routes. All the below routes only be accessible * if customer is authenticated. */ Route::group(['middleware' => ['customer']], function () { @@ -369,20 +204,21 @@ Route::group(['middleware' => ['web', 'locale', 'theme', 'currency']], function }); }); }); + }); + + /** + * These are the routes which are used during checkout for checking the customer. + * So, placed outside the cart merger middleware. + */ + Route::prefix('customer')->group(function () { + /** + * For customer exist check. + */ + Route::post('/customer/exist', [OnepageController::class, 'checkExistCustomer'])->name('customer.checkout.exist'); /** - * CMS pages. + * For customer login checkout. */ - Route::get('page/{slug}', [PagePresenterController::class, 'presenter'])->name('shop.cms.page'); - - /** - * Fallback route. - */ - Route::fallback(\Webkul\Shop\Http\Controllers\ProductsCategoriesProxyController::class . '@index') - ->defaults('_config', [ - 'product_view' => 'shop::products.view', - 'category_view' => 'shop::products.index' - ]) - ->name('shop.productOrCategory.index'); + Route::post('/customer/checkout/login', [OnepageController::class, 'loginForCheckout'])->name('customer.checkout.login'); }); }); diff --git a/packages/Webkul/Shop/src/Routes/store-front-routes.php b/packages/Webkul/Shop/src/Routes/store-front-routes.php new file mode 100644 index 000000000..7e6e93172 --- /dev/null +++ b/packages/Webkul/Shop/src/Routes/store-front-routes.php @@ -0,0 +1,85 @@ + ['web', 'locale', 'theme', 'currency']], function () { + /** + * Cart merger middleware. This middleware will take care of the items + * which are deactivated at the time of buy now functionality. If somehow + * user redirects without completing the checkout then this will merge + * full cart. + * + * If some routes are not able to merge the cart, then place the route in this + * group. + */ + Route::group(['middleware' => ['cart.merger']], function () { + /** + * CMS pages. + */ + Route::get('page/{slug}', [PagePresenterController::class, 'presenter'])->name('shop.cms.page'); + + /** + * Fallback route. + */ + Route::fallback(\Webkul\Shop\Http\Controllers\ProductsCategoriesProxyController::class . '@index') + ->defaults('_config', [ + 'product_view' => 'shop::products.view', + 'category_view' => 'shop::products.index' + ]) + ->name('shop.productOrCategory.index'); + }); + + /** + * Store front home. + */ + Route::get('/', [HomeController::class, 'index'])->defaults('_config', [ + 'view' => 'shop::home.index' + ])->name('shop.home.index'); + + /** + * Store front search. + */ + Route::get('/search', [SearchController::class, 'index'])->defaults('_config', [ + 'view' => 'shop::search.search' + ])->name('shop.search.index'); + + Route::post('/upload-search-image', [HomeController::class, 'upload'])->name('shop.image.search.upload'); + + /** + * Subscription routes. + */ + Route::get('/subscribe', [SubscriptionController::class, 'subscribe'])->name('shop.subscribe'); + + Route::get('/unsubscribe/{token}', [SubscriptionController::class, 'unsubscribe'])->name('shop.unsubscribe'); + + /** + * Product and categories routes. + */ + Route::get('/reviews/{slug}', [ReviewController::class, 'show'])->defaults('_config', [ + 'view' => 'shop::products.reviews.index' + ])->name('shop.reviews.index'); + + Route::get('/product/{slug}/review', [ReviewController::class, 'create'])->defaults('_config', [ + 'view' => 'shop::products.reviews.create' + ])->name('shop.reviews.create'); + + Route::post('/product/{slug}/review', [ReviewController::class, 'store'])->defaults('_config', [ + 'redirect' => 'shop.home.index' + ])->name('shop.reviews.store'); + + Route::get('/downloadable/download-sample/{type}/{id}', [ProductController::class, 'downloadSample'])->name('shop.downloadable.download_sample'); + + Route::get('/product/{id}/{attribute_id}', [ProductController::class, 'download'])->defaults('_config', [ + 'view' => 'shop.products.index' + ])->name('shop.product.file.download'); + + Route::get('products/get-filter-attributes/{categoryId}', [ProductController::class, 'getFilterAttributes'])->name('admin.catalog.products.get-filter-attributes'); + + Route::get('products/get-category-product-maximum-price/{categoryId}', [ProductController::class, 'getCategoryProductMaximumPrice'])->name('admin.catalog.products.get-category-product-maximum-price'); +}); diff --git a/packages/Webkul/Shop/src/Routes/web.php b/packages/Webkul/Shop/src/Routes/web.php new file mode 100644 index 000000000..7cfbe07b2 --- /dev/null +++ b/packages/Webkul/Shop/src/Routes/web.php @@ -0,0 +1,18 @@ +