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>';
}
?>
Solved! Go to Solution.
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!
Thank you.
I think I'm getting the idea now.
But the code isn't doing exactly what I'm needing ![]()
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