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

Feed prodotti categorie
 
crisis86
Jr. Member
 
Total Posts:  23
Joined:  2012-03-13
 

SALVE STO STO CREANDO UN FILE ESTERNO CHE GENERA I FEED IN UN FILE TXT MA HO UN PROBLEMA CON LE CATEGORIE DEI PRODOTTI NEL FOREACH MI TIRA FUORI SEMPRE LA STESSA CATEGORIA POSTO IL CODICE :

HELP PLEASE.....

<?php
define('SAVE_FEED_LOCATION','feed/base_feed.txt');
set_time_limit(0);

require_once 'app/Mage.php';
Mage::app('default');

try{
$handle = fopen(SAVE_FEED_LOCATION, 'w');


//---------------------- GET THE PRODUCTS
$products = Mage::getModel('catalog/product')->getCollection();
$products->addAttributeToFilter('status', 1);//enabled
$products->addAttributeToFilter('visibility', 4);//catalog, search
$products->addAttributeToSelect('*');
$prodIds=$products->getAllIds();


$product = Mage::getModel('catalog/product');

foreach($prodIds as $productId) {

$product->load($productId);

$product_data = array();
$product_data['sku']=$product->getSku() .'|';
$product_data['title']=$product->getName().'|';

$product_data['description']=$product->getShortDescription().'|';
$product_data['link']='http://www.gifrangroup.co.uk/index.php/'.$product->getUrl_path().'|';
$product_data['image_link']=Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$product->getImage().'|';
$product_data['price']=round($product->getPrice(),2).'|';



//get the product categories



$categoryIds = $product->getCategoryIds();


foreach ($product->getCategoryIds() as $category_id) {

$category = Mage::getModel('catalog/category')->load($category_id);

$product_data['product_type']=$category->getName();
}




$product_data['availability']='Disponibile'.'|';
$product_data['shipping']='-1'.'|';
$product_data['codice produttore']=$product->getSku();


$product_data['end']='<endrecord>';


//sanitize data
foreach($product_data as $k=>$val){
$bad=array('"',"\r\n","\n","\r","\t");
$good=array(""," "," "," ","");
$product_data[$k] = str_replace($bad,$good,$val);
}

$feed_line = implode($product_data)."\r\n";
fwrite($handle, $feed_line);
fflush($handle);

}

//---------------------- WRITE THE FEED
fclose($handle);

}
catch(Exception $e){
die($e->getMessage());
}
?>

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