migrate Product www_editVariant to FormBuilder

This commit is contained in:
Doug Bell 2011-01-25 14:11:53 -06:00
parent ed70aa8929
commit 3b4b729518
2 changed files with 111 additions and 40 deletions

View file

@ -1380,53 +1380,53 @@ sub www_editVariant {
return $self->session->privilege->insufficient() unless ($self->canEdit);
my $i18n = WebGUI::International->new($self->session,'Asset_Product');
my $data = $self->getCollateral("variantsJSON", 'variantId', $vid);
my $f = WebGUI::HTMLForm->new($self->session, -action=>$self->getUrl);
$f->hidden(
-name => 'func',
-value => 'editVariantSave',
my $f = WebGUI::FormBuilder->new($self->session, action=>$self->getUrl);
$f->addField( "hidden",
name => 'func',
value => 'editVariantSave',
);
$f->hidden(
-name => 'vid',
-value => $vid,
$f->addField( "hidden",
name => 'vid',
value => $vid,
);
$f->text(
-name => 'varSku',
-label => $i18n->get('variant sku'),
-hoverHelp => $i18n->get('variant sku description'),
-value => $data->{varSku},
$f->addField( "text",
name => 'varSku',
label => $i18n->get('variant sku'),
hoverHelp => $i18n->get('variant sku description'),
value => $data->{varSku},
);
$f->text(
-name => 'shortdesc',
-maxlength => 30,
-label => $i18n->get('shortdesc'),
-hoverHelp => $i18n->get('shortdesc description'),
-value => $data->{shortdesc},
$f->addField( "text",
name => 'shortdesc',
maxlength => 30,
label => $i18n->get('shortdesc'),
hoverHelp => $i18n->get('shortdesc description'),
value => $data->{shortdesc},
);
$f->float(
-name => 'price',
-label => $i18n->get(10),
-hoverHelp => $i18n->get('10 description'),
-value => $data->{price},
$f->addField( "float",
name => 'price',
label => $i18n->get(10),
hoverHelp => $i18n->get('10 description'),
value => $data->{price},
);
$f->float(
-name => 'weight',
-label => $i18n->get('weight'),
-hoverHelp => $i18n->get('weight description'),
-value => $data->{weight},
$f->addField( "float",
name => 'weight',
label => $i18n->get('weight'),
hoverHelp => $i18n->get('weight description'),
value => $data->{weight},
);
$f->integer(
-name => 'quantity',
-label => $i18n->get('quantity'),
-hoverHelp => $i18n->get('quantity description'),
-value => $data->{quantity},
$f->addField( "integer",
name => 'quantity',
label => $i18n->get('quantity'),
hoverHelp => $i18n->get('quantity description'),
value => $data->{quantity},
);
$f->yesNo(
-name => "proceed",
-label => $i18n->get('add another variant'),
-hoverHelp => $i18n->get('add another variant description'),
$f->addField( "yesNo",
name => "proceed",
label => $i18n->get('add another variant'),
hoverHelp => $i18n->get('add another variant description'),
);
$f->submit;
return $self->getAdminConsole->render($f->print, 'add variant');
$f->addField( "submit", name => "submit" );
return $f->toHtml;
}
#-------------------------------------------------------------------

View file

@ -36,7 +36,7 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
plan tests => 58; # Increment this number for each test you create
plan tests => 67; # Increment this number for each test you create
#----------------------------------------------------------------------------
# put your tests here
@ -411,3 +411,74 @@ cmp_deeply(
],
);
#----------------------------------------------------------------------------
# editVariant
my $mech = WebGUI::Test::Mechanize->new( config => WebGUI::Test->file );
$mech->get_ok( '/' );
$mech->session->user({ userId => 3 });
$mech->get_ok( $product->getUrl( 'func=editVariant' ) );
my %variantFlexo = (
varSku => "3370318",
shortdesc => "He just looks evil because he has a beard.",
price => "199.99",
weight => "100",
quantity => 1,
);
$mech->submit_form_ok({
fields => {
%variantFlexo,
proceed => 1,
},
}, 'add one new variant');
$product = $product->cloneFromDb;
cmp_deeply(
$product->getAllCollateral( 'variantsJSON' ),
[
{ %variantFlexo, variantId => ignore() },
],
);
my %variantBender = (
varSku => "2716057",
shortdesc => "He's just evil",
price => "109.99",
weight => "100",
quantity => 1,
);
$mech->submit_form_ok({
fields => {
%variantBender,
proceed => 0,
},
}, 'add one more new variant' );
$product = $product->cloneFromDb;
cmp_deeply(
$product->getAllCollateral( 'variantsJSON' ),
[
{ %variantFlexo, variantId => ignore() },
{ %variantBender, variantId => ignore() },
],
);
my $variant = $product->getAllCollateral( 'variantsJSON' )->[1];
$mech->get_ok( $product->getUrl( 'func=editVariant;vid=' . $variant->{variantId} ) );
$variantBender{variantId} = $variant->{variantId};
$variantBender{shortdesc} = "He found religion";
$variantBender{weight} = 99;
$variantBender{price} = 119.99;
$mech->submit_form_ok( {
fields => { %variantBender },
}, 'edit an existing variant' );
$product = $product->cloneFromDb;
cmp_deeply(
$product->getAllCollateral( 'variantsJSON' ),
[
{ %variantFlexo, variantId => ignore() },
{ %variantBender, variantId => ignore() },
],
);