FAQ: Is it possible to override MageMail’s product url fetching?

·

·

Yes, you can use the kj_magemail_product_image_fetch_after observer to fetch the image URL and modify it.

Here’s a quick example of the observer setup in config.xml:

<global>
    <events>
        <kj_magemail_product_image_fetch_after>
            <observers>
                <namespace_kj_magemail_product_image_fetch_after>
                    <class>KJ_MageMail_Model_Observer</class>
                    <method>productImageFetchAfter</method>
                </namespace_kj_magemail_product_image_fetch_after>
            </observers>
        </kj_magemail_product_image_fetch_after>
    </events>
</global>

And the observer:

<?php

/**
 * @param $observer Varien_Event_Observer
 */
public function productImageFetchAfter($observer)
{
    /** @var Varien_Object $data */
    $data = $observer->getData('data');

    /** @var Mage_Catalog_Model_Product $product */
    $product = $observer->getData('product');
    
    /**
     * The product ID that was requested in the product image URL.
     * This may be different from the $product model, because the $product
     * model attempts to load a product that has a small_image set on it,
     * and if it doesn't have one, it will load the parent product.
     */
    $requestedProductId = $observer->getData('requested_product_id');


    $data->setData('image_url', 'http://local.magemail.co/app/media/uploads/d2176f2e5d09f7071cf98ea460f0b9b6.png');

    return $this;
}