Create category link with content Menu alias only

  • Posts: 8
  • Thank you received: 1
11 years 6 months ago #109979

I am adding a link to the product category in the view product / show.php .

This link is a Menu item of the type Products listing, so it is also present in Hikashop Content menus:

AliasTypeLink
exampleproductindex.php?option=com_hikashop&view=product&layout=listing

So, in the view I was expecting this code to work:

JRoute::_('index.php?option=com_hikashop&view=product&layout=listing'.$url_itemid.$lang);

But this returns:

/example/product/listing

Should it return the "/product/listing", since it is unecessary?
Is there a better way of getting only "/example" than doing something like this?

preg_replace('/\/product\/listing$/', '', JRoute::_('index.php?option=com_hikashop&view=product&layout=listing'.$url_itemid.$lang));

Thanks!

Last edit: 11 years 6 months ago by pipedream. Reason: formatting

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

  • Posts: 83049
  • Thank you received: 13408
  • MODERATOR
11 years 6 months ago #110051

Hi,

That should indeed be the case if the option "Activate smaller url" of the configuration is turned on.

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

  • Posts: 8
  • Thank you received: 1
11 years 6 months ago #110118

It is.

SEF url options

Simplified breadcrumbs: Yes
Activate smaller url..: Yes
Category SEF name.....: categoria
Product SEF name......: (I left this empty)

Last edit: 11 years 6 months ago by pipedream. Reason: formatting

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

  • Posts: 83049
  • Thank you received: 13408
  • MODERATOR
11 years 6 months ago #110134

Maybe you can try with ctrl instead of view and task instead of layout as that's what we're normally using inside hikashop but normally it should also work with view and layout.

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

  • Posts: 8
  • Thank you received: 1
11 years 6 months ago #110161

JRoute::_('index.php?option=com_hikashop&ctrl=product&task=listing'.$url_itemid.$lang);
gives the same result:

/example/product/listing

Took a quick look at /components/com_hikashop/router.php and it seems that the only menu types where the crtl/task or layout/view pairs are being unset are the category listing and product show.

So, the "/product/listing" part can only be avoided by adding:

else if($query['view']=='product' && $query['layout']=='listing'){
        unset( $query['layout'] );
        unset( $query['view'] );
}
which I won't add, at least until I further understand if I'm not ruining anything else.

Should HikaShop router better understand which menus correspond to its builded links, thus avoiding unecessary added segments?

Last edit: 11 years 6 months ago by pipedream. Reason: formatting

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

  • Posts: 83049
  • Thank you received: 13408
  • MODERATOR
11 years 6 months ago #110240

Ok I see what you mean.

But no, if you want to have only the menu alias you should give only the menu itemid.
So I think that what you want actually is to use the code:

JRoute::_('index.php?option=com_hikashop'.$url_itemid.$lang);

Because joomla already knows that you want a products listing using the type of the menu of the itemid of the URL.

That's why the URLs of products listings don't have the product/listing part.

The following user(s) said Thank You: pipedream

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

  • Posts: 8
  • Thank you received: 1
11 years 6 months ago #110257

Perfect solution, merci!!!

For some mysterious reason I thought JRoute also needed the ctrl/task or view/layout pair...

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

Time to create page: 0.067 seconds
Powered by Kunena Forum