Function to generate a product alias

  • Posts: 634
  • Thank you received: 16
7 years 11 months ago #258070

-- HikaShop version -- : 2.6.4
-- Joomla version -- : 3.6.4
-- Browser(s) name and version -- : Any

I'm building a product importer from a third party DB to Hikashop,

I need to know what function or procedures is required to generate a product alias the way HikaShop does.

Can I call it from my own code built in a separate component?

Thanks in advance.

-- Víctor

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 11 months ago #258073

Hi,

Yes.
You can do like that:

include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_hikashop'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php');
$class = hikashop_get('class.product');
$class->addAlias($productDataObject);
echo $productDataObject->alias;

The following user(s) said Thank You: PeterChain

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

  • Posts: 634
  • Thank you received: 16
7 years 11 months ago #258102

Thank you Nicolas,

I forgot to mention that in my import process from the third party DB there is a potential risk that some products share exactly the same name although the "product code" is always unique, so to avoid potential alias conflicts i would like to add the product_code at the end of the alias as a standard rule. Also, many users / clients will identify first the product by its reference (product_code) than by its name, so in my opinion this is not breaking the SEF logic as many people will search at google by product code.

Do you see any inconvenience in this practice?

How can we add this in a stable way in our system so it does not reset for each hikashop update?

Thank you.

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 11 months ago #258113

Hi,

1. I don't see any problem with that.

2. I don't understand what you mean ? You said in your first message that this code was to be added to the import process in your custom component. Why would HikaShop updates change the products alias or the code of your component ?

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

  • Posts: 634
  • Thank you received: 16
7 years 11 months ago #258161

About point 2.

Sorry for my bad explanation:

My idea is that I would change the HikaShop function to add this product_code in the alias both when the product is imported by my code and when it is created directly in the system so I keep everywhere the same alias scheme.

So, if then I update HikaShop I would potentially loose this alias building "tweak" as I don't think this is an overridable part of the script.

right?

So the question is:

Is there a way to circumvent this, and tell hikashop always to do this with alias? Like maybe rebuilding the alias all the time with an OnBeforeCreate and nBeforeUpdate trigger?

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

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
7 years 11 months ago #258169

Hi,

Exactly, just implement the onBeforeProductCreate and onBeforeProductUpdate triggers in a plugin of the group HikaShop and generate the alias yourself the way you want it. That way, HikaShop will use it automatically.

The following user(s) said Thank You: PeterChain

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

Time to create page: 0.070 seconds
Powered by Kunena Forum