X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   Redirect to Product Page when only One product in category (https://forum.x-cart.com/showthread.php?t=23339)

moneysaver67 07-17-2006 07:40 AM

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:


{if $products|@count eq 1}
        {assign var="prodURL" value="product.php?productid=`$products.0.productid`&cat=$cat&page=1"}
        {php}
                header( "Location: " . $GLOBALS[smarty]->_tpl_vars[prodURL] );
        {/php}
{/if}


balinor 07-18-2006 02:23 AM

Yea, that is a nice one...saw someone looking for this a while back.

carpeperdiem 07-28-2006 05:00 AM

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

carpeperdiem 07-28-2006 06:31 AM

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.

moneysaver67 07-28-2006 08:41 PM

Quote:

Originally Posted by carpeperdiem
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.


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!

carpeperdiem 07-28-2006 08:53 PM

Quote:

Originally Posted by moneysaver67
Care to post the sub-cat code for the sake of the topic?


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!!!!

moneysaver67 07-29-2006 07:28 PM

Quote:

Originally Posted by carpeperdiem
Quote:

Originally Posted by moneysaver67
Care to post the sub-cat code for the sake of the topic?


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!!!!


Rock on, and No problem! :D

carlisleglass 07-31-2006 12:39 AM

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.

carlisleglass 07-31-2006 05:02 AM

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}
{if $subcategories}{else}
  {assign var="prodURL" value="product.php?productid=`$products.0.productid`&cat=$cat&page=1"}
  {php}
      header( "Location: " . $GLOBALS[smarty]->_tpl_vars[prodURL] );
  {/php}
{/if}
{/if}


carpeperdiem 07-31-2006 05:14 AM

Quote:

Originally Posted by darrenkierman
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.


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... ?

moneysaver67 07-31-2006 08:34 AM

Quote:

Originally Posted by darrenkierman
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}
{if $subcategories}{else}
  {assign var="prodURL" value="product.php?productid=`$products.0.productid`&cat=$cat&page=1"}
  {php}
      header( "Location: " . $GLOBALS[smarty]->_tpl_vars[prodURL] );
  {/php}
{/if}
{/if}



@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!

ecommerce 08-05-2006 07:21 AM

"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.

Acquamarina 09-19-2006 06:47 AM

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

carpeperdiem 09-19-2006 07:33 AM

Re: Redirect to Product Page when only One product in category
 
Quote:

Originally Posted by Acquamarina
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


Here ya go...

http://forum.x-cart.com/showthread.php?t=24671

Acquamarina 09-19-2006 09:15 AM

Re: Redirect to Product Page when only One product in category
 
Thanks!

Vera

Jon 09-19-2006 01:34 PM

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`"}

ryan c. 12-01-2006 04:18 PM

Re: Redirect to Product Page when only One product in category
 
works great!

gastu 12-01-2006 07:42 PM

Re: Redirect to Product Page when only One product in category
 
and when have only one product in manufacter?

jeanne 12-18-2006 09:47 AM

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

alreadyregistered 10-10-2007 06:21 AM

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

luxor 11-13-2007 09:58 AM

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

balinor 11-13-2007 09:59 AM

Re: Redirect to Product Page when only One product in category
 
It works fine, I have used it in 4.1.8 without issue.

Steve-C 11-19-2007 07:04 AM

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 ?

Steve-C 11-30-2007 04:33 AM

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 ***

instink 02-06-2008 10:25 PM

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!

jeanne 04-10-2008 06:38 PM

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.

craichead 06-11-2008 09:13 PM

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

Stizerg 04-10-2009 07:47 AM

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?

Jon 04-10-2009 11:34 AM

Re: Redirect to Product Page when only One product in category
 
Quote:

Originally Posted by Stizerg
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?


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

Stizerg 04-10-2009 06:22 PM

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.

Jon 04-10-2009 06:42 PM

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`"}

ChristineP 06-01-2009 08:07 AM

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?

carpeperdiem 06-01-2009 09:19 AM

Re: Redirect to Product Page when only One product in category
 
Quote:

Originally Posted by ChristineP
How would I use this code for a category without a subcategory, though there maybe 1 to 5 products?


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?

AusNetIT 06-04-2009 09:43 PM

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,

carpeperdiem 10-07-2009 08:41 AM

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`"}

carpeperdiem 11-20-2009 04:15 PM

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 *}
{if $products|@count eq 1}
    {assign var="prodURL" value="`$http_location`/`$products.0.page_url`"}
    {php}
        header( "Location: " . $GLOBALS[smarty]->_tpl_vars[prodURL] );
    {/php}
{/if}
{* END MOD to Redirect to Product Page when only One product in category *}


DrQuietus 11-06-2011 07:08 AM

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

carpeperdiem 10-10-2012 07:41 AM

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 *}
{if $products|@count eq 1}
    {assign var="prodURL" value="`$http_location`/`$products.0.page_url`"}
    {php}
        header( "Location: " . $GLOBALS[smarty]->_tpl_vars[prodURL] );
    {/php}
{/if}
{* END MOD to Redirect to Product Page when only One product in category *}


Jon 10-11-2012 09:51 AM

Re: Redirect to Product Page when only One product in category
 
Quote:

Originally Posted by carpeperdiem
Not sure if the code needs to change for CDSEO Pro?


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.

carpeperdiem 10-11-2012 10:10 AM

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.