Piotr Kaczor Posted December 23, 2013 Share Posted December 23, 2013 Hello I'm using method getProducts from object Category to get random products, but I need only products with quantity greater than zero. How to achieve that? $category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id); $nb = (int)Configuration::get('HOME_FEATURED_RND_NBR'); $products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8)); Thank You for any advice Best regards Link to comment Share on other sites More sharing options...
PascalVG Posted December 24, 2013 Share Posted December 24, 2013 In the file classes/Category.php, copy the function GetProducts and change the name to getAvailableProducts or so. then add to the its SQL WHERE part something like this: WHERE product_shop.`id_shop` = '.(int)$context->shop->id.' AND cp.`id_category` = '.(int)$this->id .($active ? ' AND product_shop.`active` = 1' : '') .' AND stock.quantity > 0 ' .($front ? ' AND product_shop.`visibility` IN ("both", "catalog")' : '') .($id_supplier ? ' AND p.id_supplier = '.(int)$id_supplier : '') .' GROUP BY product_shop.id_product'; Save the file and use the new function to get the products with available quantity. Hope that helps. Merry Christmas!! pascal 2 Link to comment Share on other sites More sharing options...
Piotr Kaczor Posted December 25, 2013 Author Share Posted December 25, 2013 Thank You works well. Merry Christmas Link to comment Share on other sites More sharing options...
PascalVG Posted December 26, 2013 Share Posted December 26, 2013 Perfect, I'll mark it as solved. :-) pascal Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now