Skip to content

Commit

Permalink
Fix bad characters in the price column when importing products into a…
Browse files Browse the repository at this point in the history
… Shelf. Fixes bug #12001.
  • Loading branch information
perlDreamer committed Jan 4, 2011
1 parent cb7ffb3 commit 6726466
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/7.x.x.txt
Expand Up @@ -17,6 +17,7 @@
- fixed #11994: recurring calendar entries
- fixed #11995: recurring calendar entries in trash
- fixed #11986: Finance::Quote can give invalid dates to StockData asset
- fixed #12001: Shelf product import mangles price

7.10.6
- fixed #11974: Toolbar icons unclickable in Webkit using HTML5
Expand Down
1 change: 1 addition & 0 deletions lib/WebGUI/Asset/Wobject/Shelf.pm
Expand Up @@ -190,6 +190,7 @@ sub importProducts {
my %productRow;
##Order the data according to the headers, in whatever order they exist.
@productRow{ @headers } = @{ $productRow };
$productRow{price} =~ tr/0-9.//cd;
##Isolate just the collateral from the other product information
my %productCollateral;
@productCollateral{ @collateralFields } = @productRow{ @collateralFields };
Expand Down
48 changes: 47 additions & 1 deletion t/Asset/Wobject/Shelf.t
Expand Up @@ -35,7 +35,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests

my $tests = 61;
my $tests = 65;
plan tests => 1 + $tests;

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -449,6 +449,52 @@ SKIP: {
$tag->commit;
WebGUI::Test->addToCleanup($tag);

#######################################################################
#
# import, funky data in the price column
#
#######################################################################

my $shelf3 = WebGUI::Asset->getRoot($session)->addChild({className => $class});

$pass = 0;
eval {
$pass = $shelf3->importProducts(
WebGUI::Test->getTestCollateralPath('productTables/dollarsigns.csv'),
);
};
ok($pass, 'Able to load a table with odd characters in the price column');
$e = Exception::Class->caught();
is($e, '', '... no exception thrown');
is($shelf3->getChildCount, 1, '...imported 1 child sku for shelf3 with old headers');

my $sign = $shelf3->getFirstChild();
my $signCollateral = $sign->getAllCollateral('variantsJSON');
cmp_deeply(
$signCollateral,
[
{
varSku => 'dollar signs',
shortdesc => 'Silver Dollar Signs',
price => '5.00',
weight => '0.33',
quantity => '1000',
variantId => ignore(),
},
],
'collateral set correctly for sign'
);


$shelf3->purge;
undef $shelf3;

##Clear out this tag so we can do downstream work.
my $tag = WebGUI::VersionTag->getWorking($session);
$tag->commit;
WebGUI::Test->addToCleanup($tag);


#######################################################################
#
# Template variables
Expand Down
2 changes: 2 additions & 0 deletions t/supporting_collateral/productTables/dollarsigns.csv
@@ -0,0 +1,2 @@
mastersku,varSku,title,shortdescription,price,weight,quantity
signs,dollar signs,Silver Dollar Signs,Silver Dollar Signs, $5.00 ,0.33,1000

0 comments on commit 6726466

Please sign in to comment.