Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Redirect to Product Page when only One product in category

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 07-17-2006, 07:40 AM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

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

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}
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote

The following 3 users thank moneysaver67 for this useful post:
donavichi (10-25-2009), jaydee (08-11-2009), Regs (11-30-2009)
  #2  
Old 07-18-2006, 02:23 AM
 
balinor balinor is offline
 

Veteran
  
Join Date: Oct 2003
Location: Connecticut, USA
Posts: 30,253
 

Default

Yea, that is a nice one...saw someone looking for this a while back.
__________________
Padraic Ryan
Ryan Design Studio
Professional E-Commerce Development
Reply With Quote
  #3  
Old 07-28-2006, 05:00 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default

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
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #4  
Old 07-28-2006, 06:31 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default

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.
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #5  
Old 07-28-2006, 08:41 PM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default

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!
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote
  #6  
Old 07-28-2006, 08:53 PM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default

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!!!!
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
  #7  
Old 07-29-2006, 07:28 PM
  moneysaver67's Avatar 
moneysaver67 moneysaver67 is offline
 

Advanced Member
  
Join Date: Nov 2005
Posts: 74
 

Default

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!
__________________
X-Cart 4.0.16-.19 Gold [unix] / DSEFU
Reply With Quote
  #8  
Old 07-31-2006, 12:39 AM
  carlisleglass's Avatar 
carlisleglass carlisleglass is offline
 

eXpert
  
Join Date: Aug 2003
Location: Carlisle, UK
Posts: 316
 

Default

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.
__________________
Darren Kierman
Carlisle Glass (http://www.carlisleglass.co.uk/)
... running X-Cart Gold 4.4.5 [unix]
Reply With Quote
  #9  
Old 07-31-2006, 05:02 AM
  carlisleglass's Avatar 
carlisleglass carlisleglass is offline
 

eXpert
  
Join Date: Aug 2003
Location: Carlisle, UK
Posts: 316
 

Default

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 Kierman
Carlisle Glass (http://www.carlisleglass.co.uk/)
... running X-Cart Gold 4.4.5 [unix]
Reply With Quote
  #10  
Old 07-31-2006, 05:14 AM
 
carpeperdiem carpeperdiem is offline
 

X-Guru
  
Join Date: Jul 2006
Location: New York City, USA
Posts: 5,399
 

Default

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... ?
__________________
xcart 4.5.4 gold+ w/x-payments 1.0.6; xcart gold 4.4.4
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 07:28 AM.

   

 
X-Cart forums © 2001-2020