remove Parameters and Options from the Sku Product

This commit is contained in:
Colin Kuskie 2008-04-28 22:41:38 +00:00
parent aae6a32df4
commit 99e5694513
3 changed files with 0 additions and 273 deletions

View file

@ -561,8 +561,6 @@ sub mergeProductsWithCommerce {
my $session = shift;
print "\tMerge old Commerce Products to new SKU based Products.\n" unless ($quiet);
## Add the parameter and variants columns
$session->db->write("alter table Product add column parameters mediumtext");
$session->db->write("alter table Product add column variants mediumtext");
return 1;
}

View file

@ -136,16 +136,6 @@ sub definition {
deleteFileUrl=>$session->url->page("func=deleteFileConfirm;file=warranty;filename="),
defaultValue=>undef
},
parameters=>{ ##Parameters and options
tab => "properties",
fieldType=>"hidden",
defaultValue=>'{}',
},
variants=>{ ##Which variants are enabled and/or disabled
tab => "properties",
fieldType=>"hidden",
defaultValue=>'{}',
},
);
push(@{$definition}, {
assetName=>$i18n->get('assetName'),
@ -281,21 +271,6 @@ sub getFileUrl {
return $store->getUrl($self->getFilename($store));
}
#-------------------------------------------------------------------
=head2 getParams
Return the parameter data from this product as a perl data structure,
rather than the internally stored JSON.
=cut
sub getParams {
my $self = shift;
my $structure = JSON::from_json($self->get('parameters'));
return $structure;
}
#-------------------------------------------------------------------
sub getPrice {
my $self = shift;
@ -642,33 +617,6 @@ sub setCollateral {
return $properties->{$keyName};
}
#-------------------------------------------------------------------
=head2 setParamData ($paramData)
Set the product's parameter data as a perl data structure. This is
stored in the db as JSON. This adds a revision to the Product, since
parameters and options are stored directly in the asset table.
Returns a copy to the new version of the Product Asset.
=head2 $paramData
A hash of arrays. The keys in the hash are names of parameters, and the
values of the arrays are subhashes, containing the names of options as
well as price and weight modifiers.
=cut
sub setParamData {
my $self = shift;
my $paramData = shift;
my $json = JSON::to_json($paramData);
my $newSelf = $self->addRevision({parameters => $json});
return $newSelf;
}
#-------------------------------------------------------------------
sub www_addAccessory {
my $self = shift;
@ -900,169 +848,6 @@ sub www_editFeatureSave {
return $self->www_editFeature("new");
}
#-------------------------------------------------------------------
sub www_editParameter {
my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit);
my $param = shift || $self->session->form->get('name') || 'new';
my $allParams = $self->getParams;
$param = "new" unless exists $allParams->{$param};
my $i18n = WebGUI::International->new($self->session,'Asset_Product');
my $f = WebGUI::HTMLForm->new($self->session,-action=>$self->getUrl);
$f->hidden(
-name => "func",
-value => "editParameterSave",
);
$f->hidden(
-name => "origname",
-value => $param,
);
$f->text(
-name => 'name',
-label => $i18n->get('edit parameter name'),
-hoverHelp => $i18n->get('edit parameter name description'),
-value => $param,
-maxlength => 64,
);
$f->submit;
return $self->getAdminConsole->render($f->print, "edit parameter");
}
#-------------------------------------------------------------------
sub www_editParameterSave {
my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit);
my $param = $self->session->form->get('name');
my $origname = $self->session->form->get('origname');
my $allParams = $self->getParams;
if (($origname ne "new") and ($origname ne $param)) {
##Rename existing param
my @options = @{ $allParams->{$origname} };
$allParams->{$param} = \@options;
delete $allParams->{$origname};
my $newSelf = $self->setParamData($allParams);
return $newSelf->www_editParameter($param);
}
elsif ($origname eq "new") {
$allParams->{$param} = [];
my $newSelf = $self->setParamData($allParams);
return $newSelf->www_editParameterOptions($param);
}
return $self->www_view();
}
#-------------------------------------------------------------------
sub www_editParameterOptions {
my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit);
my $session = $self->session;
my $param = shift || $session->form->get('name');
my $value = shift || $session->form->get('value') || "new";
my $allParams = $self->getParams;
##You cannot add an option to a non-existant parameter.
if (! exists $allParams->{$param}) {
$session->errorHandler->warn("$param is not in param data");
return $self->www_editParameter($param);
}
##Convert to a byname interface
my $option = {};
OPTION: foreach my $subOption (@{ $allParams->{$param} }) {
if ($subOption->{value} eq $value) {
$option = $subOption;
last OPTION;
}
}
my $i18n = WebGUI::International->new($session,'Asset_Product');
my $f = WebGUI::HTMLForm->new($session,-action=>$self->getUrl);
$f->hidden(
-name => "func",
-value => "editParameterOptionSave",
);
##Editing an existing option
if (defined $value) {
$f->hidden(
-name => "origValue",
-value => $value,
);
}
$f->readOnly(
-name => 'name',
-value => $param,
);
$f->text(
-name => 'value',
-label => $i18n->get('edit option value'),
-hoverHelp => $i18n->get('edit option value description'),
-value => $value,
-maxlength => 64,
);
$f->float(
-name => 'priceModifier',
-label => $i18n->get('edit option price modifier'),
-hoverHelp => $i18n->get('edit option price modifier description'),
-value => $session->form->process("priceModifier") || $option->{priceModifier},
-maxlength => 11,
);
$f->float(
-name => 'weightModifier',
-label => $i18n->get('edit option weight modifier'),
-hoverHelp => $i18n->get('edit option weight modifier description'),
-value => $session->form->process("weightModifier") || $option->{weightModifier},
-maxlength => 7,
);
$f->submit;
return $self->getAdminConsole->render($f->print, "edit option");
}
#-------------------------------------------------------------------
sub www_editParameterOptionsSave {
my $self = shift;
return $self->session->privilege->insufficient() unless ($self->canEdit);
my $form = $self->session->form;
my $param = $form->get('name');
my $value = $form->get('value');
my $origValue = $form->get('origValue');
my $allParams = $self->getParams();
if (! exists $allParams->{$param}) {
$self->session->errorHandler->warn("$param is not an existing parameter");
return $self->www_editParameter($param);
}
my $paramData = $allParams->{$param};
if (($origValue ne "new") and ($origValue ne $value)) {
##Rename existing option
my $option = {};
OPTION: foreach my $subOption (@{ $allParams->{$param} }) {
if ($subOption->{value} eq $value) {
$option = $subOption;
last OPTION;
}
}
##Warning for a non-existant option
if (! keys %{ $option } ) {
$self->session->errorHandler->warn("$value is not an existing option of $param");
return $self->www_editParameter($param, $value);
}
$option->{value} = $value;
$option->{priceModifer} = $form->get('priceModifier');
$option->{weightModifer} = $form->get('weightModifier');
}
elsif ($origValue eq "new") {
my $newOption = {};
$newOption->{value} = $value;
$newOption->{priceModifer} = $form->get('priceModifier');
$newOption->{weightModifer} = $form->get('weightModifier');
push @{ $paramData }, $newOption;
}
return $self->www_view();
}
#-------------------------------------------------------------------
sub www_editSpecification {
my $self = shift;

View file

@ -634,62 +634,6 @@ be useful, others may not.|,
lastUpdated => 1164841201
},
'edit parameter name' => {
message => q|Name|,
lastUpdated => 1208130239,
context => q|The form label for the name field in editParameter|,
},
'edit parameter name description' => {
message => q|<p>The name of this parameter.</p>|,
lastUpdated => 1208130267,
},
'edit parameter' => {
message => q|Edit product parameter|,
lastUpdated => 1208130542,
context => q|The name of the editParameter form|
},
'edit option' => {
message => q|Edit product parameter option|,
lastUpdated => 1208144888,
context => q|The name of the editParameter form|
},
'edit option value' => {
message => q|Value|,
lastUpdated => 1208320423,
context => q|The form label for the value field in editParameterOption|
},
'edit option value description' => {
message => q|<p>The value of this option (ie. 'Blue').</p>|,
lastUpdated => 1208320422,
},
'edit option price modifier' => {
message => q|Price modifier|,
lastUpdated => 1208292477,
context => q|The form label for the priceModifier field in editProductParameterOption|
},
'edit option price modifier description' => {
message => q|<p>The amount this option adds to the default price for product variants containig this option.</p>|,
lastUpdated => 1146606364,
},
'edit option weight modifier' => {
message => q|Weight modifier|,
lastUpdated => 1208292479,
context => q|The form label for the weightModifier field in editProductParameterOption|
},
'edit option weight modifier description' => {
message => q|<p>The weight this option adds to the default weight for product variants consisting of this option.</p>|,
lastUpdated => 1208292519,
},
};
1;