From 67264660f70ec907ac20bfaf826e64594727477a Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 3 Jan 2011 19:11:40 -0800 Subject: [PATCH] Fix bad characters in the price column when importing products into a Shelf. Fixes bug #12001. --- docs/changelog/7.x.x.txt | 1 + lib/WebGUI/Asset/Wobject/Shelf.pm | 1 + t/Asset/Wobject/Shelf.t | 48 ++++++++++++++++++- .../productTables/dollarsigns.csv | 2 + 4 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 t/supporting_collateral/productTables/dollarsigns.csv diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 6b2c20c96..e5e20ee1d 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -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 diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm index 37744b850..cb1a1f165 100644 --- a/lib/WebGUI/Asset/Wobject/Shelf.pm +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -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 }; diff --git a/t/Asset/Wobject/Shelf.t b/t/Asset/Wobject/Shelf.t index 41a70152d..b6b79da50 100644 --- a/t/Asset/Wobject/Shelf.t +++ b/t/Asset/Wobject/Shelf.t @@ -35,7 +35,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 61; +my $tests = 65; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -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 diff --git a/t/supporting_collateral/productTables/dollarsigns.csv b/t/supporting_collateral/productTables/dollarsigns.csv new file mode 100644 index 000000000..b20e7b9ac --- /dev/null +++ b/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