嗨我已经获得了完整的缓存缩略图以及带有我的代码的主图像路径但我希望获得 relative 的完整缓存路径* 图片 *也请提出一些想法
<?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{
$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
echo 'product_id '.'=>'.$product->getId().'<br/>';
echo 'created_at '.'=>'.$product->getcreated_at().'<br/>';
echo 'description '.'=>'.$product->getdescription().'<br/>';
echo 'short_description '.'=>'.$product->getshort_description().'<br/>';
echo 'sku'.'=>'.$product->getsku().'<br/>';
'media_gallery'.'=>'.$product->getmedia_gallery().'<br/>';
print_r($product->getmedia_gallery());
?>
<?php
$image = Mage::helper('catalog/image')->init($product, 'image');
$image1 = str_replace('/webApps/migration/productapi/new/','/',$image);
//echo '<img id="image" src="'.$image1.'" />';
echo 'image => '.$image1.'<br/>';
$thumbnail = Mage::helper('catalog/image')->init($product, 'thumbnail');
$thumbnail1 = str_replace('/webApps/migration/productapi/new/','/',$thumbnail);
echo 'thumbnail => '.$thumbnail1.'<br/>';
?>
答案 0 :(得分:1)
* 此代码 *我的产品相对 * 图片 * 完整路径
<?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{
$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
echo 'product_id '.'=>'.$product->getId().'<br/>';
echo 'created_at '.'=>'.$product->getcreated_at().'<br/>';
echo 'description '.'=>'.$product->getdescription().'<br/>';
echo 'short_description '.'=>'.$product->getshort_description().'<br/>';
echo 'sku'.'=>'.$product->getsku().'<br/>';
if (count($product->getMediaGalleryImages()) > 0){
foreach ($product->getMediaGalleryImages() as $_image){
$thumbnail12 = Mage::helper('catalog/image')->init($product->getProduct(), 'image', $_image->getFile())->resize(2000);
$thumbnail13 = str_replace('/webApps/migration/productapi/new/','/',$thumbnail12);
echo 'thumbnail => '.$thumbnail13.'<br/>';
}
}
?>
答案 1 :(得分:0)
请注意,如果您正在调试此操作而不理解为什么您没有从中获取图像路径字符串:
Mage::helper('catalog/image')->init($product->getProduct(), 'image', $_image->getFile())->resize(2000)
它因为它实现了toString()方法,所以每次执行此操作实际上都会提供图像的完整路径。你可以通过调用 - &gt; toString()或者只是添加(String)Mage ...
来看到它(但是在回显时不需要使用(String)或 - &gt; toString(),php默认情况下这样做)