create task=showcart url with menu itemid

  • Posts: 3
  • Thank you received: 0
3 years 4 months ago #326084

-- HikaShop version -- : 4.3
-- Joomla version -- : 3.9.19
-- PHP version -- : 7.2
-- Browser(s) name and version -- : chrome

Hello,
I am changing the lnk from cart module to go to showcart page instead of checkout.
this is what I found in module:

$link = hikashop_completeLink('cart&task=showcart&cart_id='.$this->element->cart_id.'&cart_type='.$this->element->cart_type . $this->cart_itemid);
Now this does take me to the cart page, but with itemid of menu item for the shop.
But I have created menu item specifically for the cart page.
Can I route this link to get the right itemid?

Thanks

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
3 years 4 months ago #326095

Hi,

Yes. You need to change $this->cart_itemid by '&Itemid=xx' where xx is the id of the menu item you created for the cart page.

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

  • Posts: 3
  • Thank you received: 0
3 years 4 months ago #326125

Thanks,
well this is obvious, but I do not want to add Itemid number manually, what if I change it tomorrow?
The routing is supposed to take Itemid (if such menu exists) automatically. This is what usually happens with joomla.

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

  • Posts: 81481
  • Thank you received: 13062
  • MODERATOR
3 years 4 months ago #326127

Hi,

There is no such mechanism as far as I know that auto detects which menu item to use.
Normally in Joomla, the links generated on a page uses the current menu item and that's it.
Automatically calculating the menu item to use would require a few dozen lines of code along with a MySQL query and it's not that easy. For example, the system would have to check if the menu item's access is available to the current user as the cart page menu item that might be created in the backend might be only for registered users, and you might be not logged in. And that's just one example of what needs to be checked. Another one would be the language issue.
That's why there are many menu item selection options to tell the system what menu item to use.
For example, you have the "force a menu on checkout" setting in the HikaShop configuration which allows you to select a menu item to use on the checkout.
And if you leave that setting empty, it will stay on the current menu item when reaching the checkout, even if you have a HikaShop checkout menu item created.
So to me it looks normal to have the menu item id in hard there. But you sure can write the few dozen of lines of code to search in the menu table of Joomla for the menu item to get its id and set it there dynamically. As a basis, you can check the code in the file administrator/components/com_hikashop/classes/menus.php where you'll find some functions we wrote to check the menu items and try to auto select them for some URLs generated in some places of HikaShop. For example to check that the menu item selected in the "force a menu on checkout" setting is a valid one we have the getCheckoutURL and loadAMenuItemId functions.

Last edit: 3 years 4 months ago by nicolas.

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

  • Posts: 3
  • Thank you received: 0
3 years 4 months ago #326164

I understand,
I thought there is a joomla routing function that does that..
I think I can manage to do this with sh404sef component.

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

Time to create page: 0.060 seconds
Powered by Kunena Forum