1

I have a yes/no product attribute set in my backend for all the products.

What i tried to do, is to get for every product the set value in a phtml and i can't.

I tried like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
    $_product = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId());
    $special = $_product->getAttributeText('special_label');
    var_dump($special);

and i received something weird :

object(Magento\Framework\Phrase)#2564 (2) { ["text":"Magento\Framework\Phrase":private]=> string(3) "Yes" ["arguments":"Magento\Framework\Phrase":private]=> array(0) { } }

Even i don't have set anything to yes, i receive only "yes" for my all products.

What i am doing wrong?

5
  • return $special or echo $special it will display yes. you are using display var_dump so it display including type and object. Sep 7 '17 at 13:40
  • the same. i receive only yes Sep 7 '17 at 13:41
  • okey i understand Sep 7 '17 at 13:44
  • @alin, have you got solution ?
    – Pawan
    Sep 7 '17 at 16:56
  • yes @Pawan, see the answer: for my was working with this one $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $_product = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId()); $specialLabel = $_product->getData('special_label'); Sep 8 '17 at 11:10
4
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$_product = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId());
$specialLabel = $_product->getSpecialLabel();

OR

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); 
$_product = $objectManager->get('Magento\Catalog\Model\Product')->load($_product->getId());
$specialLabel = $_product->getData('special_label');

It will return boolean value for Yes/NO. "1" means "Yes" and "0" means "No"

Note: Please make sure that you are getting correct product ID.

0

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.