<?php
$lang = 2;
$sql='SELECT p.`id_product`, '.implode(', ', $fields).'
FROM '._DB_PREFIX_.'product as p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product`)
WHERE pl.`id_lang`=' . $lang . ' GROUP BY p.`id_product`
';
$delimiter = $_REQUEST['delimiter'];
$exportlist = Db::getInstance()->ExecuteS($sql);
$fileName = 'products_stream.csv';
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header('Content-Description: File Transfer');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename={$fileName}");
header("Expires: 0");
header("Pragma: public");
$f = @fopen( 'php://output', 'w' );
fwrite($f, implode($delimiter, $titles) . "\r\n");
foreach($exportlist AS $export) {
$product = new Product($export['id_product'], true, $lang);
$tags = array();
$accessories = array();
$export_final = array();
$imagelinks = array();
$cats = array();
if(isset($export['id_category_default'])) {
$categories = $product->getIndexedCategories($export['id_product']);
foreach($categories as $cat) {
$category = new Category($cat['id_category'], $lang);
$cats[] = $category->name;
}
$export['id_category_default'] = implode(",", $cats);
}
if($inc_images) {
$link = new Link();
$images = $product->getImages($export['id_product']);
foreach($images as $image) {
$imagelinks[] = "http://" . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8').$link->getImageLink($product->link_rewrite, $product->id .'-'. $image['id_image']);
}
$export['images'] = implode(",", $imagelinks);
}
if(isset($export['id_manufacturer'])) {
$export['id_manufacturer'] = $product->manufacturer_name;
}
if(isset($export['meta_description'])) {
$export['meta_description'] = $product->meta_description;
}
if(isset($export['meta_title'])) {
$export['meta_title'] = $product->meta_title;
}
if(isset($export['meta_keywords'])) {
$export['meta_keywords'] = $product->meta_keywords;
}
if(isset($export['id_supplier'])) {
$export['id_supplier'] = $product->supplier_name;
}
if(isset($export['id_tax'])) {
$export['id_tax'] = $product->tax_rate;
}
if(isset($inc_tags))
{
$export['tags'] = $product->getTags(1);
}
if(isset($inc_accessories)) {
if($acc = $product->getAccessories(1, false)) {
foreach($acc as $acc_key => $acc_value)
{
$accessories[] = $acc_value['reference'];
}
$export['accessories'] = implode(',', $accessories);
} else {
$export['accessories'] = '';
}
}
if($_REQUEST['wcurrency'] == 1) {
$params['currency'] = Tools::setCurrency();
if(isset($export['price'])) {
$params['price'] = $product->price;
$export['price'] = $product->displayWtPriceWithCurrency($params, $smarty);
}
if(isset($export['wholesale_price'])) {
$params['price'] = $product->wholesale_price;
$export['wholesale_price'] = $product->displayWtPriceWithCurrency($params, $smarty);
}
}
foreach($export_fields as $field => $value) {
$export_final[$field] = iconv("UTF-8", "cp1250//TRANSLIT", $export[$field]);
}
fputcsv($f, $export_final, $delimiter, '"');
}
fclose($f);
?>