![]() |
Redirect to Product Page when only One product in category
For simple sites that don't use sub-categories, etc, this may come in handy! Further, this was my first success at defining a Smarty var in the actual .TPL template file, then referencing back in php. I'm sure there is an easier way to do this, but this was my first successful attempt.
A request was made to have all of our category links on the left link directly to the individual product page when there is only one product in the category. Adding the following code to the top of skin1/customer/main/subcategories.tpl does the trick! :D Thanks to darrenkierman for pointing out that adding the following code to the top of skin1/customer/main/search_result.tpl will also take you straight to the product page if your search returns only 1 result! Code:
|
Yea, that is a nice one...saw someone looking for this a while back.
|
It works! My bad.
The copy/paste on a mac sometimes adds whitespace when pasting into my preferred text editor (text wrangler)... Thanks to a suggestion from PhilJ, I looked at the code and for whatever reasons, mr. macintosh dropped some extra spaces in to the lines (also when copying from a mac browser like Safari, all kinds of bad things happen at line breaks) Re-formatting all the linebreaks and whitespace fixed this! YEAH BABY! Thank you moneysaver67! Jeremy |
What a BEAUTIFUL piece of code this is...
It also works in sub-cats - so if you make a sub-category with only 1 product, your customer does not have to visit the subcategory page first... This is especially useful if you are using a nested category menu, such as PhilJ's "True Three Level Vertical Category Flyout Menu" This code along with the flyout menus makes the interface fluid and what you (read: customer) expect. Very, very nice. |
Quote:
That is awesome. There I go, coding into the unknown again. LoL Care to post the sub-cat code for the sake of the topic? As always, Enjoy! |
Quote:
There's no extra code! My point was that your code automagically made the functionality of the sub-cats from the flyout menus even better, and exactly as you would expect -- it just worked... in my case, I have 3-deep sub-cats, but some of the sub-cats only have a single product -- and your code makes it so that when you navigate to the 3-deep sub-cat that only has a single product, you end up on the product detail page. THIS IS COOL. This is how it should work by default... thanks!!!! |
Quote:
Rock on, and No problem! :D |
Add the same coding to the top of 'search_result.tpl' and you will get the same effect on your search results.
i.e. if there is only one search result, it will show full details. --- and use the following mod as well: Search by SKU/Product code in quick search - 4.1.1 http://forum.x-cart.com/viewtopic.php?t=29877 and you can have it so when someone puts in a SKU in the search box, the full details appear instantly. |
One small bug .... lets say you have one product and 5 subcategories, it will not show the subcategories because it automatically jumps to the one product. To fix it :
Code:
{if $products|@count eq 1} |
Quote:
Isn't that the point of the mod? The goal is for a category (or subcat) with only one product, to not have the "speedbump" of the category or subcat page. The mod works exactly this way... Why would you want to see the subcategories, if there is only one product ina category? Isn't the goal to get the customer to the product detail page with minimum navigation? I am using PhilJ's "True Three Level Vertical Category Flyout Menu" - and by assigning a product to a sub-cat (even 3 deep) - by selecting the sub-cat, this mod takes you direct to the product detail (assuming it is the only product in the subcat). I think you want to modify your product detail page, to also include the subcategory links... ? |
Quote:
@darren, good find. @carpeperdiem, good point. I think the key here is to realize that different shops are obviously set up to operate and navigate in different manners. Per darren's piont, I can understand having a top-level category with three sub-cats, but wanting the users to see the subcats before being taken to the product page. In this case, I would modify the code so that drilling into the subcat itself would take you to the product page? Either way, good posts on use of the code. I also enjoy the search result hook. :) Keep 'em coming! |
"Rock on" ! LOL moneysaver, i hadnt heard that since wayne's world! LOLOLOLOL
good mod by the way. and i do think that if the category has 1 procut and subcategories, then it should present the subs adn the procuct. NOT go to the product directly. If you go to the product directly. i understand carpes point, but he's using a 3 level flyout, so his mindset is a little different. Others are just using the default xcart menu. |
Re: Redirect to Product Page when only One product in category
Carperdiem,
I just visited the Mommymakeup.com site and it looks great! I a, wondering if you used a mod for Debbie's favorites and would you mind sharing which one? I would like to do that on my site. Thanks! Vera |
Re: Redirect to Product Page when only One product in category
Quote:
Here ya go... http://forum.x-cart.com/showthread.php?t=24671 |
Re: Redirect to Product Page when only One product in category
Thanks!
Vera |
Re: Redirect to Product Page when only One product in category
Just a note, if your using CDSEO then:
Replace: Code:
{assign var="prodURL" value="product.php?productid=`$products.0.productid`&cat=$cat&page=1"} with: Code:
{assign var="prodURL" value="`$http_location`/`$cdseo_prod`/`$products.0.cdseo_url`"} |
Re: Redirect to Product Page when only One product in category
works great!
|
Re: Redirect to Product Page when only One product in category
and when have only one product in manufacter?
|
Re: Redirect to Product Page when only One product in category
Does anyone have it working with the SAFETYNET DSEFU MOD?
Jeanne Gold 4.0.17 |
Re: Redirect to Product Page when only One product in category
I could kiss you on the lips for this mod. Just what I needed. Merci beaucoup.
:D/ Tyme |
Re: Redirect to Product Page when only One product in category
does this mod work with 4.1.8 if so, can someone post the latest code
we have sub categories , and a seo url rewirte installed |
Re: Redirect to Product Page when only One product in category
It works fine, I have used it in 4.1.8 without issue.
|
Re: Redirect to Product Page when only One product in category
Anyone got a fix to make this great mod work with Safetynetweb's DSEFU ?
|
Re: Redirect to Product Page when only One product in category
Just out of interest, I contacted John Heath at SafetyNetWeb and he very quickly and efficiently fixed the file for me. Now it works great with the DSEFU. Excellent service.
You can contact him at safetynetweb.com ****E-MAIL removed by mod *** |
Re: Redirect to Product Page when only One product in category
Love this mod! Does anyone know a way to make it so that if there is only one subcategory and no products that it will redirect to that category? Sounds silly I know but the categories in my shop are getting a little out of hand :) thanks!
|
Re: Redirect to Product Page when only One product in category
In my Google account I get a Warning on my Sitemap that I have pages that returning 302 redirects. It looks like the only products that have the problem pages are the ones that use this redirect. I'm going to turn this off and see if this is the problem.
If anyone else has seen this, I'd like to know. |
Re: Redirect to Product Page when only One product in category
any news on the last question?
Also, i'm getting the following error after installing BCSE back/preorder mod: Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/wd_newest/include/preorder_search.php:13) in /Applications/MAMP/htdocs/wd_newest/var/templates_c/%%3D^3DB^3DBA0730%%subcategories.tpl.php on line 8 Best, B |
Re: Redirect to Product Page when only One product in category
It works on 4.1.12
We'll see what google thinks about it. Jon, your code for CDSEO doesn't work. Can you update it please? |
Re: Redirect to Product Page when only One product in category
Quote:
The CDSEO code is for CDSEO Basic only. For CDSEO Pro you can use the default code and the url will 301 redirect to the CDSEO Pro url. Jon Peters |
Re: Redirect to Product Page when only One product in category
Yes, but it redirects to "monaco-suspender-belt.html?&cat=14" instead of "monaco-suspender-belt.html"
For customer it looks alright, I don't mind but Google can find it as duplicate content because both addresses exist. Don't worry, just decided to remove it as it can confuse some 'blond' customers. Thanks. |
Re: Redirect to Product Page when only One product in category
If using a recent version of CDSEO with canonical link support then the primary url would be indexed only regardless.
You could also change the code from: Code:
{assign var="prodURL" value="product.php?productid=`$products.0.productid`&cat=$cat&page=1"} to: Code:
{assign var="prodURL" value="product.php?productid=`$products.0.productid`"} |
Re: Redirect to Product Page when only One product in category
How would I use this code for a category without a subcategory, though there maybe 1 to 5 products?
|
Re: Redirect to Product Page when only One product in category
Quote:
You don't. The purpose of this mod is so that your customer can simply choose a category (or subcat) and be taken to the ONLY product in the category (or subcat). There is no other purpose for this mod. If you have a category with 1 to 5 products, you could make a subcat per product, assign the product as the only product in the subcat, and then use this code. Got it? |
Re: Redirect to Product Page when only One product in category
HI,
Will this work with 4.2.1?:wink: I want to test. but if anyone done let me know. Thanks, |
Re: Redirect to Product Page when only One product in category
This DOES NOT work with 4.3 beta3
--- but if you edit this line, it will: Code:
{assign var="prodURL" value="`$http_location`/`$products.0.page_url`"} |
Re: Redirect to Product Page when only One product in category
CONFIRMED to work with 4.3.0 PRO
INSERT the following to the top of /skin1/customer/main/subcategories.tpl Code:
{* BEGIN MOD to Redirect to Product Page when only One product in category *} |
Re: Redirect to Product Page when only One product in category
The above also works with the flyout module in 4.4
Placing it at the top of: /common_files/modules/Flyout_Menus/Icons/fancy_subcategories.tpl or /common_files/modules/Flyout_Menus/Icons/fancy_subcategories_exp.tpl |
Re: Redirect to Product Page when only One product in category
Mod confirmed to work with 4.5.3 goldplus!
Not sure if the code needs to change for CDSEO Pro? INSERT the following to the top of /skin/common_files/customer/main/subcategories.tpl Code:
{* BEGIN MOD to Redirect to Product Page when only One product in category *} |
Re: Redirect to Product Page when only One product in category
Quote:
For SEO purposes it would be much better to do the redirect in PHP as this causes a 302 redirect and in PHP you could create a proper 301. |
Re: Redirect to Product Page when only One product in category
But Jon...
The page doesn't redirect at all - only the category does *to the page). And it redirects to the page, which is indexed. The "category" in this case is NOT indexed, nor do we want it to be, if there is only a single product associated. Where this technique works well is for a store using flyout menus... COMPUTER HARDWARE KEYBOARDS (only 1 item - this takes us directly to product detail page) MOTHRBOARDS (3 items, this takes us to the category page) PORTABLE COMPUTERS (2 items, this takes us to the category page) PRINTERS (3 items, this takes us to the category page) So although Computer Hardware > Keyboards is a category, this code automatically sends the browsing customer to the one ond only product in the category. Jon - ARE YOU SUGGESTING that we solve the browsing experience for the customer with a 301? This will mean more work for the admin, since we have to identify each instance of this situation... Are you also suggesting stores with CDSEO Pro NOT use this technique? Thanks for the clarification. J |
All times are GMT -8. The time now is 01:13 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.