0

in a template I am calling function in a block using:

$_product = Mage::registry('current_product');
<?php echo $this->getProductEncode($_product); ?>

The function getProductEncode then returns some json-ld encoded text. However, when I use this function:

$description = $product->getShortDescription(); 

Nothing is description is set to " '' ". Why is this? If I remember correctly, short descriptions IS part of products, right? I looked in our backend and it's definitely set for the product in question. Is there a workaround available?

I don't understand why magento instantiates only minutely different implementations of a 'product' seemingly at random.

Mage::log($product->debug(), null, 'testing.log', true);

Does not display short description as part of this product. Other areas of my store use the above getShortDescription() on product to retrieve it.

4
  • Assuming that your using $_product and not $product, is this a single or multi store? Nov 13, 2014 at 22:06
  • 1
    Are you missing the ()? And as R.S. already started to say, are you sure, the value is set correctly in the store view? Nov 13, 2014 at 22:12
  • @R.S when a user visits the product page I am calling the above registry mage function which then passes the product to the function described in the block. Multi store. Nov 14, 2014 at 13:05
  • @FabianBlechschmidt I added the () to the question. And added additional information. Nov 14, 2014 at 13:05

1 Answer 1

4

This is wrong,

$description = $product->getShortDescription 

Without the parenthesis, you are trying to access a variable called getShortDescription, not call the method getShortDescription(), it should be,

$description = $product->getShortDescription()

Now that you've edited you question ...

Your code is still wrong, you are instantiating the model and storing it in a variable called $_product

$_product = Mage::registry('current_product');

But then you are trying to access a non-defined variable called $product

$product->getShortDescription();

You should use,

$_product->getShortDescription(); 
 ^
 |
Note the underscore!
5
  • Yea, I had the (). I'll edit my question. Nov 14, 2014 at 12:55
  • 1
    Answer updated to suit edited question. Nov 14, 2014 at 14:00
  • I am passing $_product from a template file to a block. The function getProductEncode($product) could just as well be defined as getProductEncode($sponge) or getProductEncode($notAProduct). The result would still be me passing $_product to getProductEncode($___) and then using that parameter to call $___->getShortDescription(). Which, just as originally described, does not return the $_product's short description. Nov 14, 2014 at 14:16
  • Read my answer, you assigned the class instance to $_product - but then later tried to access it with $product. You are trying to access a variable that has not been defined Nov 14, 2014 at 14:26
  • <?php Mage::log($_product->debug(), null, 'testing.log',true);?> shows no short description either. Nov 14, 2014 at 14:38

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