jzahedieh
jzahedieh

Reputation: 1579

Magento Product Placeholder Image

I have product placeholder images set in the backend at System -> Configuration -> Catalog -> Product Image Placeholders

I can half-successfully access a product placeholder image programmatically in one of my views using the following code:

$this->getSkinUrl($this->helper('catalog/image')->init(
Mage::getModel('catalog/product'), 'small_image'));

My issue is that the above returns:

http://x.dev/skin/frontend/base/default/http://x.dev/media/catalog/product/cache/7/small_image/0dc2d03fe217f8c83829496872af24a0/placeholder/default/logo_4.jpg*

It seems like getSkinUrl does what it says and adds the skin path to the string, this is my real issue, to fix the issue I thought I would just remove getSkinUrl:

$this->helper('catalog/image')->init(
Mage::getModel('catalog/product'), 'small_image');

But the above code throws:

PHP Fatal error:  Allowed memory size of 268435456 bytes exhausted

Can anyone see a problem with this, I seem to be doing less and it seems to be getting stuck in a loop.

Alternatively does anybody know an alternative method? I am really stuck and I really don't want to hard code it.

Thanks

Upvotes: 3

Views: 15264

Answers (1)

jzahedieh
jzahedieh

Reputation: 1579

Many thanks to @Lucasmus for setting me on the right track.

I ended up solving this in a bit of a hacky way, but it works.

Mage::getModel('catalog/product')->getSmallImageUrl(200,200);

That will get you the product placeholder image set in System -> Configuration -> Catalog -> Product Image Placeholders

Edit

As @Tyler V pointed out this is a depreciated method, if you don't wish to use it you can use the same logic of the method it is a bit more verbose:

    (string)Mage::helper('catalog/image')->init(
        Mage::getModel('catalog/product'),
        'small_image'
    )->resize(200, 200);

Upvotes: 13

Related Questions