Want To Change Category Url

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

Want To Change Category Url

Post by awaidqureshi » 14 Jan 2020, 14:36

Default category url is http://......com/catgegoryname~categoryid

want to change it to only category name means
http://......com/catgegoryname

Please guide how can i do that

Thanks

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Want To Change Category Url

Post by aimeos » 14 Jan 2020, 15:02

That will be difficult because the category name must be unique then and this is only rarely the case. Furthermore, things get more complicated if category names should translated into several languages.

For products, we've added a resolve() method to the product frontend controller that is used in the HTML client and which finds the product by its name:
https://github.com/aimeos/ai-controller ... #L294-L310
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

awaidqureshi
Posts: 86
Joined: 12 Jan 2019, 15:17

Re: Want To Change Category Url

Post by awaidqureshi » 20 Jan 2020, 10:18

aimeos wrote: 14 Jan 2020, 15:02 That will be difficult because the category name must be unique then and this is only rarely the case. Furthermore, things get more complicated if category names should translated into several languages.

For products, we've added a resolve() method to the product frontend controller that is used in the HTML client and which finds the product by its name:
https://github.com/aimeos/ai-controller ... #L294-L310
Can i replace this "~" with forward slash if yes then where i have to do the changes

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Want To Change Category Url

Post by aimeos » 21 Jan 2020, 09:49

Only if you change the product detail routes too because they already use a "/" for separating name and id and/or pos. Otherwise, the Laravel router won't be able to distingish which route to use.

You can add a prefix like /category_name/c/123 to make routes unique.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

ttyy
Posts: 10
Joined: 02 Apr 2021, 16:31

Re: Want To Change Category Url

Post by ttyy » 09 Apr 2021, 13:19

Is is possible to create a custom route for instance /mytestpage/{f_catid} for category view? If so how I would disable required f_name param?

I've tried a similar approach, created a router but w/o f_name i'm getting an error handling the request

Error --
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameter for [Route: aimeos_shop_tree] [URI: shop/{f_name}~{f_catid}] [Missing parameter: f_name].
URL: http://localhost:8000/category/2
Route: Route::get('category/{f_catid}/{f_name?}', '\Aimeos\Shop\Controller\CatalogController@treeAction');
Also same results with route: 'category/{f_catid}'

User avatar
aimeos
Administrator
Posts: 7836
Joined: 01 Jan 1970, 00:00

Re: Want To Change Category Url

Post by aimeos » 11 Apr 2021, 12:08

You can overwrite existing Laravel routes by their name in ./routes/web.php, e.g.:

Code: Select all

Route::match( array( 'GET', 'POST' ), 'mytestpage/{f_catid}', array(
	'as' => 'aimeos_shop_tree',
	'uses' => 'Aimeos\Shop\Controller\CatalogController@treeAction'
) )->where( ['site' => '[a-z0-9\.\-]+' );
Because the f_name parameter is added when the URL is generated in the template, it will be part of the URL as

Code: Select all

/mytestpage/123?f_name=test
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

ttyy
Posts: 10
Joined: 02 Apr 2021, 16:31

Re: Want To Change Category Url

Post by ttyy » 14 Apr 2021, 11:47

Thanks, adding name for the route did the trick!

Post Reply