5

I would like to display the product SKU on the category pages.

I managed to plant it in the short description on every product page using:

<div class="std">
      <h5><?php echo $this->__('Product Code: ') . $this->htmlEscape($_product->getData('sku'));?></h5>
 </div>

this was on view.phtml

If i apply the same code inside list.phtml it displays on site "Product Code:" but no actual SKU number.

I am placing it just below:

<?php if ($gc['display_price'] == 1) echo '<div class="display-onhover">'; ?>
                    <?php echo $this->getPriceHtml($_product, true); ?>
                <?php if ($gc['display_price'] == 1) echo '</div>'; ?>
2

4 Answers 4

4

In Magento if we are working with the custom HTML integration then we want to display the products SKU on the product listing page as well as on the Product description page as by default it is not displayed in Magento frontend. It is very easy to display the product SKU on the frontend.

Diaplay SKU On The Product Listing Page.

Step 1. Navigate to the /app/design/frontend/default/your_custom_template/template/catalog/product/list.phtml or Navigate to the /app/design/frontend/base/default/template/catalog/product/list.phtml open the file in the editor of your choice.

Step 2. Add the code below in the appropriate position where you want to display the SKU

<?php echo nl2br($_product->getSku()) ?>

<?php echo $this->htmlEscape($_product->getSku()) ?>

<?php echo $sku = Mage::getModel('catalog/product')->load($_product->getId())->getSku();?>

Now refresh the browser cache and you have done.

5

Step 1. Navigate to the /app/design/frontend/default/your_custom_template/template/catalog/product/list.phtml or Navigate to the /app/design/frontend/base/default/template/catalog/product/list.phtml open the file in the editor of your choice.

Step 2. Add the code below in the appropriate position where you want to display the SKU .

<?php echo nl2br($_product->getSku()) ?>
<?php echo  $this->htmlEscape($_product->getSku()) ?>

try this another code:-

 <?php
   productCollections=$_category->getProductCollection()->addAttributeToFilter('type_id','configurable');
 foreach($productCollections as $p)
{
 echo $p->getSku();
 }
 ?>
4
  • Thank you @Ashvin Monpara! Some of the products titles drop down onto 2 lines, therefore the product SKU's are not always in-line. How can I make them always inline? just above the add to cart button??? I will add an image if I can to the original post to show you what I mean. Thanks Commented Jul 9, 2015 at 9:26
  • frinds nathan smith try this another code.... Commented Jul 9, 2015 at 9:35
  • 3
    product load again is very bad idea.. you need to remove =Mage::getModel('catalog/product')->load($_product->getId())->getSku(); from there code...
    – Amit Bera
    Commented Jul 9, 2015 at 9:36
  • again a copy : my-whiteboard.com/display-sku-and-image-magento-shopping-cart Commented Jul 15, 2015 at 3:50
4

To get the sku, you need to place this for both grid and list mode

$_product->getSku();
4

Try this,hope it's work.

    <?php 
        $current_product = Mage::registry('current_product');
        if($current_product) {
            $sku = $current_product->getSku();
            // output sku
            echo $sku;
        } 
     ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.