1

I have a CI project and a Magento Project on same server.

I want to periodically import Magento products into my CI website.

Everything is working perfectly, I am currently able to import each thing from Magento to my CI website.

BUT, how do I get physical/server paths of images of magento product? I want to copy those image files to my CI project.

Here is relative line I am loading product with

$product = $simpleProduct->getData()

And this is Image related part of what I get in return. look at file key, its not actual server path.

 "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 I dont want browser path of an image like this http://www.website/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/2/-/image_name_here.jpg

I want server path.

0

AFAIK, there is no clean way of doing it out of the box.

The hacky script I tend to use is the following (note that $file corresponds to the data stored with the file key in your media gallery images array):

$imageUrl = Mage::helper('catalog/image')->init($_product, 'image', $file)->__toString();
$imagePath = str_replace(array(Mage::getBaseUrl('media'), '/'), array(Mage::getBaseDir('media').DS, DS), $imageUrl);

Pretty sure I found it on StackExchange a while ago but can't get my hands on the link.

  • ` $_product = $simpleProduct->load($_GET['loadprod']); foreach ($simpleProduct->getMediaGalleryImages() as $image) { $imageUrl = Mage::helper('catalog/image')->init($simpleProduct, 'image', $image)->__toString(); echo $imagePath = str_replace(array(Mage::getBaseUrl('media'), '/'), array(Mage::getBaseDir('media') . DS, DS), $imageUrl); }` returned me link like website.com/test/skin/frontend/default/kawaii/images/catalog/… – Umair Oct 28 '16 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.