Let the product importer import files with windows style line endings.
This commit is contained in:
parent
72edbfd628
commit
de889434da
4 changed files with 32 additions and 1 deletions
|
|
@ -61,6 +61,7 @@
|
|||
- rfe: Teach Thingy to be a Web Service (SDH Consulting Group)
|
||||
- fixed: ~~~ showing up on my site.
|
||||
- fixed: Shelf/Product import export does not work
|
||||
- fixed: Shelf/Product import does not work with windows files
|
||||
|
||||
7.5.21
|
||||
- fixed: purchase detail screen shows incorrectly in Safari
|
||||
|
|
|
|||
|
|
@ -158,6 +158,7 @@ sub importProducts {
|
|||
my $headers;
|
||||
$headers = <$table>;
|
||||
chomp $headers;
|
||||
$headers =~ tr/\r//d;
|
||||
my @headers = WebGUI::Text::splitCSV($headers);
|
||||
WebGUI::Error::InvalidFile->throw(error => qq{Bad header found in the CSV file}, brokenFile => $filePath)
|
||||
unless (join(q{-}, sort @headers) eq 'mastersku-price-quantity-shortdescription-title-varSku-weight')
|
||||
|
|
@ -167,6 +168,7 @@ sub importProducts {
|
|||
my $line = 1;
|
||||
while (my $productRow = <$table>) {
|
||||
chomp $productRow;
|
||||
$productRow =~ tr/\r//d;
|
||||
$productRow =~ s/\s*#.+$//;
|
||||
next unless $productRow;
|
||||
local $_;
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 45;
|
||||
my $tests = 48;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -391,6 +391,30 @@ SKIP: {
|
|||
$e = Exception::Class->caught();
|
||||
is($e, '', 'No exception thrown on a file with quoted fields');
|
||||
is($shelf2->getChildCount, 3, 'imported 3 children skus for shelf2 with quoted fields');
|
||||
|
||||
$shelf2->purge;
|
||||
undef $shelf2;
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# import, windows line endings
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
$shelf2 = WebGUI::Asset->getRoot($session)->addChild({className => $class});
|
||||
|
||||
$pass = 0;
|
||||
eval {
|
||||
$pass = $shelf2->importProducts(
|
||||
WebGUI::Test->getTestCollateralPath('productTables/windowsTable.csv'),
|
||||
);
|
||||
};
|
||||
ok($pass, 'Able to load a table with windows style newlines');
|
||||
$e = Exception::Class->caught();
|
||||
is($e, '', 'No exception thrown on a file with quoted fields');
|
||||
is($shelf2->getChildCount, 2, 'imported 2 children skus for shelf2 with windows line endings fields');
|
||||
|
||||
$shelf2->purge;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
|
|||
4
t/supporting_collateral/productTables/windowsTable.csv
Normal file
4
t/supporting_collateral/productTables/windowsTable.csv
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
"mastersku","varSku","title","shortdescription","price","weight","quantity"
|
||||
"Software","Windows-Vista","Windows Vista","Bad software",120,5.00,5000
|
||||
"Software","Windows-XP","Windows XP","Mainly bad software",80,4.50,2000
|
||||
"Hardware","X-box","X-box","Very expensive hardware",280,10,150
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 75.
|
Loading…
Add table
Add a link
Reference in a new issue