Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting image for bundle product child products, currently returning placeholder
    primarykey
    data
    text
    <h2>My problem:</h2> <p>I need to retrieve the main product image from a cut down product object which is supplied by the class: <code>Mage_Bundle_Model_Resource_Price_Index</code></p> <p>My code demonstrating the issue:</p> <pre><code>$_product = $this-&gt;getProduct(); $_options = Mage::helper('core')-&gt;decorateArray($this-&gt;getOptions()); foreach($_options as $_option): $_selections = $_option-&gt;getSelections(); foreach ($_option-&gt;getSelections() as $tmpsel) { var_dump($tmpsel-&gt;getImageUrl()); } </code></pre> <p>Which returns my placeholder image:</p> <p><code>http://dev.dev/media/catalog/product/cache/7/image/265x/0dc2d03fe217f8c83829496872af24a0/placeholder/default/logo_3.jpg</code></p> <h2>My horrible and hacky work around:</h2> <p>In order to get correct image Url, I have resorted to loading a completely new product object, which is terribly inefficient.</p> <pre><code>foreach ($_option-&gt;getSelections() as $tmpsel) { $product = Mage::getModel("catalog/product")-&gt;load($tmpsel-&gt;getId()); $image = Mage::helper('catalog/image')-&gt;init($product, 'image'); var_dump($image.""); } </code></pre> <p>This returns correctly: <code>http://dev.dev/media/catalog/product/cache/7/image/0dc2d03fe217f8c83829496872af24a0/M/P/MP1428219-107-Main.jpg</code></p> <h2>What I want to do:</h2> <p>I want to be able to use the <code>catalog/image</code> helper with the selection ($tmpsel), but when I try I end up getting the placeholder image again.</p> <pre><code>foreach ($_option-&gt;getSelections() as $tmpsel) { $image = Mage::helper('catalog/image')-&gt;init($tmpsel, 'image'); var_dump($image.""); } </code></pre> <h2>Extra Info:</h2> <p><em>Anything I think of that could help I will add here</em></p> <h3>Cut down product object includes some reference to image</h3> <pre><code> 'small_image' =&gt; string '/M/P/MP1428219-107-Main.jpg' 'thumbnail' =&gt; string '/M/P/MP1428219-107-Main.jpg' </code></pre> <h3>Description of getSelection()</h3> <p>In: ./app/code/core/Mage/Bundle/Model/Resource/Price/Index.php</p> <p><code>* Retrieve bundle options with selections and prices by product</code></p> <p>The function uses low level SQL to generate the collection, so I can always extend it to add options if needed, not sure which options though.</p> <hr> <p>Thank you for reading, hope someone can give me a good way of doing this, will keep updated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload