0

I have added a widget to my cms page which shows products of the category.

{{widget type="Magento\CatalogWidget\Block\Product\ProductsList" title="BREAKFAST" show_pager="0" products_count="10" template="Magento_CatalogWidget::product/widget/content/grid.phtml" conditions_encoded="^[`1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Combine`,`aggregator`:`all`,`value`:`1`,`new_child`:``^],`1--1`:^[`type`:`Magento||CatalogWidget||Model||Rule||Condition||Product`,`attribute`:`category_ids`,`operator`:`==`,`value`:`3`^]^]"}}

Product show name, price, image, but it does not show description of Products. this file is used there.

  app\design\frontend\Smartwave\porto_child\Magento_CatalogWidget\templates\product\widget\content\grid.phtml 

and here is the code of this grid.phtml file

    <?php
/**
 * Copyright © 2015 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Template for displaying products list widget
 *
 * @var $block \Magento\CatalogWidget\Block\Product\ProductsList
 */
?>
<?php if ($exist = ($block->getProductCollection() && $block->getProductCollection()->getSize())):?>
<?php
$_productCollection = $block->getLoadedProductCollection();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');

$_category_config = $this->helper('Smartwave\Porto\Helper\Data')->getConfig('porto_settings/category');
$_category_grid_config = $this->helper('Smartwave\Porto\Helper\Data')->getConfig('porto_settings/category_grid');
?>
<?php
    $type = 'widget-product-grid';

    $mode = 'grid';

    $image = 'new_products_content_widget_grid';
    $hover_image = 'category_page_grid-hover';
    $title = $block->getTitle() ? __($block->getTitle()) : '';
    $items = $block->getProductCollection()->getItems();
    //print_r($items);exit;

    $showWishlist = true;
    $showCompare = true;
    $showCart = true;
    $templateType = \Magento\Catalog\Block\Product\ReviewRendererInterface::DEFAULT_VIEW;
    $description = true;

    $image_width = ($_category_config['ratio_width'])?$_category_config['ratio_width']:300;
    $image_height = ($_category_config['ratio_height'])?$_category_config['ratio_height']:300;
?>
        <?php if ($title):?>
            <div class="col-sm-6 p-l">
                <h2><?php /* @escapeNotVerified */ echo $title; ?></h2>
            </div>
        </div>
        <div class="col-lg-9">
        <?php endif ?>
            <?php $iterator = 1; ?>
            <?php foreach ($items as $_item): ?>
            <!--  -->
                <div class="col-sm-6 p-l">
                    <div class="img-box">
                        <a href="<?php echo $_item->getProductUrl() ?>" class="product-modal-btn product-modal-btn-top">
                            <div class="img-box-outer">
                                <?php
                                if($_category_config['aspect_ratio'])
                                $productImage = $_imagehelper->init($_item, $image)->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize($image_width);
                                else
                               $productImage = $_imagehelper->init($_item, $image)->resize($image_width, $image_height);
                               $productImageUrl = $productImage->getUrl();
                                ?>
                                <img src="<?php echo $productImageUrl?>" alt="<?php echo $productImage->getLabel(); ?>">
                            </div>
                        </a>
                        <div class="text-box">
                            <h3><?php echo $block->escapeHtml($_item->getName())?></h3><span><?php echo $block->getProductPriceHtml($_item, $type)?></span>
                            <p><?php echo $block->escapeHtml($_item->getDescription())?></p>
                        </div>
                    </div>
            </div>
            <!--  -->
            <?php endforeach ?>
    <?php echo $block->getPagerHtml()?>
<?php endif;?>

if the 9th last line you can see i am using escapeHtml($_item->getDescription())?> which is showing nothing. Can you provide me the code which will show description here.

1
  • try with - var_dump($_item); to check which data you get in array. – Anas Mansuri Aug 23 '19 at 10:23
0

This piece of code worked for me in showing Description of Product.

<?php echo $block->escapeHtml($_item->getShortDescription())?>

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.