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)

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 12:45 AM.

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