Skip to content

Commit

Permalink
Merge branch 'main' into docs/update-contribution-guide
Browse files Browse the repository at this point in the history
  • Loading branch information
sushmangupta authored Dec 18, 2024
2 parents 77564ac + 7318e06 commit 1edadb1
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions guides/hosting/configurations/framework/routes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
nav:
title: Custom routes
position: 10

---

# Custom routes

## Overview

Your default routes in Shopware 6 are defined in the controllers of the core or your plugins. An example could be the wishlist route:

```php
<?php declare(strict_types=1);

#[Route(path: '/wishlist', name: 'frontend.wishlist.page', options: ['seo' => false], defaults: ['_noStore' => true], methods: ['GET'])]
public function index(Request $request, SalesChannelContext $context): Response
{
$customer = $context->getCustomer();

if ($customer !== null && $customer->getGuest() === false) {
$page = $this->wishlistPageLoader->load($request, $context, $customer);
$this->hook(new WishlistPageLoadedHook($page, $context));
} else {
$page = $this->guestPageLoader->load($request, $context);
$this->hook(new GuestWishlistPageLoadedHook($page, $context));
}

return $this->renderStorefront('@Storefront/storefront/page/wishlist/index.html.twig', ['page' => $page]);
}
```

It defines that your wishlist page is available at `/wishlist`. This is fine for an English-only shop, but for a multilingual shop, you might want to have a different route for each language.

For example, you could have `/wishlist` for English and `/merkliste` for German.

## Configuration

To easily configure those routes, you can use the `routes.yaml` file in ROOT/config/routes/routes.yaml. Symfony loads this file, which allows you to define your custom `paths`, in our case, for the wishlist index page.

```yaml
frontend.wishlist.page:
path:
en-GB: '/wishlist'
de-DE: '/merkliste'
controller: 'Shopware\Storefront\Controller\WishlistController::index'
methods: ['GET']
defaults:
_noStore: true
_routeScope: ['storefront']
options:
seo: false
```
You can configure the `path` with the **locales** (for example, `de-DE`) your shop uses.

If you want to learn more about routes in Symfony, check out the [Symfony documentation](https://symfony.com/doc/current/routing.html#creating-routes-as-attributes).

0 comments on commit 1edadb1

Please sign in to comment.