0

I have listed all brands to the main menu using below code and it gives all available brands.

$attributeId = Mage::getResourceModel('eav/entity_attribute')->getIdByCode('catalog_product','brand');
$attribute = Mage::getModel('catalog/resource_eav_attribute')->load($attributeId);
$attributeOptions = $attribute->getSource()->getAllOptions();

But, now I wants to load only brands, which related products are is in stock(qty>=1) to the Main Menu.

So How could I do that?

Thanks.

0

The thing you are requesting is not that simple or 2-3 lines of code.

Here is the dazzy way to achieve this

  • Load class Magento/CatalogSearch/Model/Layer
  • method getProductCollection()
  • than get attributes from this collection
  • get your brand attribute model and its options

In this way all primary checks like enable/ disable, stock will be taken care of

| improve this answer | |
  • Thank you for your answer Yash. But I did'n get it. It will grateful if you could describe more about your answer please. Because , I'm new to magento & back-end development. I have tried like this ; but it doesn't give "brand".[$_productCollection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect(array('size','name','brand')) ->joinField( 'qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.is_in_stock=1', 'left') ->addAttributeToFilter('qty', array('gt' => 1));] – Ravi Feb 24 at 5:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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