On the homepage, under “Best-Selling Products”, a product description needs to be added to the products. To do this, an override must be created. The template file that needs to be overridden is located at:
\app\design\frontend\template-name\default\Magento_CatalogWidget\templates\product\widget\content\grid.phtml
We can find the block that needs to be inserted under
\vendor\magento\module-catalog\view\frontend\templates\product\list.phtml
<?php if ($showDescription):?>
<div class="product description product-item-description">
<?= /* @escapeNotVerified */ $_helper->productAttribute($_product, $_product->getShortDescription(), 'short_description') ?>
<a href="/<?= /* @escapeNotVerified */ $_product->getProductUrl() ?>" title="<?= /* @escapeNotVerified */ $_productNameStripped ?>" class="action more"><?= /* @escapeNotVerified */ __('Learn More') ?>
</a>
</div>
<?php endif; ?>
Then the variable $_description must be changed to “true”.
$description = true;
$showDescription = true;
After inserting the block into the override, the homepage was no longer displayed correctly and an error appeared in var/log/exception.log:
Undefined variable: _helper…
Apparently, the variables we took from list.phtml are not defined in grid.phtml. In addition, the Product object is defined as $_item in grid.phtml:
<?php foreach ($_productCollection as $_product): ?>
<?php foreach ($items as $_item): ?>
Therefore, for the code from list.phtml to work in grid.phtml as well, all instances of $_product must be replaced with $_item.
Finally, the “Full Page” and “Block” caches must be cleared.
