Guest CoastalData Posted March 6, 2009 Share Posted March 6, 2009 Hello, I've tried several times to use the Export to CSV function in CC, but it has never produced acceptable output, so today I went in and made several modifications that have fixed the problem, I think, entirely. The first problem I found seems a little too obvious, maybe there was some kind of corruption in my install??? Can't imagine why this worked at all... Starting at line 199 of export.inc.php, I found this code: $name = str_replace(array(" ","\t","\r","\n","\0","\x0B"," "),"",strip_tags($results[$i]['name'])); $name = str_replace(" ","",$name); $desc = str_replace(array(" ","\t","\r","\n","\0","\x0B"," "),"",strip_tags($results[$i]['description'])); $desc = str_replace(" ","",$desc); Notice the bad line breaks... I dunno, maybe PHP just ignores the white space before the semi, as does Perl, but it really should be this: $name = str_replace(array(" ","\t","\r","\n","\0","\x0B",""),"",strip_tags($results[$i]['name'])); $name = str_replace(" ","",$name); $desc = str_replace(array(" ","\t","\r","\n","\0","\x0B",""),"",strip_tags($results[$i]['description'])); $desc = str_replace(" ","",$desc); The next problem I found/fixed was that if the description field contains any quotes, this will screw things up, so I converted those to HTML entities like this: $desc = str_replace(" ","",$desc); $desc = str_replace("\"",""",$desc); Finally, I'm a Windows guy, so I want the file to be more easily usable in Excel, so I changed this: $ccContent .= $name.",".$results[$i]['productCode'].",".$desc.",".$results[$i]['price'].",".$results[$i]['sale_price'].",".$results[$i]['image'].",".$results[$i]['stock_level'].",".$results[$i]['useStockLevel'].",".$results[$i]['cat_id']."\r\n"; To this: $ccContent .= "\"".$name."\",\"".$results[$i]['productCode']."\",\"".$desc."\",\"".$results[$i]['price']."\",\"".$results[$i]['sale_price']."\",\"".$results[$i]['image']."\",\"".$results[$i]['stock_level']."\",\"".$results[$i]['useStockLevel']."\",\"".$results[$i]['cat_id']."\"\r\n"; Basically all that does is to wrap each and every field in double quotes, the way Excel likes it. OpenOffice may not have the same preferences for quoting, but I'm sure it'll deal with it equally well. Now, I'm not so sure the import function will handle these modifications without further modification to the import module... Maybe the "right" thing to do here would be to add a new option to the drop down menu like "Export to CSV (Excel)" and then add the appropriate "else if" to the code so that the existing format can still work as is, while simply adding on the new format. Either way, at the bare minimum, however, I think that the HTML entity for the quotes should be a fix for all to use. Hope this helps! --Jon Quote Link to comment Share on other sites More sharing options...
convict Posted March 6, 2009 Share Posted March 6, 2009 Great contribution but it would be worth to mention what is the CubeCart version because latest (4.3.0) has the double quotes already included. Well line breaks in space as character should be problem, it is worth to report this as a bug in our bug area at http://bugs.cubecart.com, thank you. Quote Link to comment Share on other sites More sharing options...
Guest CoastalData Posted March 6, 2009 Share Posted March 6, 2009 Hmm, Okay, cool -- How can I quickly get my running version #? I know I am running CC4, but not sure which release... Quote Link to comment Share on other sites More sharing options...
convict Posted March 6, 2009 Share Posted March 6, 2009 Hmm, Okay, cool -- How can I quickly get my running version #? I know I am running CC4, but not sure which release... Just login to admin area you should see the current version on admin home page. Quote Link to comment Share on other sites More sharing options...
Guest CoastalData Posted March 6, 2009 Share Posted March 6, 2009 Oh, right, duh, there it is... this is 4.2.3 that still had the bug Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.