9

How to get full product image url in magento ,i need to migrate the data from magento to django so i need to get the product full image url to migrate the site

here is my code

<?php @ob_start(); @session_start(); ini_set('display_errors', 1); //for order update include '../../../../app/Mage.php'; Mage::app('default'); echo '<pre>'; if(isset($_REQUEST['productid'])){ $productId = $_REQUEST['productid']; }else{ echo 'Default Product => '; $productId = '12402'; // product ID 10 is an actual product, and used here for a test } $product = Mage::getModel('catalog/product')->load($productId); //load the product print_r($product->getthumbnail());<br/> print_r($product->getcreated_at()); ?> 

4 Answers 4

24

You can try below code first of all call helper of catalog

echo Mage::helper('catalog/image')->init($product, 'thumbnail'); 

From this code you can get cache path also.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi by using this code i get following error Fatal error: Using $this when not in object context in /mnt/aviesta/development/webApps/migration/productapi/new/index.php on line 24
19

After you loaded your product using load() you can use the following in your code:

Full size image:

$imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage(); 

Resized/Cached image:

$imageCacheUrl = Mage::helper('catalog/image')->init($product, 'image')->resize(135, 135); 

If you need a different cache size, then use other numbers for the resize method.

3 Comments

Can you please elaborate your answer and link with my code , i dont know how to link this with my code, my code is in a webdev directoey
i need the full cache path also for the image , i am trying very hard but have no idea how to get this
@RohitGoel I updated my post. Add my code right after your $product = Mage::getModel('catalog/product')->load($productId); line.
7

Try this

$product = Mage::getModel('catalog/product')->load($product_id); $full_path_url = Mage::helper('catalog/image')->init($product, 'thumbnail'); 

Comments

0
 <img src="<?php echo Mage::helper('catalog/image')->init($_products, 'small_image')->resize(200,200);?>" width="200" alt=""> <?php ini_set('display_errors','on'); require_once 'app/Mage.php'; Mage::app('default'); $_products = Mage::getResourceModel('catalog/product_collection')->toOptionArray(); $product_id = $this->getRequest()->getParam('id'); $_products=Mage::getModel('catalog/product')->load($product_id);?> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.