Fix product exporting and importing through the Shelf.

Note that sku entries in the import and export file are now varSku.
This commit is contained in:
Colin Kuskie 2008-09-28 23:59:26 +00:00
parent 1c2993dd86
commit 79c5425bcf
8 changed files with 40 additions and 21 deletions

View file

@ -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

View file

@ -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;

View file

@ -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;

View file

@ -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',

View file

@ -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

1 mastersku sku varSku title shortdescription price weight quantity
2 t-shirt red-t-shirt red-t-shirt Colored T-Shirts Red T-Shirt 5.00 1.33 1000
3 t-shirt blue-t-shirt blue-t-shirt Colored T-Shirts Blue T-Shirt 5.25 1.33 2000
4 soda soda-sweet soda-sweet Sweet Soda-bottled in Oregon Sweet Soda 0.95 0.95 500

View file

@ -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

1 mastersku sku varSku title shortdescription price weight quantity
2 Kids-lashed red-t-shirt red-t-shirt Colored T-Shirts Red T-Shirt 5 1.33 1000
3 Kids-lashed blue-t-shirt blue-t-shirt Colored T-Shirts Blue T-Shirt 5.25 1.33 2000
4 soda soda-sweet soda-sweet Sweet Soda-bottled in Oregon Sweet Soda 0.95 0.95 500

View file

@ -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

1 mastersku,sku,title,shortdescription,price,weight,quantity mastersku,varSku,title,shortdescription,price,weight,quantity
2 ##alter existing with two collateral ##alter existing with two collateral
3 t-shirt,red-t-shirt,Colored T-Shirts,Red T-Shirt,5.00,1.33,500 t-shirt,red-t-shirt,Colored T-Shirts,Red T-Shirt,5.00,1.33,500
4 ##alter existing with one collateral ##alter existing with one collateral

View file

@ -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

1 mastersku,sku,title,shortdescription,price,weight,quantity mastersku,varSku,title,shortdescription,price,weight,quantity
2 ##alter a title ##alter a title
3 soda,soda-sweet,Sweet Soda-totally organic,Sweet Soda,1.00,0.85,500 soda,soda-sweet,Sweet Soda-totally organic,Sweet Soda,1.00,0.85,500
4 ##add new collateral to an existing product ##add new collateral to an existing product