0

I am trying to hide the out of stock products from my homepage. I want them to display everywhere else but not in this widget. Hiding from admin configuration is not the solution. How can i achieve this?

I am using typologancee theme. Widget i am using is "Home 02 - Collection Product", which has random, latest products. Image showing product collection in my widget I am not very sure where to make changes and what changes.

Any help is appreciated, thanks.

PЯINCƎ
11.8k3 gold badges27 silver badges85 bronze badges
asked Aug 1, 2017 at 22:18

1 Answer 1

0

If you are using a widget to diplay the products in your home page and you want hide the out of stock product only in this widget, you should create another widget with a custom collection.

Here we will do some collection who display products just who have One minimum quantity (1) and Not out of stock.

$productCollection = Mage::getModel('catalog/product')
 ->getCollection()
 ->addAttributeToSelect('*')
 ->joinField('qty',
 'cataloginventory/stock_item',
 'qty',
 'product_id=entity_id',
 '{{table}}.is_in_stock=1',
 'left')
 ->addAttributeToFilter('qty', array("gt" => 1))
 ->setCurPage(1) // limit to one page
 ->setPageSize(50); //limit to 50 products
foreach($productCollection as $product) { 
 if($product->getTypeId() == 'simple')
 echo $product->getName().'<br>';
 echo $product->getProductUrl().'<br>';
 // you can get the other data ...
}

Now you have to make all this so pretty.

answered Aug 1, 2017 at 23:31
3
  • i can't do it for products with 0 quantity? Commented Aug 2, 2017 at 21:40
  • The products with 0 qty is a product out of stock no ? Else you can update this ->addAttributeToFilter('qty', array("gt" => 0)) Commented Aug 2, 2017 at 23:45
  • So you got what you needed ? Commented Aug 4, 2017 at 18:38

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.