Frage

How can I check if any of the cross sell items are in stock in our Magento 1 store?

I want to load some php if rule, that only display a text line, if any of the cross sell items are in stock.

My current foreach code:

<?php foreach($this->getItems() as $_item): ?>
<?php $productqty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getQty(); ?>

<?php if ($productqty > 0):?>
War es hilfreich?

Lösung

You need to do the code like this one :

    $product = Mage::registry('product');

    $productcrosscol = $product->getCrossSellProductCollection()
              ->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
                ->setPositionOrder()
                ->addStoreFilter();

    Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($productcrosscol);

    $productcrosscol->load();
    $isruleshow = 0;
    foreach ($productcrosscol as $product) {
        $productqty = (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getQty(); 
        if ($productqty > 0) {
            $isruleshow = 1;
            break;
        }
    }

    if($isruleshow) :
       //PRINT YOUR RULE HERE
    endif;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top