- Posts: 447
- Thank you received: 20
Link To Categories
5 years 6 months ago #331273
by davec
Link To Categories was created by davec
-- 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
Also if I click the Pre-orders 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
-- 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.
5 years 6 months ago #331275
by nicolas
Replied by nicolas on topic Link To Categories
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.
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.
5 years 6 months ago - 5 years 6 months ago #331316
by davec
Replied by davec on topic Link To Categories
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
Thanks
David
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: 5 years 6 months ago by davec.
Please Log in or Create an account to join the conversation.
5 years 6 months ago #331317
by nicolas
Replied by nicolas on topic Link To Categories
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:
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 ?
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:
Code:
echo '<a href="'.hikashop_contentLink('category&task=listing&Itemid=XX&cid='.$category->category_id.'&name='.$category->alias,$category).'">'.($category->category_name).'</a> - ';
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.
5 years 6 months ago - 5 years 6 months ago #331378
by davec
Replied by davec on topic Link To Categories
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
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
Last edit: 5 years 6 months ago by davec. Reason: additonal image & description
Please Log in or Create an account to join the conversation.
5 years 6 months ago #331387
by davec
Replied by davec on topic Link To Categories
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
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.
5 years 6 months ago - 5 years 6 months ago #331380
by nicolas
Replied by nicolas on topic Link To Categories
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.
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: 5 years 6 months ago by nicolas.
The following user(s) said Thank You: davec
Please Log in or Create an account to join the conversation.
5 years 5 months ago #331764
by davec
Replied by davec on topic Link To Categories
Hi
I have small query which I am not sure is possible?
I have used the code above and it works as expected in showing the
Thanks
David
I have small query which I am not sure is possible?
Code:
$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.
5 years 5 months ago #331766
by nicolas
Replied by nicolas on topic Link To Categories
Hi,
you can use such code instead:
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.
you can use such code instead:
Code:
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> - ';
}
Please Log in or Create an account to join the conversation.
5 years 5 months ago #331777
by davec
Replied by davec on topic Link To Categories
Hi Nicolas
the code I currently have is
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
the code I currently have is
Code:
<?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> ';
}
?>
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.
5 years 5 months ago #331779
by nicolas
Replied by nicolas on topic Link To Categories
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:
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:
Code:
<?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.
5 years 5 months ago #331787
by davec
Replied by davec on topic Link To Categories
Thanks Nicolas
all worked a treat.
David
all worked a treat.
David
Please Log in or Create an account to join the conversation.
Time to create page: 0.304 seconds