CSV를 가져 와서 데이터를 구문 분석하고 표준 형식으로 출력하는 CSV 변환기를 만들려고합니다.배열에 변수 저장
이렇게하려면 변환 할 CSV의 각 유형에 대해 약간의 데이터 맵을 만들어야합니다.
내가 원하는 것은 각 행 매핑을 해당 CSV의 해당 클래스에 저장 한 다음 foreach 루프를 사용할 때 변환기 클래스 내에서 사용하는 것입니다.
class CsvImporter {
public function exportCSV()
{
$headers = ['store','websites','attribute_set','type','category_ids','sku','has_options','name','image','small_image','thumbnail','cost','upc','price','special_price','weight','msrp','status','visibility','tax_class_id','description','short_description','qty','is_in_stock','product_name','store_id','product_type_id','manufacturer','pla_category','pla_stock','condition','mpn'];
$data = $this->parseCSV();
if ($this->feed = 'feed1'){
//return feed1 mapping
} else{
//return feed2 mapping
}
foreach($data as $row) {
$importData['store'] = //return values from class mapping here
$importData['website'] = //return values from class mapping here
$importData['attribute_set'] = //return values from class mapping here
$importData['type'] = //return values from class mapping here
$importData['category_ids'] = //return values from class mapping here
$importData['sku'] = //return values from class mapping here
$importData['has_options'] = //return values from class mapping here
$importData['name'] = //return values from class mapping here
$importData['image'] = //return values from class mapping here
$importData['small_image'] = //return values from class mapping here
$importData['thumbnail'] = //return values from class mapping here
$importData['cost'] = //return values from class mapping here
$importData['upc'] = //return values from class mapping here
$importData['price'] = //return values from class mapping here
$importData['special_price'] = //return values from class mapping here
$importData['weight'] = //return values from class mapping here
$importData['msrp'] = //return values from class mapping here
$importData['status'] = //return values from class mapping here
$importData['visibility'] = //return values from class mapping here
$importData['tax_class_id'] = //return values from class mapping here
$importData['description'] = //return values from class mapping here
$importData['short_description'] = //return values from class mapping here
$importData['qty'] = //return values from class mapping here
$importData['is_in_stock'] = //return values from class mapping here
$importData['product_name'] = //return values from class mapping here
$importData['store_id'] = //return values from class mapping here
$importData['product_type_id'] = //return values from class mapping here
$importData['manufacturer'] = //return values from class mapping here
$importData['pla_category'] = //return values from class mapping here
$importData['pla_stock'] = //return values from class mapping here
$importData['condition'] = //return values from class mapping here
$importData['mpn'] = //return values from class mapping here
}
fclose($handle);
}
}
class Feed1{
const feed = 'feed1';
const db = ''; //initialize db connection
private static $mapping =[
$this->store,
$this->website,
'Default',
'simple',
'',
$row['4'],
'0',
$row[8] . " " . $row[15],
'',
'';
'',
$row[9],
$row[6],
($row[9]/0.85) + $row[14],
'',
$row[14],
'',
'Enabled',
'"Catalog, Search"',
'Taxable Goods',
$row[16],
'',
$row[1],
($row[1] > 0) ? 1 : 0,
$row[15],
'',
'simple',
$row[8],
'285',
($row[1] > 0) ? 'in stock' : 'out of stock',
'new',
$row[4],
]
}
class Feed2{
const feed = 'feed2';
const db = ''; //initialize db connection
private static $mapping =[
$this->store,
$this->website,
'Default',
'simple',
'',
$row['0'],
'0',
$row[5] . " " . $row[1],
'',
'';
'',
$row[6],
$row[7],
$row[8],
'',
$row[9],
'',
'Enabled',
'"Catalog, Search"',
'Taxable Goods',
$row[12],
'',
$row[11],
($row[10] > 0) ? 1 : 0,
$row[3],
'',
'simple',
$row[4],
'285',
($row[17] > 0) ? 'in stock' : 'out of stock',
'new',
$row[15]
]
}