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


All times are GMT -8. The time now is 07:39 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.