Note that there are some explanatory texts on larger screens.

plurals
  1. POGet all image urls when creating csv in magento
    text
    copied!<p>I am new in magento and in php objects but 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 after the “SOMETHING MISSING HERE" text). Thank you for any help.</p> <pre><code>&lt;?php header('Content-Type: text/html; charset=utf-8'); require 'app/Mage.php'; Mage::app("default"); $collection = Mage::getModel('catalog/product') -&gt;getCollection() -&gt;addAttributeToSelect('*') // all attributes -&gt;addAttributeToFilter('exportornot', 'yes') // custom attribute filter -&gt;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-&gt;getCategoryIds() as $category_id) { $category = Mage::getModel('catalog/category')-&gt;load($category_id); $fcmCathegoryPath.=$category-&gt;getName(); } //-----------------------------MAKE IMAGE VARIABLES------------------------------ $_gallery = Mage::getModel('catalog/product')-&gt;load( $product-&gt;getId())-&gt;getMediaGalleryImages(); $imgCount = Mage::getModel('catalog/product')-&gt;load( $product-&gt;getId())-&gt;getMediaGalleryImages()-&gt;count(); if($imgCount &gt;1){ foreach ($_gallery as $_image ){ /* SOMETHING MISSING HERE for example: put the first image url to the first variable $photo_url_1 = $_image-&gt;getFile() and so on */ } //-----------------------------MAKE CSV CONTENT----------------------------- fcmFeedContent=array( //put the things to the array $product-&gt;getName(),//title $product-&gt;getSku(),//seller_product_id $photo_url_1, $photo_url_2, $photo_url_3, $photo_url_4, $fcmCathegoryPath, 'http://mysite.com/'.$product-&gt;getUrlPath(), $product-&gt;getDescription() ); fputcsv($fp, fcmFeedContent, $delimiter = ",");//write to the csv } fclose($fp); ?&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload