diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 2071fcd67..61862cf35 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -60,6 +60,7 @@ - fixed: Utility script skeleton now more complete and less annoying - 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 7.5.21 - fixed: purchase detail screen shows incorrectly in Safari diff --git a/docs/upgrades/upgrade_7.5.24-7.6.0.pl b/docs/upgrades/upgrade_7.5.24-7.6.0.pl index 660909c3a..247e7652c 100644 --- a/docs/upgrades/upgrade_7.5.24-7.6.0.pl +++ b/docs/upgrades/upgrade_7.5.24-7.6.0.pl @@ -20,6 +20,7 @@ use Getopt::Long; use WebGUI::Session; use WebGUI::Storage; use WebGUI::Asset; +use WebGUI::Asset::Sku::Product; my $toVersion = '7.6.0'; @@ -41,6 +42,7 @@ addAdHocMailGroups( $session ); makeAdminConsolePluggable( $session ); migrateAssetsToNewConfigFormat($session); deleteAdminBarTemplates($session); +repairBrokenProductSkus($session); finish($session); # this line required @@ -58,6 +60,22 @@ sub deleteAdminBarTemplates { print "DONE!\n" unless $quiet; } +#---------------------------------------------------------------------------- +sub repairBrokenProductSkus { + my $session = shift; + print "\tRepairing broken Products that were imported... " unless $quiet; + my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session); + while (my $product = $getAProduct->()) { + COLLATERAL: foreach my $collateral ($product->getAllCollateral('variantsJSON')) { + next COLLATERAL unless exists $collateral->{sku}; + $collateral->{varSku} = $collateral->{sku}; + delete $collateral->{sku}; + $product->setCollateral('variantsJSON', 'variantId', $collateral->{variantId}, $collateral); + } + } + print "DONE!\n" unless $quiet; +} + #---------------------------------------------------------------------------- sub migrateAssetsToNewConfigFormat { my $session = shift; diff --git a/lib/WebGUI/Asset/Wobject/Shelf.pm b/lib/WebGUI/Asset/Wobject/Shelf.pm index cb08117cb..50cc87b58 100644 --- a/lib/WebGUI/Asset/Wobject/Shelf.pm +++ b/lib/WebGUI/Asset/Wobject/Shelf.pm @@ -69,7 +69,7 @@ file will be named siteProductData.csv. sub exportProducts { my $self = shift; my $session = $self->session; - my @columns = qw{sku shortdescription price weight quantity}; + my @columns = qw{varSku shortdescription price weight quantity}; my $productData = WebGUI::Text::joinCSV(qw{mastersku title}, @columns) . "\n"; @columns = map { $_ eq 'shortdescription' ? 'shortdesc' : $_ } @columns; my $getAProduct = WebGUI::Asset::Sku::Product->getIsa($session); @@ -109,7 +109,7 @@ mastersku =item * -sku +varsku =item * @@ -160,7 +160,7 @@ sub importProducts { chomp $headers; 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-sku-title-weight') + unless (join(q{-}, sort @headers) eq 'mastersku-price-quantity-shortdescription-title-varSku-weight') and (scalar @headers == 7); my @productData = (); @@ -213,7 +213,7 @@ sub importProducts { my $collaterals = $product->getAllCollateral('variantsJSON'); my $collateralSet = 0; ROW: foreach my $collateral (@{ $collaterals }) { - next ROW unless $collateral->{sku} eq $productRow{sku}; + next ROW unless $collateral->{varSku} eq $productRow{varSku}; @{ $collateral}{ @collateralFields } = @productCollateral{ @collateralFields }; ##preserve the variant Id field, assign all others $product->setCollateral('variantsJSON', 'variantId', $collateral->{variantId}, $collateral); $collateralSet=1; diff --git a/t/Asset/Wobject/Shelf.t b/t/Asset/Wobject/Shelf.t index 0293f02e1..6f452ed1e 100644 --- a/t/Asset/Wobject/Shelf.t +++ b/t/Asset/Wobject/Shelf.t @@ -33,7 +33,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 44; +my $tests = 45; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -153,7 +153,7 @@ SKIP: { $sodaCollateral, [ { - sku => 'soda-sweet', + varSku => 'soda-sweet', shortdesc => 'Sweet Soda', price => 0.95, weight => 0.95, @@ -172,7 +172,7 @@ SKIP: { $shirtCollateral, [ { - sku => 'red-t-shirt', + varSku => 'red-t-shirt', shortdesc => 'Red T-Shirt', price => '5.00', weight => '1.33', @@ -180,7 +180,7 @@ SKIP: { variantId => ignore(), }, { - sku => 'blue-t-shirt', + varSku => 'blue-t-shirt', shortdesc => 'Blue T-Shirt', price => '5.25', weight => '1.33', @@ -204,7 +204,7 @@ SKIP: { my $productData = $productsOut->getFileContentsAsScalar($productsOut->getFiles->[0]); my @productData = split /\n/, $productData; is(scalar @productData, 4, 'productData should have 4 entries, 1 header + 3 data'); - is($productData[0], 'mastersku,title,sku,shortdescription,price,weight,quantity', 'header line is okay'); + is($productData[0], 'mastersku,title,varSku,shortdescription,price,weight,quantity', 'header line is okay'); @productData = map { [ WebGUI::Text::splitCSV($_) ] } @productData[1..3]; my ($sodas, $shirts) = ([], []); foreach my $productData (@productData) { @@ -246,7 +246,7 @@ SKIP: { $sodaCollateral, [ { - sku => 'soda-sweet', + varSku => 'soda-sweet', shortdesc => 'Sweet Soda', price => '1.00', weight => 0.85, @@ -263,7 +263,7 @@ SKIP: { $shirtCollateral, [ { - sku => 'red-t-shirt', + varSku => 'red-t-shirt', shortdesc => 'Red T-Shirt', price => '5.00', weight => '1.33', @@ -271,7 +271,7 @@ SKIP: { variantId => ignore(), }, { - sku => 'blue-t-shirt', + varSku => 'blue-t-shirt', shortdesc => 'Blue T-Shirt', price => '5.25', weight => '1.33', @@ -289,7 +289,7 @@ SKIP: { $recordCollateral, [ { - sku => 'track-16', + varSku => 'track-16', shortdesc => 'Track 16', price => '3.25', weight => '0.00', @@ -323,7 +323,7 @@ SKIP: { $shirtCollateral, [ { - sku => 'red-t-shirt', + varSku => 'red-t-shirt', shortdesc => 'Red T-Shirt', price => '5.00', weight => '1.33', @@ -331,7 +331,7 @@ SKIP: { variantId => ignore(), }, { - sku => 'blue-t-shirt', + varSku => 'blue-t-shirt', shortdesc => 'Blue T-Shirt', price => '5.25', weight => '1.33', @@ -348,7 +348,7 @@ SKIP: { $recordCollateral, [ { - sku => 'track-16', + varSku => 'track-16', shortdesc => 'Track 16', price => '3.25', weight => '0.00', @@ -356,7 +356,7 @@ SKIP: { variantId => ignore(), }, { - sku => 'track-9', + varSku => 'track-9', shortdesc => 'Track 9', price => '3.25', weight => '0.00', diff --git a/t/supporting_collateral/productTables/goodProductTable.csv b/t/supporting_collateral/productTables/goodProductTable.csv index 8107938f2..80b375a62 100644 --- a/t/supporting_collateral/productTables/goodProductTable.csv +++ b/t/supporting_collateral/productTables/goodProductTable.csv @@ -1,4 +1,4 @@ -mastersku,sku,title,shortdescription,price,weight,quantity +mastersku,varSku,title,shortdescription,price,weight,quantity t-shirt,red-t-shirt,Colored T-Shirts,Red T-Shirt,5.00,1.33,1000 t-shirt,blue-t-shirt,Colored T-Shirts,Blue T-Shirt,5.25,1.33,2000 soda,soda-sweet,Sweet Soda-bottled in Oregon,Sweet Soda,0.95,0.95,500 diff --git a/t/supporting_collateral/productTables/quotedTable.csv b/t/supporting_collateral/productTables/quotedTable.csv index 0befb12e3..976f448c8 100644 --- a/t/supporting_collateral/productTables/quotedTable.csv +++ b/t/supporting_collateral/productTables/quotedTable.csv @@ -1,4 +1,4 @@ -"mastersku","sku","title","shortdescription","price","weight","quantity" +"mastersku","varSku","title","shortdescription","price","weight","quantity" "Kids-lashed","red-t-shirt","Colored T-Shirts","Red T-Shirt",5,1.33,1000 "Kids-lashed","blue-t-shirt","Colored T-Shirts","Blue T-Shirt",5.25,1.33,2000 "soda","soda-sweet","Sweet Soda-bottled in Oregon","Sweet Soda",0.95,0.95,500 diff --git a/t/supporting_collateral/productTables/secondProductTable.csv b/t/supporting_collateral/productTables/secondProductTable.csv index d89899ba8..542d63042 100644 --- a/t/supporting_collateral/productTables/secondProductTable.csv +++ b/t/supporting_collateral/productTables/secondProductTable.csv @@ -1,4 +1,4 @@ -mastersku,sku,title,shortdescription,price,weight,quantity +mastersku,varSku,title,shortdescription,price,weight,quantity ##alter existing with two collateral t-shirt,red-t-shirt,Colored T-Shirts,Red T-Shirt,5.00,1.33,500 ##alter existing with one collateral diff --git a/t/supporting_collateral/productTables/thirdProductTable.csv b/t/supporting_collateral/productTables/thirdProductTable.csv index e7d0a51fc..bce0f172c 100644 --- a/t/supporting_collateral/productTables/thirdProductTable.csv +++ b/t/supporting_collateral/productTables/thirdProductTable.csv @@ -1,4 +1,4 @@ -mastersku,sku,title,shortdescription,price,weight,quantity +mastersku,varSku,title,shortdescription,price,weight,quantity ##alter a title soda,soda-sweet,Sweet Soda-totally organic,Sweet Soda,1.00,0.85,500 ##add new collateral to an existing product