Change url sanitize behavior
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Change url sanitize behavior
Hi!
The default language of my Aimeos shop is Persian.
The product URLs must look like this: which can be achieved by setting the URL segment in the basic tab of products' edit page. If I enter this URL in the browser's address bar it works fine.
But the issue is, on the list page, the URL is converted to:
Seems like the sanazite method converts non-Latin characters to Latin ones in the `url()` helper of the view .
How can I change the helper's behavior to make sure the Persian characters remain untouched?
The default language of my Aimeos shop is Persian.
The product URLs must look like this:
Code: Select all
shop/default/کت-مشکی/0
But the issue is, on the list page, the URL is converted to:
Code: Select all
/shop/default/kt-mshky/0
How can I change the helper's behavior to make sure the Persian characters remain untouched?
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Change url sanitize behavior
You can overwrite the Str::slug() method with your own code:
https://github.com/aimeos/aimeos-core/b ... #L188-L196
Just add upfront:
https://github.com/aimeos/aimeos-core/b ... #L188-L196
Just add upfront:
Code: Select all
\Aimeos\MW\Str::method( 'slug', function( $str, string $lang = 'en', string $sep = '-' ) {
// your own code
} );
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Change url sanitize behavior
That works! Thanks a lot
So where should I actually add this code?
Is adding a new common decorator on the client side the best solution? I mean:
So where should I actually add this code?
Is adding a new common decorator on the client side the best solution? I mean:
Code: Select all
client/html/common/decorators/default
Re: Change url sanitize behavior
No, you should do that very early in the bootstrapping process. If you are using Laravel, the AppServiceProvider is a good place:
https://github.com/aimeos/aimeos/blob/m ... hp#L25-L30
https://github.com/aimeos/aimeos/blob/m ... hp#L25-L30
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Change url sanitize behavior
Thanks a million.
Re: Change url sanitize behavior
I was thinking, we don't want the admin to become confused.
So why not save the sanitized URL part in the first place?
Is adding
in admin/jqadm/src/Admin/JQAdm/Product/Standard.php:466 correct?
So why not save the sanitized URL part in the first place?
Is adding
Code: Select all
if (isset($data['product.url']) && $data['product.url'] != '') {
$data['product.url'] = \Aimeos\MW\Str::slug( $data['product.url'] );
}
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Change url sanitize behavior
The sanitized URL is already stored immedately, either the provided value in the product.url field or using the sanitized label:
- https://github.com/aimeos/aimeos-core/b ... #L248-L263
- https://github.com/aimeos/aimeos-core/b ... d.php#L651
- https://github.com/aimeos/aimeos-core/b ... #L248-L263
- https://github.com/aimeos/aimeos-core/b ... d.php#L651
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Change url sanitize behavior
Suppose in the admin panel the URL segment is set to a phrase with whitespaces, for example: 'black dress'.
The phrase saved to the database is exactly 'black dress' because
\Aimeos\MW\Str::slug() is only called when there's no value in the URL segment input.
Then, on the client-side, the URL segment is passed through the slug method, which replaces whitespaces with dashes.
So we can see a product in lists, but clicking on it shows an `Unable to find product` error.
Maybe we could change the setUrl method of product item like this:
The phrase saved to the database is exactly 'black dress' because
\Aimeos\MW\Str::slug() is only called when there's no value in the URL segment input.
Then, on the client-side, the URL segment is passed through the slug method, which replaces whitespaces with dashes.
So we can see a product in lists, but clicking on it shows an `Unable to find product` error.
Maybe we could change the setUrl method of product item like this:
Code: Select all
public function setUrl( ?string $url ) : \Aimeos\MShop\Product\Item\Iface
{
return $this->set( 'product.url', \Aimeos\MW\Str::slug($url));
}
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9
Re: Change url sanitize behavior
Your are right, in that case the product.url is different from the used URL.
Can you create a PR with the required change?
Can you create a PR with the required change?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star
Re: Change url sanitize behavior
Thanks for the merge.
When do you we'll get this change with composer update?
When do you we'll get this change with composer update?
Aimeos version: ~2021.07
Laravel version: ^8.40
PHP: 7.4.9
Laravel version: ^8.40
PHP: 7.4.9