Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • 'is_in_stock' or inventory filter in product collection in magento

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 10.8k
    Comment on it

    Below code will return you the products of a category that have status 'Enable' , Visibility 'catalog,search' and Stock Availability ' In stock'.

    $productDetails    = Mage::getModel('catalog/category')->load($cat_id)
                              ->getProductCollection()
                              ->addAttributeToSelect('*');
    
    $productDetails -> addAttributeToFilter('visibility', array('in' => array(4) ));
    $productDetails -> addAttributeToFilter('status', array('in' => array(1) ));
    $productDetails->joinField('is_in_stock',
                    'cataloginventory/stock_item',
                    'is_in_stock',
                    'product_id=entity_id',
                    'is_in_stock=1',
                    '{{table}}.stock_id=1',
                    'left');        
    

 2 Comment(s)

  • We have recently updated one of our extension for Magento designed to improve magento product filters. Now you can filter products at catalog and search results pages by stock http://potatocommerce.com/sales-new-stock-filters-for-layered-navigation-amasty-improved.html

  • i was having a complex script that i needed to extract all the configurable products filtered by colors and get the size for each one but only those with stock.
    This did the trick,,

    Thank you
Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: