0
votes

who can help me solve this puzzle of php code? (for the record, i am not a php programmer)

I want to show a thumbnail (for using in the sales order screen and new order mail)

Simple products aren't the problem. I have this code for this:

<?php //added for sending image with order
$product = Mage::getModel('catalog/product')
->setStoreId($_item->getOrder()->getStoreId())
->load($_item->getProductId());     ?>
<p align="center"><img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(135); ?>" width="135" height="135" alt="" /></p>

This works fine. Where it's getting difficult is when i have a simple product related to a configurable product. The "childs" of the configurable product don't have images included, only the configurable product. (see the screenshot, the first product is the configurable product with the images, the rest are simple products "childs" with no photo's)

enter image description here

With the code above i only see the placeholder of the image. How can i call the image of the configurable product?

I use magento 1.6.2.0 on the dedicated server (running on ubuntu 10.04lts server)

1

1 Answers

1
votes

I just worked through this problem. Here is my solution.

The issue I ran into was, like you, images are not linked to the children products of a configurable parent (tho you can upload images for these products...). I took the route of adding images to the attributes that drive the variations of the parent product, and output an image for them instead.

My solution is tied into the configurable.phtml template, and uses JS to pull out the proper details (Magento uses a lot of JS to represent configurable products, unlike bundles).

Good luck. This is a pain.

(And why Magento doesn't support this out of the box I'll never know. Seems like essential functionality to me...)

update


Well - it really depends on what you are trying to do. If you just want one image for each child product you could try something like:

$spImages = array();
foreach ($this->getAllowProducts() as $_sp) {
    $spImages[$_sp->getId()] = 
        (string)$this->helper('catalog/image')
            ->init($_sp, 'small_image')
            ->resize(40,40);
}

Assuming you've uploaded an image for each child product.

But, as I noted, I was interested in a swatch for each attribute option, and this was not going to work out for my needs. That's why I associated images with the attributes themselves.