Magento Forum

Page 1 of 3
Display SKU in frontend
 
ourmaninparis
Member
 
Avatar
Total Posts:  40
Joined:  2008-03-03
 

Hello,

I’d like to display the SKU reference number in the frontend. I thought I could configure this in attributes but it is not there. Anybody know how to do this?

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sankaman2k
Jr. Member
 
Total Posts:  13
Joined:  2008-01-22
 

I’m interested in knowing this myself.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sankaman2k
Jr. Member
 
Total Posts:  13
Joined:  2008-01-22
 

I figured it out.

Add the following to /app/design/frontend/default/default/template/catalog/product/view.phtml

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

This will display the sku on your product page.

 
Magento Community Magento Community
Magento Community
Magento Community
 
sherrie
Moderator
 
Avatar
Total Posts:  1655
Joined:  2007-12-14
Waterloo, ON
 

Excellent - thank you!!

 
Magento Community Magento Community
Magento Community
Magento Community
 
sdb
Sr. Member
 
Avatar
Total Posts:  223
Joined:  2007-11-13
coastal California, USA
 

i’m having problems getting this to work. could i get a hint as to where you placed it in your code / on your site as an example?

edit: bah, nevermind, disregard this idiot, i was editing the wrong file (must have double clicked incorrectly when i went to open it. everything works fine now.

 
Magento Community Magento Community
Magento Community
Magento Community
 
hondaspeder
Jr. Member
 
Total Posts:  29
Joined:  2008-05-08
 

Is there another way to do this without having to go into the code?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael R
Jr. Member
 
Total Posts:  8
Joined:  2008-08-04
 
hondaspeder - 21 August 2008 07:26 AM

Is there another way to do this without having to go into the code?

If you’re changing the templates, there’s really no way around changing the code for the template....

As the Magento developers recommend, you should copy the “default” theme directory into a new one, as some of these files get overwritten when you upgrade. Instead you should set it up as detailed here:
http://www.magentocommerce.com/design_guide/articles/working-with-magento-themes#head-how-to-create-a-theme

 
Magento Community Magento Community
Magento Community
Magento Community
 
benfrain.com
Sr. Member
 
Total Posts:  142
Joined:  2008-08-15
 

Well, this had been working for me with no problems. Now for some reason it’s stopped. Anybody else had this problem? The

<?php echo nl2br($_product->getSku()) ?>
line is still there in my file (and also re-uploaded to make sure!)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Bojan Hrnkas
Member
 
Total Posts:  51
Joined:  2008-04-15
 

@benfrain:

Did you do update lately? The updates rewrite the template files as well. What I do, is create custom theme and skin that hold files I’ve changed. That way magento update rewrites only original files and leaves my files untouched. There are several HowTos that explain how to create and use custom theme.

Hope this helps…

 
Magento Community Magento Community
Magento Community
Magento Community
 
benfrain.com
Sr. Member
 
Total Posts:  142
Joined:  2008-08-15
 

Hi Bojan, no I am using my own theme. That’s why I don’t understand how it could have changed??

 
Magento Community Magento Community
Magento Community
Magento Community
 
Bitterman
Jr. Member
 
Total Posts:  1
Joined:  2008-08-06
 

One of the things keeping it from working may be that the Magento code is more object orientated than before. The old code snippet may no longer work with a newer version of Magento.

Here is what I used that worked:

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

Note the “$this->” and “htmlEscape” function instead of nl2br. Basically I made it look like the $_product->getName() line right above it, with the same syntax and functions it was using.

Finally, I placed this around line 47 in my file, /app/design/frontend/default/modern/template/catalog/product/view.phtml
This put the SKU right underneath the name of the product. If you’re using a different template, you’ll need to be sure you’re editing the correct file for your template. Finally the layout of your template may (and probably will) vary, so feel free to experiment with the placement.

Also be sure to clear your cache if you don’t see a change. Under Admin -> System -> Cache Management

Hope that helps.

 
Magento Community Magento Community
Magento Community
Magento Community
 
reefnut
Member
 
Total Posts:  72
Joined:  2008-07-05
 

Instead of changing any code at all why not just create another attribute with a name like model number or something and chosse to sisplay it on fromt end.

Except for the fact that it takes a few seconds longer to add the information it works fine.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jimmypalmer
Sr. Member
 
Total Posts:  79
Joined:  2008-05-04
 

Thanks.  worked for me. 

seems a bit random...but hey...it works.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joya-joya
Jr. Member
 
Total Posts:  28
Joined:  2008-08-17
 
reefnut - 12 November 2008 03:54 AM

Instead of changing any code at all why not just create another attribute with a name like model number or something and chosse to sisplay it on fromt end.

Except for the fact that it takes a few seconds longer to add the information it works fine.

This works, but if you have hundreds of products then it takes a heck of a lot longer then a few seconds…

 
Magento Community Magento Community
Magento Community
Magento Community
 
joya-joya
Jr. Member
 
Total Posts:  28
Joined:  2008-08-17
 

Does anyone know how to get this to work in the “Additional Information” table?

 
Magento Community Magento Community
Magento Community
Magento Community
 
jonw101
Member
 
Total Posts:  73
Joined:  2008-11-14
 

I got

<?php echo nl2br($_product->getSku()) ?>
working like a charm… One question.. How would i go about showing SKU’s for custom options as well…

I have select heights that you can choose from but there are no SKU’s on them, just on the base product…

IF this doesnt make sense,please let me know… I’d love to figure this out…

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 3