Question

I'm having difficulty figuring out how to add a description to a Simple Product that will subsequently be displayed on the Simple Product Details Page. Everywhere I have looked discusses using code to handle this but like i said in my last post im new to magento and cannot figure out how to solve this issue with code solutions provided as they seem to gear towards more advanced developers.

Was it helpful?

Solution

To add product description in simple product only, you can follow below steps.

1) Create a catalog_product_view_type_simple.xml file in app/design/frontend/Vendor/Theme/Magento_Catalog/layout/catalog_product_view_type_simple.xml and paste below code in this file.

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="product.info.main">
            <block class="Magento\Catalog\Block\Product\View" name="product.description.simple" template="Magento_Catalog::product/view/type/simple/description.phtml" after="product.info.price"/>
        </referenceContainer>
    </body>
</page>

2) Create a description.phtml file in app/design/frontend/Vendor/Theme/Magento_Catalog/templates/product/view/type/simple/description.phtml and paste below code.

<?php
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$_product = $block->getProduct();
$_attributeLabel = $_product->getResource()->getAttribute('description')->getStoreLabel();
$_attributeValue = ($_helper->productAttribute($_product, $_product->getDescription(), 'description')) ? $_product->getAttributeText('description') : '';
?>
<?php if ($_attributeValue): ?>
    <div class="product-description">
        <strong class="type"><?= /* @escapeNotVerified */ $_attributeLabel ?></strong>
        <div class="value"><?= /* @escapeNotVerified */ $_attributeValue ?></div>
    </div>
<?php endif; ?>

3) Flush magento cache and check simple product in which you have added description in backend.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top