Auto-generate alias on content translation

  • Posts: 23
  • Thank you received: 2
  • Hikaserial Standard
3 years 3 months ago #335340

-- 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.

  • Posts: 82956
  • Thank you received: 13392
  • MODERATOR
3 years 3 months ago #335342

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: 3 years 3 months ago by nicolas.

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

  • Posts: 23
  • Thank you received: 2
  • Hikaserial Standard
3 years 3 months ago #335347

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.

  • Posts: 82956
  • Thank you received: 13392
  • MODERATOR
3 years 3 months ago #335348

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.

  • Posts: 23
  • Thank you received: 2
  • Hikaserial Standard
2 years 7 months ago #340864

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.

  • Posts: 82956
  • Thank you received: 13392
  • MODERATOR
2 years 7 months ago #340866

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.

  • Posts: 23
  • Thank you received: 2
  • Hikaserial Standard
2 years 7 months ago #340881

Thanks.

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

On line 327 instead:

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

and line 332
$emptyObject->$name_field = $trans;
to
$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.

  • Posts: 82956
  • Thank you received: 13392
  • MODERATOR
2 years 7 months ago #340882

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.073 seconds
Powered by Kunena Forum