10

I am trying to get the child product image of a configurable product that was added to cart by the customer.

For example, if the customer added a pair of red shoes to the cart I would like to show that color in the shopping cart.

I have set "Show product Thumbnail Itself"

The problem is this function from a colour swatch extension

public function findColorImage($value, $arr, $key, $type)
{
    $found = '';
    if(isset($arr[$key])) {
        $total = count($arr[$key]);
        if($total>0)
        {
            for($i=0; $i<$total;$i++)
            {
                if($value == ucwords($arr[$key][$i]))//if it matches the color listed in the attribute
                {
                    $found = $arr[$type][$i];//return the image src
                }
            }
        }
    }
    if ($found == '') {
        if (isset($arr['image'])){
            $found = $arr['image'][0];
        }
    }
    return $found;
}

in the template colorselectorplus/cart/item/default.phtml

findColorImage($_item->getProductId(),$product_base,'color', 'image'); ?>

Which is being called from Helper/Data.php for some reason it only returns the Base image for the product and ignores the correct image for the colour.

I've tried changing image to use thumbnail but I'm not having any joy...

Has any other developer come across this issue with this extension and managed to fix it?

I'd don't mind even a hot fix right now...

10

Goto admin>System>Configuration>Checkout>Shopping Cart>Configurable Product Image make it Product Thumbnail Itself this make child product image Instead of sending

$_item->getProductId()
send $_item
and put somelogic
$_item

for configurable product $_Item>getSku give child product a other time give main products. so just child product using item sku

I guess you have used third party extension so i have change some change according my concept change

Step1:instead of send product send all item object

findColorImage($_item->getProductId(),$product_base,'color', 'image');

to

findColorImage($_item,$product_base,'color', 'image'); 

Step2: some change on function

public function findColorImage($item, $arr, $key, $type)
{
    /* $value  set here*/
    $value=$item->getProductId();

    $found = '';
    if(isset($arr[$key])) {
        $total = count($arr[$key]);
        if($total>0)
        {
            for($i=0; $i<$total;$i++)
            {
                if($value == ucwords($arr[$key][$i]))//if it matches the color listed in the attribute
                {
                    $found = $arr[$type][$i];//return the image src
                }
            }
        }
    }

    if ($found == '') {
        if (isset($arr['image'])){
            $found = $arr['image'][0];
        }
    }
    /*  for configurable product send child product image */
    if($item->getProductTypeId="configurable"){
        $ChildProduct=Mage::getModel('catalog/product')->loadByAttribute('sku',$item->getSku());
        $found=Mage::helper('catalog/image')->init($ChildProduct, 'thumbnail');

    }
    return $found;
}
  • Thanks for you comments. I have mentioned in this post that I have already that to yes... – user1704524 Sep 2 '14 at 10:46
  • apologies but its not quite clear what you mean??? – user1704524 Sep 2 '14 at 13:46

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.