-
Notifications
You must be signed in to change notification settings - Fork 15
/
create.php
31 lines (27 loc) · 825 Bytes
/
create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
<?php
require_once 'vendor/autoload.php';
use GetOptionKit\GetOptionKit;
$getopt = new GetOptionKit;
$getopt->add( 'n|number:=i' , 'option requires a integer value' );
try {
$result = $getopt->parse( $argv );
$number = $result->number ? $result->number:10;
} catch(Exception $e) {
echo 'Try: create.php --number=10';
exit;
}
$seedFile = 'seed.csv';
$reader = new Csv_Reader($seedFile, new Csv_Dialect());
$headerRow = $reader->getAssociativeRow();
$seedRow = $reader->getAssociativeRow();
$writer = new Csv_Writer(STDOUT, new Csv_Dialect(array(
'quoting' => Csv_Dialect::QUOTE_ALL
)));
$writer->writeRow($headerRow);
for($i=1; $i<=$number; $i++) {
$productRow = array_merge($seedRow, array(
'sku' => 'sku-'.$i,
'name' => 'product '.$i,
));
$writer->writeRow($productRow);
}