2013-01-04 114 views
7

如何获得完整的产品图片网址Magento的,我需要从Magento的数据迁移到Django的所以我需要拿到产品完整图像的URL迁移该网站如何获得完整的产品图像URL在Magento

这里是我的代码

<?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()); 
?> 

回答

22

你可以试试下面的代码 第一目录

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

的所有呼叫帮手从这个代码,你可以得到缓存路径也。

+0

嗨通过使用此代码我得到以下错误致命错误:使用$这在不在线24 –

+0

在/mnt/aviesta/development/webApps/migration/productapi/new/index.php对象上下文我有正确的代码使用法师而不是$ this – Mufaddal

+0

谢谢这对我有用。 –

15

您使用load(),您可以在代码中使用了遵循加载产品后:

$imageUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA) . 'catalog/product' . $product->getImage(); 
$imageCacheUrl = Mage::helper('catalog/image')->init($product, 'image')->resize(135,135); 

如果您需要不同的缓存大小,请使用其他数字作为resize方法。

+0

能否请您详细阐述你的答案和链接我的代码,我不知道如何使用我的代码链接此,我的代码是一个Webdev的directoey –

+0

我需要的全部缓存路径也为图像,我很努力,但不知道如何得到这 –

+0

@RohitGoel我更新了我的帖子。在你的$ product = Mage :: getModel('catalog/product') - > load($ productId);线。 – mpaepper

6

试试这个

$product = Mage::getModel('catalog/product')->load($product_id); 
$full_path_url = Mage::helper('catalog/image')->init($product, 'thumbnail'); 
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);?>