3

I want to display description on the product listing page of Wishlist.

Facing the Fatal error:

Fatal error: Class 'Satish\Wishlist\Block\Description' not found in /home/decure/public_html/test/var/generation/SatishWishlist/Block/Description/Interceptor.php on line 7

description.php file in block

<?php

namespace Satish\Wishlist\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();
    }
}
  • 1
    please share Satish\Wishlist\Block\Description file and have you run php bin/magento setup:di:compile command? – kunj Aug 11 '18 at 5:29
  • 1
    Satish\Wishlist\Block\Description Incompatible argument type: Required type: \Magento\Catalog\Block\Product\Context. Actual type: \Magento\Framework\View\Element\Template\Context; File: /home/decure/public_html/test/app/code/Satish/Wishlist/block/description.php – 55840 Aug 11 '18 at 5:38
  • @kunj I edited question with description.php block file – 55840 Aug 11 '18 at 5:45
  • I have added answer hope it will help. – kunj Aug 11 '18 at 6:05
  • If that answer helped you then please accept it so it will help to others. – kunj Aug 11 '18 at 8:38
1

Try this:

<?php
namespace Satish\Wishlist\Block;
class Description extends \Magento\Wishlist\Block\Customer\Wishlist\Item\Column\Info{
    protected $_productloader;
    public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Magento\Framework\App\Http\Context $httpContext,
        \Magento\Catalog\Model\ProductFactory $_productloader
    ) {
        $this->_productloader = $_productloader;
        parent::__construct($context,$httpContext);
    }
    public function getDescription()
    {
        $id = $this->getItem()->getProduct()->getId();
        $product = $this->_productloader->create()->load($id);
        return $product->getDescription();
    }
}
?>

Actually, your last parent block is Magento\Wishlist\Block\AbstractBlock

below is it's construct method.

public function __construct(
        \Magento\Catalog\Block\Product\Context $context,
        \Magento\Framework\App\Http\Context $httpContext,
        array $data = []
    ) {
        $this->httpContext = $httpContext;
        parent::__construct(
            $context,
            $data
        );
    }

your XML code should be like this:

        <referenceContainer name="customer.wishlist.items">
       <block class="Satish\Wishlist\Block\Description" name="customer.wishlist.item.description" template="Satish_Wishlist::item/column/description.phtml" cacheable="false"/>
    </referenceContainer>

And in that description.phtml the code should be as below.

<strong class="product-item-description">
    <?php echo $block->getDescription() ?>
</strong>
  • Same Fatal Error . I am not used the second construct method. after replace the description php file code. now no Compilation error . – 55840 Aug 11 '18 at 6:29
  • @ssatish4u, yes, you just need to put my updated code which is done in your, after that you will need to runphp bin/magento setup:di:compile – kunj Aug 11 '18 at 6:46
  • 1
    Done changes magento.stackexchange.com/questions/199967/… I've used this url to achieve this – 55840 Aug 11 '18 at 9:28
  • 1
    wishlist product listing coming without decription - without error – 55840 Aug 13 '18 at 6:49
  • 1
    we.tl/uudr8zKiwl download the module – 55840 Aug 13 '18 at 11:09

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.