예제 #1
0
/**
 * download a CSV version of a product type in importable format
 *
 * @return null
 */
function Products_adminTypesGetSampleImport()
{
    $ptypeid = (int) $_REQUEST['ptypeid'];
    if ($ptypeid) {
        $ptypes = dbAll('select * from products_types where id=' . $ptypeid);
    } else {
        $ptypes = dbAll('select * from products_types');
    }
    $are_any_for_sale = 0;
    // { get list of data field names
    $names = array();
    foreach ($ptypes as $p) {
        if ($p['is_for_sale']) {
            $are_any_for_sale = 1;
        }
        $dfs = json_decode($p['data_fields']);
        foreach ($dfs as $df) {
            if (!in_array($df->n, $names)) {
                $names[] = $df->n;
            }
        }
    }
    // }
    header('Content-type: text/csv; Charset=utf-8');
    header('Content-Disposition: attachment; filename="product-types-' . $ptypeid . '.csv"');
    // { header
    $row = array('_stocknumber', '_name', '_ean');
    if ($are_any_for_sale) {
        $row[] = '_price';
        $row[] = '_sale_price';
        $row[] = '_bulk_price';
        $row[] = '_bulk_amount';
        $row[] = '_stockcontrol_total';
    }
    foreach ($names as $n) {
        $row[] = $n;
    }
    $row[] = '_type';
    $row[] = '_categories';
    echo Products_arrayToCSV($row);
    // }
    // { sample rows
    foreach ($ptypes as $p) {
        $row = array('stock_number', 'name', 'barcode');
        if ($are_any_for_sale) {
            $row[] = '0.00';
            $row[] = '0.00';
            $row[] = '0.00';
            $row[] = '0';
            $row[] = '0';
        }
        foreach ($names as $n) {
            $row[] = '';
        }
        $row[] = $p['name'];
        $row[] = '';
        echo Products_arrayToCSV($row);
    }
    // }
    Core_quit();
}
예제 #2
0
파일: export.php 프로젝트: raylouis/kvwebme
<?php

/**
 * export products to CSV
 *
 * PHP version 5.2
 *
 * @category None
 * @package  None
 * @author   Kae Verens <*****@*****.**>
 * @license  GPL 2.0
 * @link     http://kvsites.ie/
 */
require_once 'datatable-libs.php';
require_once dirname(__FILE__) . '/../api.php';
$i = 0;
header('Content-type: text/csv; Charset=utf-8');
header('Content-Disposition: attachment; filename="nfgws-export.csv"');
echo '"' . join('","', $columns) . "\"\n";
for (; $i < $total_records; ++$i) {
    $arr = array();
    $p = Product::getInstance($products->product_ids[$i]);
    foreach ($columns as $name) {
        $arr[] = $p->getString($name);
    }
    echo Products_arrayToCSV($arr);
}