LemonStand Forum: list_in_stock - LemonStand Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

list_in_stock

#1 User is offline   tuttle425 

  • LemonFan
  • PipPipPipPipPip
  • Group: Members
  • Posts: 57
  • Joined: 12-July 11

Posted 18 April 2012 - 02:26 PM

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
0

#2 User is offline   Aleksey 

  • Co-Founder
  • Group: +Administrators
  • Posts: 4,066
  • Joined: 31-October 09

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:

<? $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

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users