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.
1 Answer 1
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.
-
i can't do it for products with 0 quantity?Coder anonymous– Coder anonymous2017年08月02日 21:40:39 +00:00Commented 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))2017年08月02日 23:45:10 +00:00Commented Aug 2, 2017 at 23:45
-
So you got what you needed ?2017年08月04日 18:38:07 +00:00Commented Aug 4, 2017 at 18:38
Explore related questions
See similar questions with these tags.