网络营销电子商务研究中心

网络营销电子商务研究中心 (https://www.0058.net/index.php)
-   X-Cart (https://www.0058.net/forumdisplay.php?f=70)
-   -   Redirect to Product Page when only One product in category (https://www.0058.net/showthread.php?t=5412)

Pace 2016-02-14 07:40 PM

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}


Raelyn 2016-02-14 07:41 PM

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}


Taberville 2016-02-14 07:44 PM

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


All times are GMT +8. The time now is 10:49 PM.

Powered by vBulletin Version 3.8.7
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.