I have a helper from which to add a product through the id. After the product is added, I save some product data (name, price, and image) into an array and return it. But I'm getting the image directly from the product, but I need to get that same image from the magento cache in my specific case.
Helper Code:
public function addCustom($product_id)
{
// Get customer session
$session = Mage::getSingleton('customer/session');
// Get cart instance
$cart = Mage::getSingleton('checkout/cart');
$cart->init();
// Add a product with custom options
$product = Mage::getModel('catalog/product')->load($product_id);
$param = array(
'product' => $product->getId(),
'qty' => 1
);
$request = new Varien_Object();
$request->setData($param);
$cart->addProduct($product, $param);
// update session
$session->setCartWasUpdated(true);
// save the cart
$cart->save();
$nome = $product->getName();
$preco = number_format((float)$product->getPrice(), 2, ',', '');
$media = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail());
$img = $media;
$dados['name'] = $nome;
$dados['price'] = $preco;
$dados['media'] = $media;
$dados['imagem'] = $img;
return $dados;
}
From the code $media = Mage::getModel('catalog/product_media_config')->getMediaUrl($product->getThumbnail());
the magento returns the image in my phtml file as follows by the URL:
/media/catalog/product/u/m/uma-flor-alaranjada-com-mensagem-cart_o-14896928_1_2.jpg
But in my case, I need to bring the same image from the cache for resizing issues, through this URL:
/media/catalog/product/cache/1/thumbnail/50x50/9df78eab33525d08d6e5fb8d27136e95/u/m/uma-flor-alaranjada-com-mensagem-cart_o-14896928_1_2.jpg