Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get dropdown attribute text - Magento 2

I am trying to retrieve the text value for the manufacturer attribute. It is a dropdown field. I tried this:

$manufacturerName = $_product->getAttributeText('manufacturer');
$manufacturerId = $_product->getManufacturer();

$manufacturerName should display "BrandName", but it always displays 1 even if I change the manufacturer. The $manufacturerId changes when I change the manufacturer.

I don't understand why the manufacturer name is not displayed correctly. Any ideas?

like image 838
Mihaela Avatar asked Dec 11 '22 06:12

Mihaela


1 Answers

I think you can check on this code:

$manufacturerName  = $_product->getAttributeText('manufacturer');
$manufacturerId  = $_product->getResource()->getAttribute('manufacturer')->setStoreId(0)->getFrontend()->getValue($_product);

https://magento.stackexchange.com/questions/62220/getattributetext-use-default-value-regardless-what-store-view-the-user-is-on

like image 157
Mage Wet Avatar answered Jan 05 '23 14:01

Mage Wet