Link To Categories

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331273

-- HikaShop version -- : 4.4.1
-- Joomla version -- : 3.9.25

Hi

I am redeveloping an existing site.

I have implemented some code from an older post as the client would like the user to be able to view other products in the categories the product is listed in from the product page.

The code does work however I have a query. The url is

This message contains confidential information
while I would prefer it to be
This message contains confidential information
Not sure of that is achievable?

Also if I click the Pre-orders button
This message contains confidential information
I get a category not found page. I do not have a packaging category and cannot see why this may be happening. This happens on any product where there is a a Pre-order button.

Finally if I click the TV/Movie/Game link I get the categories first, I am struggling to find the area that will only show the products. All other areas of the site are working correctly and from what I can see the settings are the same for that category.

Thanks

David

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

  • Posts: 83404
  • Thank you received: 13498
  • MODERATOR
3 years 11 months ago #331275

Hi,

The hikashop_contentLink function you're using to generate the link will either generate the link dynamically from the first parameter ( 'category&task=listing&cid='.$category->category_id.'&name='.$category->alias ) and the router system of Joomla, or it will use the canonical URL of the category.
It will use the canonical URL only if the option "use canonical URLs on listings" setting of the HikaShop configuration is activated.

When that option is not activated and it generates the link dynamically, it shouldn't generate URLs that result in 404 errors. However, when that option is activated and that the canonical URL in the category is not correct, it will result in a 404.
So I suppose that you have that "force canonical URLs on listing" setting activated, but that the canonical URL setting of some of your categories is not correct anymore and thus lead to a 404 error or not the page you want.
So check these and it should help.

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

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331316

Hi

I have Force canonical URLs on listings - No, generate the URLs. Ideally I need to remove the packaging from the URL, is there a way to do this via mass action please?

I also seem to be having an issue with categories appearing at the top first where there are subcategories

So from

This message contains confidential information
if you click Macfarlane for instance I get the 2 sub categories and then the product list. Is there a way to hide the sub categories?

Thanks

David

Last edit: 3 years 11 months ago by davec.

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

  • Posts: 83404
  • Thank you received: 13498
  • MODERATOR
3 years 11 months ago #331317

Hi,

I think the best would be to create a menu item of the type "products listing" via your Joomla menu manager and then change the code you're using to add the Itemid parameter like that:

echo '<a href="'.hikashop_contentLink('category&task=listing&Itemid=XX&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';
where XX is the id of the menu item.
That way, the link will go that products listing menu item and you won't get categories.

Now regarding the 404 error, I'm not sure why you would get a 404 error. Could you provide a screenshot of the settings of the category ?

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

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331378

Hi Nicolas

the Macfarlane category is already set up as a product listing and if I click that menu item I get the product list as expected. There are 2 categories within that also Warhammer & My Hero Academia which show at the top before the listings if I click the Macfarlane link from the product detail page. I get sent to /action-figures/gi-joe/category/mcfarlane If I then remove /gi-joe/category so the /action-figures/mcfarlane the page displays correctly. So in the attached screenshot (cat-buttons) If you click Super 7 it goes to action-figures/super-7/ not action-figures/super-7/category/super-7

The pre-orders is set up in the same way. As I have said though I have ended up with packaging at the end which fails. The products are often in more than one category.

Thanks

David

Attachments:
Last edit: 3 years 11 months ago by davec. Reason: additonal image & description

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

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331387

Hi

I have managed to solve the pre-orders issue by adding a canonical url in the category. I then set the SEO to Use Canonical URL if specified. I also found packaging in he URL which must have been added when that category was labelled Packaging originally. So based on my requirements I think I will need to create a canonical URL for each category/sub-category.

Thanks

David

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

  • Posts: 83404
  • Thank you received: 13498
  • MODERATOR
3 years 11 months ago #331380

Hi,

Well, the hikashop_contentLink function cannot choose for you which menu item to use to generate the link.
If you want to have the same URL as usually used while generating the URL dynamically you need to write a big piece of code to handle that. For example, in the getLink function of the file components/com_hikashop/views/category/view.html.php we have more than 50 lines of code to select the menu item corresponding to the category for which we're generating the link dynamically. You would have to write some code similar to this (but different) to do what you want.
So yes, entering the URL that you want for each category in the "canonical URL" field of the category and setting the "force canonical URL on listings" option to "use canonical URL if specified" will indeed be a way simplier solution.

Last edit: 3 years 11 months ago by nicolas.
The following user(s) said Thank You: davec

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

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331764

Hi

I have small query which I am not sure is possible?

$categoryClass = hikashop_get('class.category');
$categoryClass->addAlias($category);
echo '<a href="'.hikashop_contentLink('category&task=listing&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';

I have used the code above and it works as expected in showing the
This message contains confidential information
However the Incoming category is for registered users only so if it is clicked a 404 page is displayed unless logged in. Is there a way to hide the incoming category unless you are logged in?

Thanks

David

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

  • Posts: 83404
  • Thank you received: 13498
  • MODERATOR
3 years 11 months ago #331766

Hi,

you can use such code instead:

iif(hikashop_isAllowed($category->category_access)) {

$categoryClass = hikashop_get('class.category');
$categoryClass->addAlias($category);
echo '<a href="'.hikashop_contentLink('category&task=listing&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';

}
That way the link will appear or not based on the user groups of the current user and the "access level" setting of the category.

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

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331777

Hi Nicolas

the code I currently have is

<?php foreach($this->categories as $category){
  $categoryClass = hikashop_get('class.category');
  $categoryClass->addAlias($category);
  echo '<a style="background:#333;color:#fff;font-size:1.0rem;"class="hikabtn" href="'.hikashop_contentLink('category&task=listing&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> &nbsp; ';
  }
  ?>

If I change it to the code you supplied all of the category buttons disappear. I only require the incoming link to be hidden unless registered.

Thanks

David

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

  • Posts: 83404
  • Thank you received: 13498
  • MODERATOR
3 years 11 months ago #331779

Hi,

You need to keep the foreach around the code I gave, otherwise $category won't be defined and thus nothing will display.
So the code should be:

<?php foreach($this->categories as $category){
iif(hikashop_isAllowed($category->category_access)) {

$categoryClass = hikashop_get('class.category');
$categoryClass->addAlias($category);
echo '<a href="'.hikashop_contentLink('category&task=listing&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';

} 
}
  ?>

The following user(s) said Thank You: davec

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

  • Posts: 440
  • Thank you received: 20
  • Hikashop Essential
3 years 11 months ago #331787

Thanks Nicolas

all worked a treat.

David B)

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

Time to create page: 0.076 seconds
Powered by Kunena Forum