문제

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.

도움이 되었습니까?

해결책

You can try this sample of code:

...
foreach ( $productCollection as $currentProduct ) {
    $categoryIds = Mage::getModel('catalog/product')->load($currentProduct->getId())
        ->getCategoryIds();

    print_r( $categoryIds );
}

다른 팁

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; ?>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top