1

I'm having many custom attributes on my web site. If I want to use them on my view page, i just use the following code, which works great.

<?php echo $_product->getData("lp_ekran_vel"); ?>

Now, I have this situation where I need to display some custom attributes for:

<meta name="keywords" content="" />
<meta name="description" content="" />

When i use the following code it want work. What I'm doing wrong? Thanks

<meta name="keywords" content="<?php echo $_product->getData("lp_model"); ?>" />

UPDATED

Here is the code which I'm using:

 <?php if(Mage::registry('current_product')): ?>
<?php $product = Mage::registry('current_product'); ?>
<title>Laptop <?php echo ($product->getName()); ?></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta property="og:title" content="<?php echo ($product->getName()); ?>" />
<meta property="og:type" content="product" />
<meta property="og:image" content="<?php echo $this->helper('catalog/image')->init($product, 'small_image')->resize(200,200);?>" />
<meta property="og:url" content="<?php echo Mage::registry('product')->getProductUrl(); ?>" />
<meta property="og:description" content="<?php echo strip_tags(($product->getShortDescription())); ?>" />
<meta property="og:site_name" content="<?php echo Mage::app()->getStore()->getName(); ?>" />

I'm trying to get my custom atribute value on product view page.

2

Issue: Stop to all pages:

head.phtml is call on all pages.

And as per as your code,this code has running to all the pages. That must be working on all pages.

Also, as you want to call this attribute to product view pages.so, you need put an condition thus your code will work on product view pages.

condition:

if(Mage::app()->getFrontController()->getAction()->getFullActionName()=='catalog_product_view')

//put you code:

endif;

Issue: Call Product Object:

Also getting current object at head section you need call registry variable

Mage::registry('current_product')



if(Mage::app()->getFrontController()->getAction()->getFullActionName()=='catalog_product_view')

    //put you code:
    $_product=Mage::registry('current_product');

    $value = $_product->getResource()->getAttribute("lp_ekran_vel")->getFrontend()->getValue($_product); 
    endif;
2
  • Thank you Amit very much. I really appropriate your effort. It seems, just, like I can't make it work. :(
    – user15151
    Jul 4 '15 at 9:46
  • Syntax issue.. Resolved .try again
    – Amit Bera
    Jul 4 '15 at 10:11
0

It depends how you loaded your $_product object. If you get the product from a collection is possible that for performance reasons not all the attributes were loaded. If you want to make sure that you are loading the product and all of it's attributes then try this:

$product = Mage::getModel('catalog/product')->load($_product->getId());

Also you can check which attributes are present in your $_product object already doing this:

print_r($_product->getData());

Althought I would recomend using xdebug

1
  • I just edited and updated my question. Can you please take a look again?
    – user15151
    Jul 4 '15 at 9:18

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.