Edit sanitize method in vendor file

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!
emdee
Posts: 3
Joined: 12 Jun 2020, 11:33

Edit sanitize method in vendor file

Post by emdee » 12 Jun 2020, 11:48

Hello,

I need to overide method sanitize in \vendor\aimeos\aimeos-core\lib\mwlib\src\MW\Common\Base.php
What is the best practice to do that to avoid upgrade issues in the future ?

One similiar solution I made before:
When the product is saved in admin, it generates sanitized URL for url.segment. I was able to edit this function right in ext file :

Code: Select all

ext/ai-laravel/lib/custom/src/MW/View/Helper/Url/Laravel5.php
I left there original function sanitize() added my own function sanitize2() and now original method calling my own function.
It is right to edit functions in ext folder like that ?

But now the problem is:
When product url.segment is empty, it is generated from product.label. And this logic is only in vendor files

Code: Select all

 \vendor\aimeos\aimeos-core\lib\mwlib\src\MW\Common\Base.php 
as I wrote at the beginning. So what is the best practice to solve this problem please ?

Thank you

Laravel 7
Aimeos 2020.04
PHP 7.4
Xampp

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

Re: Edit sanitize method in vendor file

Post by aimeos » 13 Jun 2020, 17:03

The only way is to extend the classes and overwrite the methods where it's used.
Why do you want to change it?
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

emdee
Posts: 3
Joined: 12 Jun 2020, 11:33

Re: Edit sanitize method in vendor file

Post by emdee » 15 Jun 2020, 12:01

Thanks for your response. So I can do it with service provider, as mentioned here ? https://laracasts.com/discuss/channels/ ... or-methods

I need to change it, because there are missing letters, when you write product label in Czech / Slovak language.

When you write a Czech/Slovak title of a product for example "Počítač ASUS" it generates url "po-ta-asus" instead of "pocitac-asus"

So I edited function sanitize() and now no character is missing, which is very desirable for SEO.

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

Re: Edit sanitize method in vendor file

Post by aimeos » 15 Jun 2020, 17:36

In dev-master, we use that code:
https://github.com/aimeos/aimeos-core/b ... #L147-L148

Does this work for you (requires "voku/portable-ascii": "^1.4")?
If yes, it will be in the new release in three weeks. This is much easier than changing all occurrences the method is used in the code.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

emdee
Posts: 3
Joined: 12 Jun 2020, 11:33

Re: Edit sanitize method in vendor file

Post by emdee » 16 Jun 2020, 11:24

Yes it works, thanks. And in case of similiar problem in future, the best practice is to extend original class with service provider ?
If you publish new upgrade, only vendor files are changed or files in root folder (for example /ext/ folder) too ?

Thanks

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

Re: Edit sanitize method in vendor file

Post by aimeos » 16 Jun 2020, 11:39

emdee wrote: 16 Jun 2020, 11:24 Yes it works, thanks. And in case of similiar problem in future, the best practice is to extend original class with service provider ?
No, because it's not implemented as Laravel service provider which you can overwrite. It's only a class that's used.
emdee wrote: 16 Jun 2020, 11:24 If you publish new upgrade, only vendor files are changed or files in root folder (for example /ext/ folder) too ?
Yes
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply