Add support for the original sku entry in the header.

This commit is contained in:
Colin Kuskie 2008-09-29 23:26:34 +00:00
parent 84f38558cf
commit a61bd107fa
3 changed files with 30 additions and 1 deletions

View file

@ -159,6 +159,7 @@ sub importProducts {
$headers = <$table>;
chomp $headers;
$headers =~ tr/\r//d;
$headers =~ s/\bsku\b/varSku/;
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')

View file

@ -33,7 +33,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 48;
my $tests = 51;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -415,6 +415,30 @@ SKIP: {
is($shelf2->getChildCount, 2, 'imported 2 children skus for shelf2 with windows line endings fields');
$shelf2->purge;
undef $shelf2;
#######################################################################
#
# import, old sku column header
#
#######################################################################
$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 old style, sku instead of varSku');
$e = Exception::Class->caught();
is($e, '', 'No exception thrown on a file old headers');
is($shelf2->getChildCount, 2, 'imported 2 children skus for shelf2 with old headers');
$shelf2->purge;
undef $shelf2;
}
#----------------------------------------------------------------------------

View file

@ -0,0 +1,4 @@
mastersku,sku,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
1 mastersku sku title shortdescription price weight quantity
2 Software Windows-Vista Windows Vista Bad software 120 5.00 5000
3 Software Windows-XP Windows XP Mainly bad software 80 4.50 2000
4 Hardware X-box X-box Very expensive hardware 280 10 150