3

I want to change product image after a user added a product in to cart, Because user can change image text and font style. So, I have loaded Quote item using event sales_quote_add_item and I am able to change product price using it but I am not getting how to change product image.

2
  • Which version of magento are you using ? Commented May 30, 2016 at 6:08
  • Magento CE 1.9.2.4 Commented May 30, 2016 at 6:52

2 Answers 2

2

The cart product image is provided by the getProductThumbnail method from the following renderers:

  • Mage_Checkout_Block_Cart_Item_Renderer_Configurable for configurable products
  • Mage_Checkout_Block_Cart_Item_Renderer_Grouped for grouped products
  • Mage_Checkout_Block_Cart_Item_Renderer for any other type of products

Thus, my advice would be to rewrite those renderer blocks in a module:

config.xml

<modules>
    <DigitalPianism_CartImage>
        <version>0.0.1</version>
    </DigitalPianism_CartImage>
</modules>

<global>

    <blocks>
        <checkout>
            <rewrite>
                <!-- Mage_Checkout_Block_Cart_Item_Renderer -->
                <cart_item_renderer>DigitalPianism_CartImage_Block_Checkout_Cart_Item_Renderer</cart_item_renderer>
                <!-- Mage_Checkout_Block_Cart_Item_Renderer_Configurable -->
                <cart_item_renderer_configurable>DigitalPianism_CartImage_Block_Checkout_Cart_Item_Renderer_Configurable</cart_item_renderer_configurable>
                <!-- Mage_Checkout_Block_Cart_Item_Renderer_Grouped -->
                <cart_item_renderer_grouped>DigitalPianism_CartImage_Block_Checkout_Cart_Item_Renderer_Grouped</cart_item_renderer_grouped>
            </rewrite>
        </checkout>
    </blocks>

</global>

NB: you change remove some rewrites from this file if you don't need them (i.e. if you don't use configurable products, remove the corresponding block rewrite, same for grouped products)

Then you can create your custom blocks extending the original blocks.

Here's a sample of how your code could look like for the DigitalPianism_CartImage_Block_Checkout_Cart_Item_Renderer block:

<?php

class DigitalPianism_CartImage_Block_Checkout_Cart_Item_Renderer extends Mage_Checkout_Block_Cart_Item_Renderer
{

    public function getProductThumbnail()
    {
        if () {
        } else {
            return parent::getProductThumbnail();
        }
    }
}

Please note that as I don't know exactly what will trigger the image change, you will have to update the if statement of the above code to match your needs

1
  • Thank you for your answer, I will implement this thing and let you know its working or not Commented May 31, 2016 at 5:38
0

Unfortunately the quote item does not stores the product image as it does for the product price.

Although you can store the url info of the image using the setProductOption method of Mage_Sales_Model_Quote_Item.

Once the data is saved, for the cart page you can overwrite Mage_Checkout_Block_Cart_Item_Renderer classes getProductThumbnail method to fetch the item option data saved previously.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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