Convert accessory collateral to JSON based accessory collateral.

Add a product with accessory collateral to loadProducts.pl to test the upgrade.
This commit is contained in:
Colin Kuskie 2008-05-04 17:15:02 +00:00
parent 4da1f8314f
commit 2215e55bcb
2 changed files with 33 additions and 7 deletions

View file

@ -18,6 +18,7 @@ use WebGUI::Asset::Sku::Product;
use WebGUI::Workflow;
use File::Find;
use File::Spec;
use JSON;
my $toVersion = '7.5.11';
my $quiet; # this line required
@ -673,7 +674,7 @@ 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
printf "Adding variant to %s\n", $productData->{title} unless $quiet;
printf "\t\tAdding 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('variantsJSON', 'new', {
varSku => ($productData->{productNumber} || $session->id->generate),
@ -694,12 +695,24 @@ EOSQL1
$session->db->write('alter table Product add column relatedJSON mediumtext');
$session->db->write('alter table Product add column specificationJSON mediumtext');
##Get all Product assetIds
##For each assetId, get each type of collateral
##Convert the data to JSON and store it in Product with setCollateral (update)
##To duplicate across all revision, do a get and SQL update (with no revisionDate)
my $assetSth = $session->db->read('select distinct(assetId) from Product');
my $accessorySth = $session->db->read('select accessoryAssetId from Product_accessory where assetId=? order by sequenceNumber');
while (my ($assetId) = $assetSth->array) {
##For each assetId, get each type of collateral
##Convert the data to JSON and store it in Product with setCollateral (update)
##To duplicate across all revisions, do a get and SQL update (with no revisionDate)
$accessorySth->execute([$assetId]);
my @accessories = ();
while (my $acc = $accessorySth->hashRef()) {
push @accessories, $acc;
}
my $accJson = to_json(\@accessories);
$session->db->write('update Product set accessoryJSON=? where assetId=?',[$accJson, $assetId]);
}
$assetSth->finish;
##Drop collateral tables
#$session->db->write('drop table Product_accessory');
$session->db->write('drop table Product_accessory');
#$session->db->write('drop table Product_benefit');
#$session->db->write('drop table Product_feature');
#$session->db->write('drop table Product_related');
@ -714,7 +727,7 @@ EOSQL1
$session->config->deleteFromArray('assets', 'WebGUI::Asset::Wobject::Product');
$session->config->addToArray('assets', 'WebGUI::Asset::Sku::Product');
unlink '../../lib/WebGUI/Asset/Wobject/Product.pm';
#unlink '../../lib/WebGUI/Asset/Wobject/Product.pm';
return;
}

View file

@ -98,7 +98,7 @@ my $product4 = $root->addChild($properties4);
my $properties5 = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'four',
url => 'five',
price => 7.77,
title => 'extremely long title that will be truncated to only 30 chars in the variant',
description => 'fourth product',
@ -106,6 +106,19 @@ my $properties5 = {
my $product5 = $root->addChild($properties5);
my $propertiesa = {
className => 'WebGUI::Asset::Wobject::Product',
url => 'accessory Product',
price => 1.00,
title => 'accessory Product',
description => 'accessory Product',
};
my $producta = $root->addChild($propertiesa);
$session->db->write('insert into Product_accessory (assetId, accessoryAssetId, sequenceNumber) values (?,?,?)', [$producta->getId, $root->getId, 1]);
$session->db->write('insert into Product_accessory (assetId, accessoryAssetId, sequenceNumber) values (?,?,?)', [$producta->getId, WebGUI::Asset->getDefault($session)->getId, 2]);
$tag->commit;
diag "Done.";