I needed a way to extract category informations from a magento store, and after spending more than 12 hours I came with this.

The best part of this script is that you can directly get all the information needed from the $cat array by calling the array element (name, url, image). You can obtain all the array values with a simple print_r($cat);

This particular example create the .xml needed for the coverflow flash gallery.

<?php
$myFile = “xml/data.xml”;
$fh = fopen($myFile, ‘w’) or die(“can’t open file”);
echo $stringData = ‘<?xml version=”1.0″ encoding=”utf-8″?>
<coverflow
imageWidth=”310″
imageHeight=”200″
imagePadding=”1″
coverflowSpacing=”50″
startIndex=”0″
startIndexInCenter=”yes”
coverLabelPositionY=”328″
coverSlidePositionY=”0″
transitionTime=”0.5″
centerCoverflowZPosition=”40″
target=”_blank”
reflectionAlpha=”35″
reflectionRatio=”50″
reflectionDistance=”0″
reflectionUpdateTime=”-1″
reflectionDropoff=”0.75″
>
‘;
fwrite($fh, $stringData);

$category = Mage::getModel(‘catalog/category’);
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$arr = array();
$img = array();$name = array();$url = array();
if ($ids){
foreach ($ids as $id){
$cat = Mage::getModel(‘catalog/category’);
$cat->load($id);

$stringData =  ‘<cover img=”media/catalog/category/’.$cat["image"].’” title=”‘.$cat["name"].’” link=”http://xxxxxx.com/’.$cat["url_key"].’.html” />’;
if($cat["image"]){
fwrite($fh, $stringData);}
}
}
$stringData =  ‘</coverflow>’;
fwrite($fh, $stringData);
fclose($fh);
?>I needed a way to extract category informations from a magento store, and after spending more than 12 hours I came with this.

The best part of this script is that you can directly get all the information needed from the $cat array by calling the array element (name, url, image). You can obtain all the array values with a simple print_r($cat);

This particular example create the .xml needed for the coverflow flash gallery.

<?php
$myFile = “xml/data.xml”;
$fh = fopen($myFile, ‘w’) or die(“can’t open file”);
echo $stringData = ‘<?xml version=”1.0″ encoding=”utf-8″?>
<coverflow
imageWidth=”310″
imageHeight=”200″
imagePadding=”1″
coverflowSpacing=”50″
startIndex=”0″
startIndexInCenter=”yes”
coverLabelPositionY=”328″
coverSlidePositionY=”0″
transitionTime=”0.5″
centerCoverflowZPosition=”40″
target=”_blank”
reflectionAlpha=”35″
reflectionRatio=”50″
reflectionDistance=”0″
reflectionUpdateTime=”-1″
reflectionDropoff=”0.75″
>
‘;
fwrite($fh, $stringData);

$category = Mage::getModel(‘catalog/category’);
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
$arr = array();
$img = array();$name = array();$url = array();
if ($ids){
foreach ($ids as $id){
$cat = Mage::getModel(‘catalog/category’);
$cat->load($id);

$stringData =  ‘<cover img=”media/catalog/category/’.$cat["image"].’” title=”‘.$cat["name"].’” link=”http://xxxxxx.com/’.$cat["url_key"].’.html” />’;
if($cat["image"]){
fwrite($fh, $stringData);}
}
}
$stringData =  ‘</coverflow>’;
fwrite($fh, $stringData);
fclose($fh);
?>