Jump to content

Display new products only of a certain category


Recommended Posts

Hi

 

I'm pretty new in Prestashop (developing since June) and for a shop in Prestashop (1.5.6) I have some categories:

 

Category 1

 Subcat 1.1

 Subcat 1.2

 ...

 

Category 2

 Subcat 2.1

 Subcat 2.2

 

Etc.

 

Is it posible, with a free or payed module, to display only the new products of a certain category (for example, in the page of a category, show the new products in it)? With the standard option all of them come together but I'd like to get them filtered by category.

 

I've been searching this and other fórums with no clues and it's strange because it's not a weird thing from my point of view. I installed and configured the Layered Navigation Block but it cannot filter by new products.

 

Thanks a lot in advance.

Link to comment
Share on other sites

  • 3 weeks later...
  • 8 months later...

good idea. thanks.

You can add        AND product_shop.`id_category_default` = '.$id_category.'

 

in getNewProducts   function

or create a new function like getNewProductsByCategory with a base of getNewProducts

where:

 

if (Group::isFeatureActive())
            $sql->where('p.`id_product` IN (
                SELECT cp.`id_product`
                FROM `'._DB_PREFIX_.'category_group` cg
                LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
                WHERE cg.`id_group` '.$sql_groups.'
                AND product_shop.`id_category_default` = '.$id_category.'
            )');

 

 

 

Thanks

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

there is a cleaner way to do this without using sql

 

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)

$category = new Category((int)$id, (int)$id_lang);
if (Validate::isLoadedObject($category)) {
   $categories[$item]['id'] = $item;
   $categories[$item]['name'] = $category -> name;
   $categories[$item]['products'] = $category -> getProducts($id_lang, 1, ($nb ? $nb : 10), 'date_add','DESC');
   if(method_exists('Product','getProductsImgs'))
   {
      $image_array=array();
      for($i=0;$i<count($categories[$item]['products']);$i++)
      {
         if(isset($categories[$item]['products'][$i]['id_product']))
            $image_array[$categories[$item]['products'][$i]['id_product']]= Product::getProductsImgs($categories[$item]['products'][$i]['id_product']);
      }
      $categories[$item]['productimg'] = (isset($image_array) AND $image_array) ? $image_array : NULL;
   }
}
Link to comment
Share on other sites

  • 10 months later...

 

there is a cleaner way to do this without using sql

 

public function getProducts($id_lang, $p, $n, $order_by = null, $order_way = null, $get_total = false, $active = true, $random = false, $random_number_products = 1, $check_access = true, Context $context = null)

$category = new Category((int)$id, (int)$id_lang);
if (Validate::isLoadedObject($category)) {
   $categories[$item]['id'] = $item;
   $categories[$item]['name'] = $category -> name;
   $categories[$item]['products'] = $category -> getProducts($id_lang, 1, ($nb ? $nb : 10), 'date_add','DESC');
   if(method_exists('Product','getProductsImgs'))
   {
      $image_array=array();
      for($i=0;$i<count($categories[$item]['products']);$i++)
      {
         if(isset($categories[$item]['products'][$i]['id_product']))
            $image_array[$categories[$item]['products'][$i]['id_product']]= Product::getProductsImgs($categories[$item]['products'][$i]['id_product']);
      }
      $categories[$item]['productimg'] = (isset($image_array) AND $image_array) ? $image_array : NULL;
   }
}

Could you please let me know how to access this ? I mean, the function should be placed inside /classes/Category.php as far as I can see, but what will be the link to send the inquired category? http://mysite.com/26-socks/?selected_filters=new-products - something like that ? Thanks.

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

  • 5 months later...

hi Profs..

 

 

i have market website ,have many kind of products ,forexample selling game and home appliances too...but home appliances are showing on game category also :D its being weird like this

 

is there possible to show the new products belong to same category?

 

 

Best Regards

Ps3z

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

×
×
  • Create New...