ExecuteS(' SELECT p.`id_product`, pl.`name`, p.`id_category_default`, cl.`name` as `cat_default` FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (pl.`id_product` = p.`id_product` AND pl.`id_lang` = 1) LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = p.`id_category_default` AND cl.`id_lang` = 1) '); foreach ($products as $key => &$row) { $row['category_default'] = $row['id_category_default'].' - '.$row['cat_default']; $row['categories'] = array(); foreach(Db::getInstance()->ExecuteS('SELECT cp.`id_category`, cl.`name` FROM `'._DB_PREFIX_.'category_product` cp LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (cl.`id_category` = cp.`id_category` AND cl.`id_lang` = 1) WHERE cp.`id_product` = '.(int)$row['id_product'].' AND cp.`id_category` !='.(int)$row['id_category_default'].' AND cl.id_category IS NOT NULL ') as $cat) { $row['categories'][] = $cat['id_category'].' - '.$cat['name']; } $row['categories'] = implode(', ', $row['categories']); } //echo "
";var_dump($products);echo "";die(); $fp = fopen(dirname(__FILE__).'/export_spec.csv', 'w'); $delim = ';'; $row_definition = array( 'id_product' => 'Product ID', 'name' => 'Nom du produit', 'id_category_default' => 'ID Categorie par default', 'category_default' => 'Categorie par default', 'categories' => 'Autres categories associees', ); $data=array(); foreach ($row_definition as $col) { $data[] = $col; } fputcsv ($fp,$data,$delim); foreach ($products as $item) { $data = array(); foreach ($row_definition as $key => $col) { $data[] = (isset($item[$key]) ? $item[$key] : ''); } fputcsv ($fp,array_map('utf8_decode',array_values($data)),$delim); } fclose($fp);