Jump to content

[SOLVED] Show products from category X inside product page


doubleb

Recommended Posts

I have this code on product.tpl:


GIFTS
   {include file=$tpl_dir./product-list.tpl products=$cadouCategory}



How can i make product-list.tpl to show the products from category GIFTS? (let's say the category id = 8)
I want the page to list all products from that category or just 3-4 in random order.


Thanks in advance.

Link to comment
Share on other sites

Do you want all product pages to display the products from category 8? I suggest that you use the "Products category v1.2.1" module and then change lines 38-48 of modules/productscategory/productscategory.php from:

$product = new Product(intval($idProduct));

$category = new Category(1);
if (isset($params['category']->id_category))
   $category = $params['category'];
if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
   $category = New Category(intval($product->id_category_default));
if (!Validate::isLoadedObject($category))
   Tools::displayError('Bad category!');
if (intval($category->id_category) === 1)
   return;



to:

/*        $product = new Product(intval($idProduct));

       $category = new Category(1);
       if (isset($params['category']->id_category))
           $category = $params['category'];
       if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
           $category = New Category(intval($product->id_category_default));
       if (!Validate::isLoadedObject($category))
           Tools::displayError('Bad category!');
       if (intval($category->id_category) === 1)
           return;
*/
       $category = new Category(8);



This will display products from category 8 instead of from the same category as the current product. You can also go to Tools > Translations, select "Modules translations" in the dropdown, click a flag, then scroll down to "prestashop - productscategory" and then enter "Gifts" as the translation for "In the same category".

Link to comment
Share on other sites

  • 10 months later...

Hi rocky,

I have a flower shop and this is exactly what I was looking for. Still.. there is a problem.. I have a category for funerals, and to show a cake in that category is not a good idea.. how can I define an exception for that category?


Please help me.. :)

Link to comment
Share on other sites

Try the follow instead of the above code:

/*        $product = new Product(intval($idProduct));

       $category = new Category(1);
       if (isset($params['category']->id_category))
           $category = $params['category'];
       if ($category->id_category == 1 AND isset($product->id_category_default) AND $product->id_category_default > 1)
           $category = New Category(intval($product->id_category_default));
       if (!Validate::isLoadedObject($category))
*/            Tools::displayError('Bad category!');
       if (intval($category->id_category) === 1 OR intval($category->id_category) === 7)
           return;

       $category = new Category(8); 



Change 7 to the ID of the funeral category. That category will then not have the "In the same category" section displayed.

Link to comment
Share on other sites

  • 9 months later...

Hi,

I have a similar problem. I also have a flower shop. And I have two categories, flowers and gifts, both with multiple subcategories. I'd like to show on the product page of flowers a link to the gifts category and on the gifts products a link to the flowers .

Can you help me?

Thanks

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...