Would it be possible to have a list_in_stock function added to the core similar to list_on_sale? Trying to have a page that lists only in stock items sorted by category and paginated.
Thanks
Page 1 of 1
list_in_stock
#2
Posted 19 April 2012 - 02:28 PM
Hi,
Shop_Product::apply_filters() applies the availability filter, so you can fetch all products in stock as follows:
As you need to sort products by category, you should add JOINs for category tables and then render the standard product list. You will need to extend the product list partial to output category names if the current product category doesn't match the previous product category.
I hope this helps,
Thanks
Shop_Product::apply_filters() applies the availability filter, so you can fetch all products in stock as follows:
<? $products_in_stock = Shop_Product::create()->apply_filters()->find_all() ?>
As you need to sort products by category, you should add JOINs for category tables and then render the standard product list. You will need to extend the product list partial to output category names if the current product category doesn't match the previous product category.
<?
$products = Shop_Product::create()->apply_filters();
$products->join('shop_products_categories', 'shop_products_categories.shop_product_id=shop_products.id');
$products->join('shop_categories', 'shop_products_categories.shop_category_id=shop_categories.id');
$products->group('shop_products.id');
$products->order('shop_categories.name');
$this->render_partial(
'shop:product_list', array(
'products'=>$products,
'paginate'=>true,
'pagination_base_url'=>root_url('test'), // Assuming that your page URL is /test
'page_index'=>$this->request_param(-1, 0),
'records_per_page'=>5
));
?>I hope this helps,
Thanks
Share this topic:
Page 1 of 1

Help












