Page 1 of 2
[Solved]Category with only one product
Posted: Mon Apr 04, 2011 11:56 pm
by harleybill
Is there a way to skip the category page and go straight to the product page on categories that have only one product.
Re: Category with only one product
Posted: Tue Apr 05, 2011 2:04 am
by Qphoria
We will try to add this in future versions. I remember this from zencart and found it useful
Re: Category with only one product
Posted: Tue Apr 05, 2011 8:31 am
by marc_cole
Qphoria wrote:We will try to add this in future versions.l
+1
Re: Category with only one product
Posted: Thu May 12, 2011 3:32 am
by jmagro
Hiya, any update on this post? I'm using the most recent version but don't see that option. Thanks a bunch!
Re: Category with only one product
Posted: Sat Sep 17, 2011 7:12 am
by sino
yes this would be very useful, is this still not possible?
Re: Category with only one product
Posted: Sat Sep 17, 2011 5:01 pm
by uksitebuilder
the category page would need some extra functions to check if product count = 1
if it does, grab it's id and then redirect to the product
--
same could be done on the search results page, if only 1 result found redirect to it.
I'm updating my search extension soon, so may add this. When I do I'll post the code for it and similar for the category changes too.
Re: Category with only one product
Posted: Sun Sep 18, 2011 3:36 am
by sino
great, thanks simon, will keep an eye out
Re: Category with only one product
Posted: Fri Mar 02, 2012 12:21 am
by uksitebuilder
Sorry for the delay on this guys
edit: catalog/controller/product/category.php
Find:
Code: Select all
foreach ($results as $result) {
if ($result['image']) {
Replace with:
Code: Select all
foreach ($results as $result) {
if($product_total == 1){
$this->redirect($this->url->link('product/product', 'product_id='.$result['product_id']));
}
if ($result['image']) {
Re: [Solved]Category with only one product
Posted: Fri May 25, 2012 2:08 am
by Meshach
Thanks man! Great job.
Re: [Solved]Category with only one product
Posted: Mon Jul 16, 2012 2:54 am
by Meshach
-- removed
Re: Category with only one product
Posted: Wed Nov 07, 2012 7:22 pm
by spitos
uksitebuilder wrote:Sorry for the delay on this guys
edit: catalog/controller/product/category.php
Find:
Code: Select all
foreach ($results as $result) {
if ($result['image']) {
Replace with:
Code: Select all
foreach ($results as $result) {
if($product_total == 1){
$this->redirect($this->url->link('product/product', 'product_id='.$result['product_id']));
}
if ($result['image']) {
When I applied this and the redirect was used, the breadcrumb trail was lost so I made a change to the redirect line to keep the breadcrumb trail on the product page.
Find:
Code: Select all
foreach ($results as $result) {
if ($result['image']) {
Replace with:
Code: Select all
foreach ($results as $result) {
if($product_total == 1){
$this->redirect($this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id']));
}
if ($result['image']) {
Re: [Solved]Category with only one product
Posted: Thu Nov 22, 2012 1:42 am
by carefree
I tried this approach and it works really well except I am still missing one thing. I have 10 or less products per main category, so I made a main category, then sub categories that are named the same thing as the product name. Then for each product, I linked it to both the main category and the sub category that it is named after. Then I changed the code on the category.php file as per the instructions above.
The result:
When I go to the main category, I get a description of the category, with all the products listed below in grid form. I also see the main category on the left side bar and below it is a list of all the products (sub categories) that I can click on.
What is wrong:
When I click on a product the categories go back the way they were (only displays the main category, no sub categories).
What I want:
I want the code that will make the subcategories show up on every product page that is within the main category so that no matter what product you are looking at, you can switch to another product within that same category without going back to the first page.
Does this make sense?

I need the template name and the code to replace. Seems like it shouldn't be too hard I hope.
Thanks in advance!
Re: [Solved]Category with only one product
Posted: Thu Dec 20, 2012 12:29 am
by mlvitor
Great spitos!
That was a really nice solution! Thanks a lot!
Re: [Solved]Category with only one product
Posted: Sun Jan 20, 2013 6:12 am
by HorseMagic
I tried this approach and it works really well except I am still missing one thing. I have 10 or less products per main category, so I made a main category, then sub categories that are named the same thing as the product name. Then for each product, I linked it to both the main category and the sub category that it is named after. Then I changed the code on the category.php file as per the instructions above.
The result:
When I go to the main category, I get a description of the category, with all the products listed below in grid form. I also see the main category on the left side bar and below it is a list of all the products (sub categories) that I can click on.
What is wrong:
When I click on a product the categories go back the way they were (only displays the main category, no sub categories).
What I want:
I want the code that will make the subcategories show up on every product page that is within the main category so that no matter what product you are looking at, you can switch to another product within that same category without going back to the first page.
Does this make sense?
I need the template name and the code to replace. Seems like it shouldn't be too hard I hope.
Thanks in advance!
Just wondering if anyone found/knows of a solution for sub categories, it sounds like it is only for categories?
Re: [Solved]Category with only one product
Posted: Sat Mar 30, 2013 5:14 am
by gotzon.ibarra
harleybill wrote:Is there a way to skip the category page and go straight to the product page on categories that have only one product.
My problem was I did not want to use the category view as I have very few products and cd not configure the category.tpl the way I wanted.
This may be an over-simplistic solution, but what I did was:
1) Build a new Banner though with store admin. This allows to add a link for each product e.g.
index.php?route=product/product&product_id=52
2) Go to Extensions > Modules and enable 'Carousel' and select the banner just created
3) Eliminate to Menu Bar from header.tpl
Re: [Solved]Category with only one product
Posted: Sat Mar 30, 2013 11:36 am
by butte
One approach is to let a first category (lowest sort, pole position in the race) have no title (fill in some spaces or call it Uncategorized) and put the Product onesies there. Forcing it to load prior to any button click can be omitted or inserted.
Re: [Solved]Category with only one product
Posted: Wed Jun 19, 2013 4:59 pm
by santura
I tried to implement the code changes suggested above with vqmod, but the first line of the code to be replaced occurs twice in category.php.
Can anyone tell me how to do this?
Re: [Solved]Category with only one product
Posted: Wed Jun 19, 2013 7:28 pm
by webvet
Santura
In your <search> tag for this line use the "index" function:
for example the following code replaces the first instance of the line:
Code: Select all
<search position="replace" index="1"><![CDATA[
if ($result['image']) {
]]></search>
Use index="2" to replace the second instance of the same line.
This is a useful guide to writing code for vQmods
http://code.google.com/p/vqmod/wiki/Scripting
Re: [Solved]Category with only one product
Posted: Wed Jun 19, 2013 10:45 pm
by santura
Beautiful - Thanks
Re: [Solved]Category with only one product
Posted: Mon Apr 06, 2015 5:58 am
by j@nnik.dk
Hallo, I'm looking for a solution like this, but I'm using OC 2.x
Is there a way to add code like this in OC 2.x to get the same function, if only one product i category:
foreach ($results as $result) {
if($product_total == 1){
$this->redirect($this->url->link('product/product', 'product_id='.$result['product_id']));
}
if ($result['image']) {
Please help :-)
Thanks, Jannik