2016-10-28 60 views
1

我在同一台服务器上有一个CI项目和一个Magento项目。通过产品ID获取图像的服务器路径 - Magento 1.8

我想定期将Magento产品导入我的CI网站。

一切工作完美,我目前能够从Magento导入我的CI网站的每件事情。

但是,如何获得magento产品图像的物理/服务器路径?我想将这些图像文件复制到我的CI项目。

这里是我装的产品与

$product = $simpleProduct->getData() 

相对线这是我所得到的回报与图像相关的部分。看看file键,它不是真正的服务器路径。

"media_gallery":{ 
    "images":[ 
     { 
      "value_id":"6", 
      "file":"\/2\/-\/2-2.jpg", 
      "label":"", 
      "position":"1", 
      "disabled":"0", 
      "label_default":null, 
      "position_default":"1", 
      "disabled_default":"0" 
     }, 
     { 
      "value_id":"5", 
      "file":"\/2\/_\/2.jpg", 
      "label":"", 
      "position":"2", 
      "disabled":"0", 
      "label_default":null, 
      "position_default":"2", 
      "disabled_default":"0" 
     } 
    ], 
    "values":[ 

    ] 
    }, 

PS 我不希望这样的http://www.website/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/2/-/image_name_here.jpg

图像的浏览器路径我想服务器路径。

+0

1codeigniter'或'magento'? –

+0

正如我所说的Magento和CI项目在同一台服务器上,所以是的,我有权访问Magento ...正如你看到我使用'$ simpleProduct-> getData()'加载产品...因此我需要在Magento中的解决方案... – Umair

+0

我已经使用'require_once(“../ app/Mage.php”)初始化了magento;' – Umair

回答

1

嗨,你可以通过使用此代码 缓存图像

foreach ($_product->getMediaGalleryImages() as $image) { 
     echo Mage::helper('catalog/image')->init($product, 'image', $image->getFile()); 
    } 

对于没有缓存的原始图像

foreach ($_product->getMediaGalleryImages() as $image) { 

     echo Mage::getUrl('media').'catalog/'.'product'.$image->getFile().'<br>'; 
    } 
+0

我想它只返回1张图片。我想要一个产品的所有图像 – Umair

0

我做了一个脚本,提取有关使用它的SKU产品信息得到这样的:

<?php 
if(isset($_GET['productId'])) 
{ 
getImage($_GET['productId']); 
} 
else{ 
    header('HTTP/1.0 404 Not Found', true, 404); 
    echo "404 Not found"; 
    die(); 
} 
function getImage($product) 
{ 
    @ob_start(); 
    @session_start(); 

    //for order update 
    include 'app/Mage.php'; 
    Mage::app('default'); 
    $product_id = Mage::getModel("catalog/product")->getIdBySku($product); 
    $cProduct = Mage::getModel('catalog/product'); 
    $cProduct->load($product_id); 
    $productInfo = Array(
    'name' => $cProduct->getImageUrl(), 
    'url' => $cProduct->getUrlPath(), 
    'prodId' => $product_id, 
    'prodName' => $cProduct->getName(), 
    'prodPrice' => round($cProduct->getFinalPrice(),2), 
    'currency' => Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol() 
    ); 
    echo json_encode($productInfo); 
} 


?> 

然而,它只会获取你的基地址的形象不是一切