Export produktów do CSV z osCommerce do PrestaShop

Skrypt testowany na osCommerce Online Merchant v2.3
[php]

require('includes/application_top.php');

# Output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');

# Create a file pointer connected to the output stream
$output = fopen('php://output', 'w');

try {
# SQL for products with products extra images
$exportSQL = "SELECT p.products_id, p.products_price, p.products_quantity, p.products_image, p.products_status, p.products_model, pd.products_name, pd.products_description, m.manufacturers_name, cd.categories_name, concat(p.products_image, ',', GROUP_CONCAT(pi.image)) AS images
FROM products p
LEFT JOIN products_description pd
ON pd.products_id = p.products_id
LEFT JOIN manufacturers m
ON m.manufacturers_id = p.manufacturers_id
LEFT JOIN products_to_categories ptc
ON p.products_id = ptc.products_id
LEFT JOIN categories_description cd
ON ptc.categories_id = cd.categories_id
LEFT JOIN products_images pi
ON pi.products_id = p.products_id
WHERE pd.products_viewed <> 0 AND cd.language_id = 2
GROUP BY p.products_id
ORDER BY p.products_id";

$exportQuery = tep_db_query($exportSQL);

if (tep_db_num_rows($exportQuery) > 1) {
while ($exportList = tep_db_fetch_array($exportQuery)) {

//połączie dwóch kolumn oraz usunięcie duplikatów

$arrayImg = explode(',', $exportList['images']);
foreach ($arrayImg as &$img) {
if (!empty($img)) {
$img = "http://tomlot.eu/images/" . $img;
}
}
$exportList['images'] = implode(',', $arrayImg);

fputcsv($output, $exportList, ";");
}
}
} catch (PDOException $e) {
print "Error: " . $e->getMessage();
die();
}
[/php]

Wiedza: 
Praktyczna