I am having a bit of trouble right now.. I'm trying to create a php file to export products to a csv file and it's working pretty good.
My only problem is with the product description. I'm using the getDescription() function to get my product descriptions, but it inserts line breaks into the csv file, which won't work on import obviously. I'm trying to remove all line breaks and stuff, since I only want plain text for the descriptions.
I've tried using strip_tags, but it's doing weird things.. When I use strip_tags, the whole description is in one line like I want it to, but it also replaces all spaces with + and removes any of the German characters ..
Let me just show you what I mean. Here's the code I'm using:
<?php
error_reporting(E_ALL | E_STRICT);
define('MAGENTO_ROOT', getcwd());
$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
Mage::app();
$products = Mage::getModel("catalog/product")->getCollection();
$products->addAttributeToSelect('name');
$products->addAttributeToSelect('description');
$products->addAttributeToSelect('product_url');
$products->addAttributeToSelect('thumbnail');
$products->addAttributeToSelect('price');
$products->addAttributeToFilter('status', 1);//optional for only enabled products
//$products->addAttributeToFilter('visibility', 4);//optional for only visible products
$fp = fopen('export_moebelde.csv', 'w');
$csvHeader = array("art_nr", "art_name", "art_beschreibung", "art_url", "art_img_url","art_waehrung","art_preis","art_lieferkosten");
fputcsv( $fp, $csvHeader,";");
foreach ($products as $product){
$art_nr = $product->getSku();
$art_name = $product->getName();
$art_beschreibung = urlencode( strip_tags($product->getDescription()) );
$art_url = $product->getProductUrl();
$art_img_url = $product->getThumbnail();
$art_waehrung = "EUR";
$art_preis = $product->getFinalPrice();
$art_lieferkosten = "0";
// $category_ids = implode(',', $product->getCategoryIds());
fputcsv($fp, array($art_nr, $art_name, $art_beschreibung, $art_url, $art_img_url, $art_waehrung, $art_preis, $art_lieferkosten), "|");
}
fclose($fp);
?>
And here's the result:
jkfalieg-xxl|"Fiam Amigo XXL"|XXL+Liege+mit+Gestell+aus+Aluminium.Bezug%3A+Textiline+%28wetterfest+und+uv-best%C3%A4ndig%29.%0D%0A|https://www.zeitlos-einrichtung.info/fiam-amigo-xxl.html?SID=toarp61ih56l7610u5uf786qa0|/f/i/fiamamigo.jpg|EUR|195.0000|0
I know the product URL and the tumbnail URL need some work, but right now I just don't have a clue what to do about the description!
I appreciate any suggestions or tips you guys may have for me!