Skip to main content

Auto-generate alias on content translation

More
5 years 1 month ago #335340 by braverman
-- HikaShop version -- : 4.4.3
-- Joomla version -- : 3.9.28
-- PHP version -- : 7.4.22

Hi,

my client translates hundreds of categories/products/etc. into 4 languages using the Falang extension. All works fine but I am trying to improve it a little. When saving translation from edit page I would like to autogenerate alias according to the name field (using stringURLSafe function). I don't like to hack core files so the ideal solution would be either if you implement this function (should be few lines in translation helper in function handleTranslations and one toggle switch in configuration) or more universally to trigger plugin event before and/or after translation saving.

Does it sound meaningful?

Thanks, Jan

Please Log in or Create an account to join the conversation.

More
5 years 1 month ago - 5 years 1 month ago #335342 by nicolas
Hi,

The handleTranslations is not really adapted to have before/after events.
And you can already use the onAfterProductUpdate and onAfterCategoryUpdate events to set the alias in the translations if empty.
And it's a bit more than a few lines to add code to handle that. It's more like 40 lines to do it properly.
But yes, it's a good idea to generate the alias automatically for the translation when the "alias auto fill" setting of the HikaShop configuration is activated. We'll look at adding that, thanks for your feedback.
Last edit: 5 years 1 month ago by nicolas.

Please Log in or Create an account to join the conversation.

More
5 years 1 month ago #335347 by braverman
Thanks! :-)

I thought that translation editing uses controller function save_translation that does not update product/category and so does not trigger onAfterProductUpdate or onAfterCategoryUpdate. But maybe I am wrong, did not test it.

Jan

Please Log in or Create an account to join the conversation.

More
5 years 1 month ago #335348 by nicolas
Hi,

That's my bad. You're correct. Still, we'll look at adding that. It will be better that way as events as not really appropriate there.

Please Log in or Create an account to join the conversation.

More
4 years 6 months ago #340864 by braverman
Hi,
I returned to this topic after some time and found that it is half way. I found changes in handleTranslations method but if I see correctly these changes are never executed because the variable $auto_fill_prefix is never true. Am I correct?

Thanks, Jan

Please Log in or Create an account to join the conversation.

More
4 years 6 months ago #340866 by nicolas
Hi,

That's a good point. I think I forgot to change the code calling handleTranslations in the product controller.
I'll change the line for the next version (4.5.2) :
$translationHelper->handleTranslations('product',$element->product_id,$element);
to:
$translationHelper->handleTranslations('product',$element->product_id,$element, 'hikashop_', null, true);
in administrator/components/com_hikashop/controllers/product.php and that should do it.
The following user(s) said Thank You: braverman

Please Log in or Create an account to join the conversation.

More
4 years 6 months ago #340881 by braverman
Thanks.

I tested it (patched it according to your post) and found some other errors in translation.php:

On line 327 instead:
Code:
if($config->get('alias_auto_fill', 1) && $auto_fill_prefix && $field == $name_field && !empty($trans) && empty($transArray[$alias_field])) {
changed to:
Code:
if($config->get('alias_auto_fill', 1) && $auto_fill_prefix && $field == $name_field && !empty($trans) && empty($transArray[$alias_field][$lg])) {

and line 332
Code:
$emptyObject->$name_field = $trans;
to
Code:
$emptyObject->$name_field = $value;

Now it works.

Jan
The following user(s) said Thank You: nicolas

Please Log in or Create an account to join the conversation.

More
4 years 6 months ago #340882 by nicolas
Hi,

Thank you for your feedback. We'll add these modifications for the 4.5.2
The following user(s) said Thank You: braverman

Please Log in or Create an account to join the conversation.

Time to create page: 0.132 seconds
Powered by Kunena Forum