Jump to content

New products controller for specific category


Recommended Posts

I want to change NewProductsController.php to get products from specific category.

 

I have copied the file to /override/controllers/front folder but I don't know what to do.

 

I want to get the category ID (and use the subcategories also) using GET variables from a custom link and filter the products of this category/subcategories.

 

eg. www.mysite.com/new-products?cg=3

 

I don't want to change the Product class, so I want to take the array

'products' => Product::getNewProducts($this->context->language->id, (int)($this->p) - 1, (int)($this->n), false, $this->orderBy, $this->orderWay),

 

and create a new array only with the products in category 3 (cg=3) and all subcategories.

 

Is this possible?

 

Thanks!!

  • Like 1
Link to comment
Share on other sites

  • 3 months later...

Right now, I currently switch the "New Products Block" into specific products.

 

To do so, you have to change the function getNewProducts in "classes/Products.php".

 

From (in Line 2014):

WHERE product_shop.`active` = 1

Into:

WHERE (product_shop.`active` = 1 AND product_shop.`id_category_default`=2)

And in line: 2044

$sql->where('product_shop.`active` = 1')

change to:

$sql->where('product_shop.`active` = 1 AND product_shop.`id_category_default` = 2');

Therefore, the New products will show all products which default category is 2. 

 

Forgot to mention, my prestashop version is 1.5.6.

Edited by linyinlu (see edit history)
Link to comment
Share on other sites

  • 2 weeks later...

Hi,

Is it possible to define a category but not a default category ?

I try to join table ps_category_product but it don't find the best solution.

Change the structure of the table, add a column "New_Products_Category" and changes the code accordingly? It may useful. But please remember to backup your database before you made any changes.

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