0

I made this query to show related products by Manufacturer.

It works perfectly with simple products, but it shows configurable products that are not available.

I would like to show only available configurable products in that list.

$manu = $product->getManufacturer();
            $brand_name = $product->getAttributeText('manufacturer');
            $brand = Mage::getSingleton('catalog/product')
                ->getCollection()
                ->addAttributeToSelect('*')
                ->addAttributeToFilter('visibility', array(
                    Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH,
                    Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_CATALOG
                ))
                ->addAttributeToFilter('manufacturer', $manu)
                ->addAttributeToFilter('is_in_stock', 1)
                ->addAttributeToFilter('qty', array("gt" => 0))
                ->addAttributeToFilter('status', 1)
                ->setOrder('updated_at','DESC')
                ->setPageSize(5);
            Mage::getModel('cataloginventory/stock')->addInStockFilterToCollection($brand);


            if ($product) {
                $brand->addAttributeToFilter('entity_id', array(
                        'neq' => Mage::registry('current_product')->getId())
                );
            }

1 Answer 1

1

They are likely filtered out as the stock is not maintained on the configureable product level but on simple products level, ->addAttributeToFilter('qty', array("gt" => 0)) filters out such products. The solution would be to check if the following condition is true: $product->isSalable()

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.