Handle null productNumbers in the Product variant translation.

Update the product loading script to add more products.
This commit is contained in:
Colin Kuskie 2008-05-01 22:38:14 +00:00
parent 94209d6edb
commit bef82ef65f
2 changed files with 44 additions and 5 deletions

View file

@ -14,6 +14,7 @@ use Getopt::Long;
use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::Asset;
use WebGUI::Asset::Sku::Product;
use File::Find;
use File::Spec;
@ -612,7 +613,7 @@ EOSQL
$toSku->execute([
$product->{assetId},
$product->{revisionDate},
$product->{productNumber},
($product->{productNumber} || $session->id->generate),
$product->{description},
$product->{displayTitle},
]);
@ -635,9 +636,10 @@ SELECT p.assetId, p.price, p.productNumber, p.revisionDate, a.title, s.sku
EOSQL1
while (my $productData = $productQuery->hashRef()) {
##Truncate title to 30 chars for short desc
my $product = WebGUI::Asset::Wobject::Product->new($session, $productData->{assetId}, 'WebGUI::Asset::Sku::Product', $productData->{revisionDate});
printf "Adding variant to %s\n", $productData->{title} unless $quiet;
my $product = WebGUI::Asset::Sku::Product->new($session, $productData->{assetId}, 'WebGUI::Asset::Sku::Product', $productData->{revisionDate});
$product->setCollateral('Product_variants', 'varSku', {
varSku => $productData->{productNumber},
varSku => ($productData->{productNumber} || $session->id->generate),
mastersku => $product->get('sku'),
shortdesc => substr($productData->{title}, 0, 30),
price => $productData->{price},

View file

@ -9,8 +9,15 @@
# http://www.plainblack.com info@plainblack.com
#------------------------------------------------------------------
# Write a little about what this script tests.
#
# This "test" script shoves products into the table so that the upgrade translation
# process can be tested.
#
# Here's what we're looking for after the upgrade runs.
# 1) Correct number of products translated
# 2) All revisions translated
# 3) Variants created for each Product Wobject
# 4) If no productNumber is defined, then it makes one for you.
# 5) Titles are truncated to 30 characters and used as the short description
#
use FindBin;
@ -69,6 +76,36 @@ $tag = WebGUI::VersionTag->getWorking($session);
my $product1a = $product1->addRevision({price => 11.11});
my $properties3 = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'three',
price => 20.00,
title => 'no product number',
description => 'third product',
};
my $product3 = $root->addChild($properties3);
my $properties4 = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'four',
price => 7.77,
title => 'no product number',
description => 'fourth product',
};
my $product4 = $root->addChild($properties4);
my $properties5 = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'four',
price => 7.77,
title => 'extremely long title that will be truncated to only 30 chars in the variant',
description => 'fourth product',
};
my $product5 = $root->addChild($properties5);
$tag->commit;
diag "Done.";