Add code

Showing posts with label drop down attributes. Show all posts
Showing posts with label drop down attributes. Show all posts

Friday 2 October 2020

Magento2: How to get list of category's dropdown attributes?

Let's say that `$category` is the instance of the current category;


    $collection = $category->getProductCollection()->addAttributeToSelect(['manufacturer', 'color']);

    $manufacturers = [];

    $colors = [];

    foreach ($collection as $product) {

        $manufacturer = $product->getData('manufacturer');

        if ($manufacturer && !isset($manufacturers[$manufacturer])) {

             $manufacturers[$manufacturer] = $product->getAttributeText('manufacturer');

        }

        $color = $product->getData('color');

        if ($color && !isset($colors[$color])) {

             $colors[$color] = $product->getAttributeText('color');

        }

    }


after this, `$manufacutrers` and `$colors` should contain all the values you need. The key is the id, and the value is the option label.  

But this may cause performance issues if you have a large product collection.

Magento : 404 error is showing admin page

Hello, Sometimes we may get the error on admin page once done with the Magento installation. In that scenario, we have to do the following: ...