cancel
Showing results for 
Search instead for 
Did you mean: 

Get All Manufacturers that have Enabled products online (phtml)

SOLVED

Get All Manufacturers that have Enabled products online (phtml)

I'm creating a brand page with logos and links manufacturer advanced search results ATM I'm stuck as all manufacturers are displaying

ideally i would like to filter and not show any manufacturers that don't have enabled products
any tips?

What I've got so far

<?php

    $om = \Magento\Framework\App\ObjectManager::getInstance();

    $attribute = $om->get(\Magento\Catalog\Api\ProductAttributeRepositoryInterface::class)->get('manufacturer');
    foreach ($attribute->getOptions() as $option)
    {
        echo '<div><a href="https://store.com/catalogsearch/advanced/result/?manufacturer=' . $option->getValue() . '"><img onerror="this.onerror=null;this.src=\'https://store.com/default.png\';" src="https://store.com/logos/' . $option->getLabel() . '.png"></a>';
        echo '<a href="https://store.com/catalogsearch/advanced/result/?manufacturer=' . $option->getValue() . '"><span>' . $option->getLabel() . '</span></a></div>';
    }
?>

 

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Get All Manufacturers that have Enabled products online (phtml)

Hi @romans_polevecko,

Did it work for you?

View solution in original post

4 REPLIES 4

Re: Get All Manufacturers that have Enabled products online (phtml)

Hi @roman_polevecko,

You can get manufacturer using following code for active products.  Then you use manufacturer array for further filter. 

 

<?php

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$productCollection = $objectManager->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');

$collection = $productCollection->create()
            ->addAttributeToSelect('manufacturer')
	    ->addAttributeToFilter('status', array('eq' => 1))
            ->load();

$manufacturer_array = $collection->getColumnValues('manufacturer');
?>


I have not tested this code. 

I hope it will work for you!

Re: Get All Manufacturers that have Enabled products online (phtml)

Thank you.

I think I'm getting the idea now.
But the code isn't doing exactly what I'm needing Smiley Sad

if i use

array('eq' => 1))

i get array of 393 items

if i use

array('eq' => 2))

i get array(0) { }

which can't be true as i know there are plenty of manufacturers on the store that don't have any enabled products atm

Re: Get All Manufacturers that have Enabled products online (phtml)

Mgaento save data in database table.

1-> enable
2-> disable

Please check active product count once in magento2 admin product grid.

If there are mismatch then use store_id as well in product collection.

I hope it will help you!

Re: Get All Manufacturers that have Enabled products online (phtml)

Hi @romans_polevecko,

Did it work for you?