7

I'm in Magento2 and the getDescription(); does not work.

I'm in the file Magento_Catalog/templates/product/list.phtml if that's relevant.

  • I want show description in additional div after tabs section on product page, how can i achieve this. Please help, Thanks in advance. – Dnyaneshwar Chavan Aug 14 at 11:24
15

In Store > Attributes > Product > Description > Storefront Properties set Visible on Catalog Pages on Storefront and Used in Product Listing to TRUE.

In your code list.phtml you can use:

<?php echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($_product, $_product->getDescription(), 'description') ?>

or

<?php echo $_product->getDescription() ?>
1

It should work fine..

<?php echo $_product->getDescription(); ?>
  • please check out the accepted answer. you answer is redundant and is missing important parts – Philipp Sander Aug 14 at 7:39
1

Try this:

$productCollection = $this->helper('\Magento\Catalog\Model\ProductFactory');

$product = $productCollection->create()->load($id);

$description = $product->getDescription();

  • Hi and welcome to stackoverflow! you're answer does exactly what mine does. – Philipp Sander Nov 12 '18 at 9:28
  • You helped me with $description = $product->getDescription(); – BraDev Oct 17 at 12:09
0

See /vendor/magento/module-catalog/view/frontend/templates/product/view/description.phtml

/**
 * Product description template
 *
 * @var $block \Magento\Catalog\Block\Product\View\Description
 */
?>
<?php /* @escapeNotVerified */ echo $this->helper('Magento\Catalog\Helper\Output')->productAttribute($block->getProduct(), $block->getProduct()->getDescription(), 'description') ?>
  • I already tried that. It's not working. If you have a look at the class of the object that returned by getProduct you will see, that there's no getDescription() – Philipp Sander Apr 6 '16 at 8:22
  • getDescription should be a magic method, where the string after "get" is the attribute name – ahnbizcad Sep 12 '16 at 4:26
  • Doesn't care if its not in the object, thus not a magic getter. :) – Max Oct 26 '17 at 18:15

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.