我使用 CSV 导入插件打开购物车,默认情况下,如果产品缺少任何列字段,则完全跳过产品。无论如何我可以读取文件并用'null'或0替换所有空字段并将其发送回代码。
跳过下面的检查会导致读取/放置格式的偏移!
$fh = fopen($file, 'r');
if(!$fh) die('File no good!');
// Get headings
$headings = fgetcsv($fh, 0, $delim);
$num_cols = count($headings);
$num_rows = 0;
//Read the file as csv
while (($row = fgetcsv($fh, 0, $delim)) !== FALSE) {
//missed product if num columns in this row not the same as num headings
if (count($row) != $num_cols) {
$this->total_items_missed++;
continue;
}
for ($i=0; $i<count($headings); $i++) {
$raw_prod[$headings[$i]] = $row[$i];
}