2

I want to get description of product in wishlist Page, I tried this code In list.phtml file but no luck .

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

EDIT

my code now look like this

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_id=$this->getItem()->getProduct()->getId();
$product = $objectManager->create('Magento\Catalog\Model\Product')->load($product_id);
?>
<strong class="product-item-description">
    <?php echo $block->escapeHtml($product->getDescription()) ?>
</strong>
  • Where do you want to show the product description exactly? – Dinesh Yadav Nov 3 '17 at 13:03
  • @DineshYadav actually wherever wishlist appear with it, product description of this product aswell should occur – Learner Nov 3 '17 at 13:14
  • you have any idea @DineshYadav ? – Learner Nov 3 '17 at 14:13
2

To Display description in wishlist you have to follow below steps-

Create a new file description.phtml at location

vendor/magento/module-wishlist/view/frontend/templates/item/column/description.phtml

In description.phtml add below code

<?php 
$item = $block->getItem();
$product = $item->getProduct();
?>
<strong class="product-item-description">
    <?php echo $block->escapeHtml($product->getDescription()) ?>
</strong>

Now at path

vendor/magento/module-wishlist/view/frontend/layout/wishlist_index_index.xml

in this file add below code after customer.wishlist.item.name block

<block class="Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info" name="customer.wishlist.item.description" template="item/column/description.phtml" cacheable="false"/>

Note:- Do not change in core files, add in your theme directory

EDIT : proper way to load data

Create a new block file in your custom module at path

app/code/Namespace/Module/Block

<?php
namespace Namespace\Module\Block;

class Description extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info
{

  protected $_productloader;  


  public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Model\ProductFactory $_productloader

    ) {


        $this->_productloader = $_productloader;
        parent::__construct($context);
    }
    public function getDescription()
    {
        $id = $this->getItem()->getProduct()->getId();
        $this->_productloader->create()->load($id);
        return $product->getDescription();
    }

}

In layout file replace block class from Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info to Namespace\Module\Block\Description

After that in your template file you can get product description using below code

$block->getDescription();

To create a custom module you can follow this article

  • class is showing now in console but no data is showing – Learner Nov 3 '17 at 14:54
  • <strong class="product-item-description"> </strong> just this is showing in console – Learner Nov 3 '17 at 15:04
  • In the wishlist product object there is no description, so you may need to create a new block file and load product there – Piyush Nov 3 '17 at 16:49
  • 1
    Create a custom block and load product in it, then you can get product description in template file, check this answer to load product magento.stackexchange.com/a/94853 – Piyush Nov 3 '17 at 16:55
  • 1
    he is using static id , like 1 and 20 in example. in my case from where I will get id ? – Learner Nov 3 '17 at 17:05

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.