0

I want to display attribute(sku) on product listing page in magento 2.3.2. I have tried to code on list.phtml file under public_html/vendor/magento/module-catalog/view/frontend/templates/product with no success. Please inform name and location of file where I need to code.

In magento 1.9.4 I can code in list.phtml file located under public_html/app/design/frontend/rwd/default/template/catalog/product to achieve result.

But In Magento 2.3.2 coding in list.phtml file located under public_html/vendor/magento/module-catalog/view/frontend/templates/product is not working.

Can anyone please let me know where & how to code to display attribute sku on product listing page(catalogue page) in magento 2.3.2

thanks,

1
  • I already have enabled attribute(sku) visibility from backend to display in frontend. I want to get displayed sku value below price value in category page.
    – Paresh
    Aug 18, 2019 at 9:12

2 Answers 2

0

Step 1: You need to create a custom theme that inherits from Luma theme to override the file correctly.

app/design/frontend/{vendor_namespace}/{theme_name}/registration.php

<?php
\Magento\Framework\Component\ComponentRegistrar::register(
    \Magento\Framework\Component\ComponentRegistrar::THEME,
    'frontend/{vendor_namespace}/{theme_name}',
    __DIR__
);

app/design/frontend/{vendor_namespace}/{theme_name}/theme.xml

<theme xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Config/etc/theme.xsd">
    <title>Your Custom Theme</title>
    <parent>Magento/luma</parent>
</theme>

Step 2: Now Override the vendor/magento/module-catalog/view/frontend/templates/product/list.phtml file.

app/design/frontend/[Vendor]/[Theme]/Magento_Catalog/templates/product/list.phtml

<?php SKU : echo ($_product->getSku() ?>
2
  • Yes I have created a custom theme that inherits from Blank theme. There were 2 3rd party theme - that I have removed and now it is displaying - perfectly.
    – Paresh
    Aug 19, 2019 at 11:39
  • Paresh, If you find my answer useful then please accept this as an answer. Aug 19, 2019 at 12:13
0

For fresh installation product listing template for category page is :

vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

Now you check under your active theme. If you installed a theme without composer then location should be:

app/design/frontend/[YourVendorName]/[YourThemeName]/Magento_Catalog/templates/product/list.phtml

If not working then looking for inside your custom module where this template overwrite.

Note: SKU attribute Used in Product Listing property should be yes. enter image description here

[Update]

I enable Used in Product Listing property for SKU, then added following line in list.phtml

SKU : <?= $_helper->productAttribute($_product, $_product->getSku(), 'sku') ?>

Now looks like: enter image description here

Don't forget to clear cache.

9
  • if I code like ..... <h3><?php echo $this->__('SKU:') . $this->htmlEscape($_product->getData('sku'));?></h3> .... in vendor/magento/module-catalog/view/frontend/templates/product/list.phtml will it displayed in case of luma theme....???
    – Paresh
    Aug 18, 2019 at 9:19
  • yes. Also, check the updated answer.
    – Sohel Rana
    Aug 18, 2019 at 9:27
  • I already have enabled attribute(sku) visibility from backend to display in frontend. I want to get displayed sku value below price value in category page.
    – Paresh
    Aug 18, 2019 at 9:29
  • Below code I have used in list.phtml file </strong> <?= $block->getReviewsSummaryHtml($_product, $templateType) ?> <?= /* @escapeNotVerified */ $block->getProductPrice($_product) ?> <?= $block->getProductDetailsHtml($_product) ?> <h3><?php echo $this->__('SKU:') . $this->htmlEscape($_product->getData('sku'));?></h3> But sku not displyed below price line in category page. ????
    – Paresh
    Aug 18, 2019 at 9:34
  • Check updated answer.
    – Sohel Rana
    Aug 18, 2019 at 9:42

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.