Reputation: 602
Here is what I have so far, to get IN STOCK items:
$productCollection = Mage::getModel('cataloginventory/stock_item')
->getCollection()
->addQtyFilter('>', 0);
echo $productCollection->getSelect();
foreach ( $productCollection as $currentProduct ) {
$categoryIds = $currentProduct->getCategoryIds();
print_r( $categoryIds );
}
It gets the products just fine, however I need to get each item's current category ID's, so in the above code $currentProduct->getCategoryIds()
isn't working.
Does anyone has an idea how can I retrieve IN STOCK items along with it's category ID's?
Thank you.
Upvotes: 0
Views: 1621
Reputation: 680
You can try this sample of code:
...
foreach ( $productCollection as $currentProduct ) {
$categoryIds = Mage::getModel('catalog/product')->load($currentProduct->getId())
->getCategoryIds();
print_r( $categoryIds );
}
Upvotes: 2
Reputation:
This appears to have already been answered here.
Please see the following urls on how to retrieve the products category ID:
Magento category ID from product ID
Get product's category ids and names
You can check if it is in stock with the following if statement
:
<?php
$__manStock = $_product->getStockItem()->getManageStock();
$__invAmt = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_product)->getQty();
if ($__invAmt >= 1)
{
//Do Something here
}
?>
And even:
<?php if ($_product->isAvailable()): ?>
Do Something here
<?php endif; ?>
Upvotes: 0