Get original image url Magento (1.6.1.0)

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

I have the following piece of code:

$cProduct = Mage::getModel("catalog/product"); foreach($products_id as $product_id) {     $product = $cProduct->load($product_id);     //$products_image[] = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).str_replace(Mage::getBaseUrl('media'),"", $product);     //$products_image[] = $product->getMediaConfig()->getMediaUrl($_product->getData('image'));     $products_image[] = $product->getImageUrl(); //product's image url } 

As you can see, I've tried several ways to get the original image url. Currently I'm using getImageUrl(), but it retrieves the base image, which is a cropped version. How can I retrieve the original image??

Thanks in advance.

Edit: Seriously appears there isn't a function for it, been Googling for hours straight (also before posting here). So I've written my own function.

function get_original_image_url($base_image_url) {     $exploded = explode("/", $base_image_url);     $image_name = $exploded[count($exploded) - 1];      $original_image_url = "http://yoursitehere.com/media/catalog/product/" . $image_name[0] . "/" .                            $image_name[1] . "/" . $image_name;      return $original_image_url; } 

I call it with:

$original = get_original_image_url($product->getImageUrl()); 

Works for me, though it isn't a nice way to do it.

回答1:

You should use the catalog product media config model for this purpose.

getMediaUrl( $product->getImage() ); //getSmallImage(), getThumbnail() 

Hope this helps.



回答2:

Other faster way:

$cProduct = Mage::getModel("catalog/product"); $baseUrl = Mage::getBaseUrl('media') . 'catalog/product/'; foreach($products_id as $product_id) {     $product = $cProduct->load($product_id);     $products_image[] = $baseUrl . $product->getImage(); } 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!