Quantcast
Channel: Opinion: Shopify Community - Shopify Apps
Viewing all articles
Browse latest Browse all 11091

How to create and download a csv file from php script? by ss

$
0
0

Hi everyone,

I am a novice programmer and I searched a lot about my question but couldn't find a helpful solution or tutorial about this.

I want to add an option, so that if a user wants, he/she can create a CSV file with array elements and download it.

I installed private app, to download all the order details as csv format.

Still my situation is, when download click butoon, please refer the link,http://imgur.com/edit .

Please provide me some tutorial or solution or advice to implement it by myself. As I'm a novice please provide easy to implement solutions.

My csv.php code:

<?php 
$order = $_GET; 
$list[] = array_to_csv_download(array(
  array(1,2,3,4), // this array is going to be the first row
  array(1,2,3,4)), // this array is going to be the second row"numbers.csv"
);
$list = array_filter($list);
array_to_csv_download($list);
function array_to_csv_download($list) {
    $output = fopen("php://output", "w");
    foreach ($list as $row) {
        fputcsv($output, $row);
        //print_r($row); die;
    }
    fclose($output);
}
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=file.csv");
header("Pragma: no-cache");
header("Expires: 0");
?>

And my oauth.php code:

<?php
require_once 'lib/shopify.php';
require_once 'csv.php';
$t="4226b767fd10efdcbe234ab0c449eda6";
$sc = new ShopifyClient("https-selvar-myshopify-com.myshopify.com", $t, API_KEY, SECRET);
if(!isset($t))
{
if(!isset($_GET['signature']))
{
  	$url = $sc->getAuthorizeUrl("read_orders");
	header('Location: '.$url);
}
if(isset($_GET['code']))
{
	$accTok = $sc->getAccessToken($_GET['code']);
	echo "token=".$accTok;exit;
	$orders = $sc->call('GET', 'admin/orders.json', array('published_status'=>'published'));
	foreach($orders as $order) {
   	echo $order['id'];
    	echo $order['email'];
}
}
}
if(isset($t))
{
	$orders = $sc->call('GET', 'admin/orders.json', array('published_status'=>'published'));
	foreach($orders as $order) {
    	echo $order['id'];
    	echo $order['email'];
    	echo $order['currency'];
    	echo $order['fulfillment_status'];
    	echo $order['created_at'];
    	echo $order['total_price'];
    	echo $order['subtotal_price'];
	echo $order['order_number'];
	echo $order['shipping_lines'][0]['tax_lines'][0]['title'];

   	}
}
?>

Now what i m need is , Title is in coloum A1,B1,... and their values are in  coloum A2,B2,..

Thanks in advance!.


Viewing all articles
Browse latest Browse all 11091

Trending Articles