Import: Column names have duplicates
The exception with the error message you stated is triggered in exactly one place (code slightly truncated for readability):
final public function __construct($source)
{
$this->_source = $source;
$this->_init();
// validate column names consistency
if (is_array($this->_colNames) && !empty($this->_colNames)) {
$this->_colQuantity = count($this->_colNames);
if (count(array_unique($this->_colNames)) != $this->_colQuantity) {
Mage::throwException(Mage::helper('importexport')->__('Column names have duplicates'));
}
}
}
This means, count(array_unique($this->_colNames))
must be unequal to $this->_colQuantity
The $_colNames
array is set in Mage_ImportExport_Model_Import_Adapter_Csv::rewind()
(which is called during _init()
.
Once again, the code is slightly truncated for readability:
public function rewind()
{
// rewind resource, reset column names, read first row as current
rewind($this->_fileHandler);
$this->_colNames = fgetcsv($this->_fileHandler, null, $this->_delimiter, $this->_enclosure);
}
The $_delimiter
is set to ,
, the $_enclosure
is set to "
.
To try to reproduce the issue, if I copy the CSV extract from your question into a file called test.csv and run the following code:
$f = fopen('test.csv', 'r');
$names = fgetcsv($f, null, ',', '"');
$qty = count($names);
$uniqueQty = count(array_unique($names));
printf("%d records, %d unique records\n", $qty, $uniqueQty);
it produces the following output:
29 records, 29 unique records
This means, your CSV file is fundamentally okay. The difference must be somewhere else.
Looking at how array_unique
works, there is a note how the type handling of array elements changed in PHP 5.2.9: http://php.net/manual/en/function.array-unique.php#refsect1-function.array-unique-changelog
To reproduce the issue, I re-ran my test-script with the SORT_REGULAR
option set, but this still gives the same result (which is logical, since reading a file only can give string values).
At this time I believe the difference must be in the CSV file you are using. The Unix and the Windows newline characters (\n
and \r\n
) are both recognized by the fgetcsv()
command, but the old MacOS style newline character (\r
) would actually lead to the behavior you are experiencing.
I can't know if that is the reason why you are experiencing the issue, but I suggest you check the CSV file (again). It might also help if you provide a download link somewhere to the unmodified file (no pastebin), so any non-printable characters are preserved.
It might also help if you post the PHP version you are using.