Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Trying to get img urls but something missing
 
AnixZsolt
Jr. Member
 
Total Posts:  2
Joined:  2013-01-14
 

I am new in magento with minimal php experience and I have to make a simple php file in root to export SKU, product name and the first 4 base image urls to csv. Unfortunately, the img urls are missing and I can’t find examples that work (I have problem at the “SOMETHING MISSING HERE"). Thank you for any help.

<?php 

header
('Content-Type: text/html; charset=utf-8');
require 
'app/Mage.php';
Mage::app("default");


 
$collection Mage::getModel('catalog/product')
                        ->
getCollection()
                        ->
addAttributeToSelect('*'// all attributes
            
->addAttributeToFilter('exportornot''yes'// custom attribute filter
            
->addAttributeToFilter('status'1);//enabled            
$fp fopen('feed.csv''w');//open csv file


//-----------------------------MAKE CSV HEADER------------------------------
$csvheader = array(
'title',
'sku',
'photo_url_1',
'photo_url_2',
'photo_url_3',
'photo_url_4',
'category',
'product_url',
'description'
);
fputcsv($fp$csvheader$delimiter ",");//write to the csv  header   


//-----------------------------MAKE CATEGORY ------------------------------
foreach ($collection as $product{
$fcmCathegoryPath
="";
    foreach (
$product->getCategoryIds() as $category_id{/
        
$category Mage::getModel('catalog/category')->load($category_id);
        
$fcmCathegoryPath.=$category->getName();
    
}
  
  
//-----------------------------MAKE IMAGE VARIABLES------------------------------
$_gallery Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages();
$imgCount Mage::getModel('catalog/product')->load($product->getId())->getMediaGalleryImages()->count();

if(
$imgCount >1){
    
foreach ($_gallery as $_image ){
    
    
/*
    
    
    
    SOMETHING MISSING HERE
    for example:
    put the first image url to the first variable
    $photo_url_1 = $_image->getFile()
    and so on
    
    
    
    
    
    */
    
}

//-----------------------------MAKE CSV CONTENT-----------------------------
    
fcmFeedContent=array( //put the things to the array
        
$product->getName(),//title
        
$product->getSku(),//seller_product_id 
        
$photo_url_1,
        
$photo_url_2,
        
$photo_url_3,
        
$photo_url_4,
        
$fcmCathegoryPath,
        
'http://mysite.com/'.$product->getUrlPath(),
        
$product->getDescription()
    );
    
     
fputcsv($fpfcmFeedContent$delimiter ",");//write to the csv    


fclose
($fp);

?>
 
Magento Community Magento Community
Magento Community
Magento Community
 
AnixZsolt
Jr. Member
 
Total Posts:  2
Joined:  2013-01-14
 

@weric0127 you are welcome

Can anybody help me?

 
Magento Community Magento Community
Magento Community
Magento Community
 
magentodesignin
Jr. Member
 
Total Posts:  22
Joined:  2013-10-29
Ahmedabad
 

Hi,

Following code will help you to get product’s origional image path.

$_images = Mage::getModel(’catalog/product’)->load($_product->getId())->getMediaGalleryImages();
if($_images)
{
$i=0;
foreach($_images as $_image)
{
$photo_url[$i] = Mage::getModel(’catalog/product_media_config’)->getMediaUrl($_image->getFile());
$i++;
}
}

Replace above code at “SOMETHING MISSING HERE” section and use $phto_url array to insert image urls in CSV.

With Regards,
Vijay Golani,
Magento Developer,
Krish TechnoLabs

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top