From 8b0e557ab912f55241c029202b5cc81dcf4c5906 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Sun, 18 May 2008 21:18:02 +0000 Subject: [PATCH] convert product accessories to use the new collateral API --- docs/upgrades/upgrade_7.5.10-7.5.11.pl | 26 +++++++++++++------------- lib/WebGUI/Asset/Sku/Product.pm | 17 ++++++++++++----- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/docs/upgrades/upgrade_7.5.10-7.5.11.pl b/docs/upgrades/upgrade_7.5.10-7.5.11.pl index db0fae72a..4a5444af8 100644 --- a/docs/upgrades/upgrade_7.5.10-7.5.11.pl +++ b/docs/upgrades/upgrade_7.5.10-7.5.11.pl @@ -806,7 +806,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 "\t\tAdding 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), @@ -1022,14 +1022,14 @@ sub updateUsersOfProductMacro { my $fixed = $session->db->prepare('update wobject set description=? where assetId=? and revisionDate=?'); while (my $wobject = $wobjSth->hashRef) { while ($wobject->{description} =~ m/\^Product\('? ([^),']+) /xg) { - printf "\t\tWorking on %s\n", $wobject->{assetId}; + #printf "\t\tWorking on %s\n", $wobject->{assetId}; my $identifier = $1; ##If this is a product sku, need to look up by productId; - printf "\t\t\tFound argument of %s\n", $identifier; + #printf "\t\t\tFound argument of %s\n", $identifier; my $assetId = $session->db->quickScalar('select distinct(assetId) from sku where sku=?',[$identifier]); - printf "\t\t\tsku assetId: %s\n", $assetId; + #printf "\t\t\tsku assetId: %s\n", $assetId; my $productAssetId = $assetId ? $assetId : $identifier; $wobject->{description} =~ s/\^Product\( [^)]+ \)/^AssetProxy($productAssetId)/x; - printf "\t\t\tUpdated description to%s\n", $wobject->{description}; + #printf "\t\t\tUpdated description to%s\n", $wobject->{description}; $fixed->execute([ $wobject->{description}, $wobject->{assetId}, $wobject->{revisionDate}, ]); } } @@ -1040,14 +1040,14 @@ sub updateUsersOfProductMacro { $fixed = $session->db->prepare('update snippet set snippet=? where assetId=? and revisionDate=?'); while (my $snippet = $snipSth->hashRef) { while ($snippet->{snippet} =~ m/\^Product\('? ([^),']+) /xg) { - printf "\t\tWorking on %s\n", $snippet->{assetId}; + #printf "\t\tWorking on %s\n", $snippet->{assetId}; my $identifier = $1; ##If this is a product sku, need to look up by productId; - printf "\t\t\tFound argument of %s\n", $identifier; + #printf "\t\t\tFound argument of %s\n", $identifier; my $assetId = $session->db->quickScalar('select distinct(assetId) from sku where sku=?',[$identifier]); - printf "\t\t\tsku assetId: %s\n", $assetId; + #printf "\t\t\tsku assetId: %s\n", $assetId; my $productAssetId = $assetId ? $assetId : $identifier; $snippet->{snippet} =~ s/\^Product\( [^)]+ \)/^AssetProxy($productAssetId)/x; - printf "\t\t\tUpdated snippet to%s\n", $snippet->{snippet}; + #printf "\t\t\tUpdated snippet to%s\n", $snippet->{snippet}; $fixed->execute([ $snippet->{snippet}, $snippet->{assetId}, $snippet->{revisionDate}, ]); } } @@ -1058,14 +1058,14 @@ sub updateUsersOfProductMacro { $fixed = $session->db->prepare('update template set template=? where assetId=? and revisionDate=?'); while (my $template = $tempSth->hashRef) { while ($template->{template} =~ m/\^Product\('? ([^),']+) /xg) { - printf "\t\tWorking on %s\n", $template->{assetId}; + #printf "\t\tWorking on %s\n", $template->{assetId}; my $identifier = $1; ##If this is a product sku, need to look up by productId; - printf "\t\t\tFound argument of %s\n", $identifier; + #printf "\t\t\tFound argument of %s\n", $identifier; my $assetId = $session->db->quickScalar('select distinct(assetId) from sku where sku=?',[$identifier]); - printf "\t\t\tsku assetId: %s\n", $assetId; + #printf "\t\t\tsku assetId: %s\n", $assetId; my $productAssetId = $assetId ? $assetId : $identifier; $template->{template} =~ s/\^Product\( [^)]+ \)/^AssetProxy($productAssetId)/x; - printf "\t\t\tUpdated template to%s\n", $template->{template}; + #printf "\t\t\tUpdated template to%s\n", $template->{template}; $fixed->execute([ $template->{template}, $template->{assetId}, $template->{revisionDate}, ]); } } diff --git a/lib/WebGUI/Asset/Sku/Product.pm b/lib/WebGUI/Asset/Sku/Product.pm index 7cdad2162..34deb5fe6 100644 --- a/lib/WebGUI/Asset/Sku/Product.pm +++ b/lib/WebGUI/Asset/Sku/Product.pm @@ -756,7 +756,14 @@ sub www_addAccessorySave { my $accessoryAssetId = $self->session->form->process('accessoryAccessId'); return "" unless $accessoryAssetId; - $self->setCollateral('accessoryJSON', 'new', { accessoryAssetId => $accessoryAssetId }); + $self->setCollateral( + 'accessoryJSON', + 'accessoryAssetId', + 'new', + { + accessoryAssetId => $accessoryAssetId + }, + ); return "" unless($self->session->form->process("proceed")); return $self->www_addAccessory(); } @@ -851,8 +858,8 @@ Delete an asset from the accessory list, by index. sub www_deleteAccessoryConfirm { my $self = shift; return $self->session->privilege->insufficient() unless ($self->canEdit); - $self->deleteCollateral('accessoryJSON', $self->session->form->process("aid")); - return ""; + $self->deleteCollateral('accessoryJSON', 'accessoryAssetId', $self->session->form->process('aid')); + return ''; } #------------------------------------------------------------------- @@ -1150,7 +1157,7 @@ sub www_editVariantSave { sub www_moveAccessoryDown { my $self = shift; return $self->session->privilege->insufficient() unless ($self->canEdit); - $self->moveCollateralDown('accessoryJSON', $self->session->form->process('aid')); + $self->moveCollateralDown('accessoryJSON', 'accessoryAssetId', $self->session->form->process('aid')); return ''; } @@ -1356,7 +1363,7 @@ sub view { $var{'addaccessory.label'} = $i18n->get(36); ##Need an index for collateral operations, and an assetId for asset instantiation. foreach my $collateral ( @{ $self->getAllCollateral('accessoryJSON') } ) { - my $id = $collateral->{collateralIndex}; + my $id = $collateral->{accessoryAssetId}; $segment = $self->session->icon->delete('func=deleteAccessoryConfirm&aid='.$id,$self->get('url'),$i18n->get(2)) . $self->session->icon->moveUp('func=moveAccessoryUp&aid='.$id,$self->get('url')) . $self->session->icon->moveDown('func=moveAccessoryDown&aid='.$id,$self->get('url'));