Display the minimum number of clicks and impressions that must be

bought by the user, in the buy ad space form.
tidy up code.  Fixes bug #10843
This commit is contained in:
Colin Kuskie 2009-08-28 00:17:08 +00:00
parent 95e979deda
commit dd89a77ba8
4 changed files with 161 additions and 128 deletions

View file

@ -1,4 +1,5 @@
7.7.19 7.7.19
- fixed #10843: Ad Sales: how many do I have to buy?
- fixed #10835: Ad Sales: Ad Space field not user-friendly - fixed #10835: Ad Sales: Ad Space field not user-friendly
- fixed #10841: Ad Sales: hover help spelling error - fixed #10841: Ad Sales: hover help spelling error
- fixed #10833: Calendar feeds not versioned, not duplicated - fixed #10833: Calendar feeds not versioned, not duplicated

View file

@ -153,6 +153,20 @@ sub getAddToCartForm {
#------------------------------------------------------------------- #-------------------------------------------------------------------
=head2 getAdSpace
Returns an AdSpace object for this Ad Sku.
=cut
sub getAdSpace {
my $self = shift;
my $adSpace = WebGUI::AdSpace->new($self->session,$self->get('adSpace'));
return $adSpace;
}
#-------------------------------------------------------------------
=head2 getClickDiscountText =head2 getClickDiscountText
returns the text to display the number of clicks purchasaed where discounts apply returns the text to display the number of clicks purchasaed where discounts apply
@ -458,56 +472,56 @@ sub view {
my $session = $self->session; my $session = $self->session;
my $options = $self->getOptions(); my $options = $self->getOptions();
my $i18n = WebGUI::International->new($session, "Asset_AdSku"); my $i18n = WebGUI::International->new($session, "Asset_AdSku");
my $adSpace = $self->getAdSpace;
my %var = ( my %var = (
formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl }) formHeader => WebGUI::Form::formHeader($session, { action=>$self->getUrl })
. WebGUI::Form::hidden( $session, { name=>"func", value=>"addToCart" }), . WebGUI::Form::hidden( $session, { name=>"func", value=>"addToCart" }),
formFooter => WebGUI::Form::formFooter($session), formFooter => WebGUI::Form::formFooter($session),
formSubmit => WebGUI::Form::submit( $session, { value => $i18n->get("form purchase button") }), formSubmit => WebGUI::Form::submit( $session, { value => $i18n->get("form purchase button") }),
error_msg => $options->{error_msg}, error_msg => $options->{error_msg},
hasAddedToCart => $self->{_hasAddedToCart}, hasAddedToCart => $self->{_hasAddedToCart},
continueShoppingUrl => $self->getUrl, continueShoppingUrl => $self->getUrl,
manageLink => $self->getUrl("func=manage"), manageLink => $self->getUrl("func=manage"),
adSkuTitle => $self->get('title'), adSkuTitle => $self->get('title'),
adSkuDescription => $self->get('description'), adSkuDescription => $self->get('description'),
formTitle => WebGUI::Form::text($session, { formTitle => WebGUI::Form::text($session, {
-name=>"formTitle", -name => "formTitle",
-value=>$options->{adtitle}, -value => $options->{adtitle},
-size=>40 -size => 40
-default=>'untitled', -defaultValue => 'untitled',
}), }),
formLink => WebGUI::Form::Url($session, { formLink => WebGUI::Form::Url($session, {
-name=>"formLink", -name=>"formLink",
-value=>$options->{link}, -value=>$options->{link},
-size=>40 -size=>40
-required=>1, }),
}), formImage => WebGUI::Form::File($session, {
formImage => WebGUI::Form::File($session, { -name=>"formImage",
-name=>"formImage", -value=>$options->{image},
-value=>$options->{image}, -size=>40
-size=>40 -forceImageOnly=>1,
-forceImageOnly=>1, }),
}),
formClicks => WebGUI::Form::Integer($session, { formClicks => WebGUI::Form::Integer($session, {
-name=>"formClicks", -name=>"formClicks",
-value=>$options->{clicks}, -value=>$options->{clicks},
-size=>40 -size=>40
-required=>1, }),
}), formImpressions => WebGUI::Form::Integer($session, {
formImpressions => WebGUI::Form::Integer($session, { -name=>"formImpressions",
-name=>"formImpressions", -value=>$options->{impressions},
-value=>$options->{impressions}, -size=>40
-size=>40 }),
-required=>1, formAdId => WebGUI::Form::Hidden($session, {
}), -name=>"formAdId",
formAdId => WebGUI::Form::Hidden($session, { -value=>$options->{adId} || '',
-name=>"formAdId", }),
-value=>$options->{adId} || '', clickPrice => $self->get('pricePerClick'),
}), impressionPrice => $self->get('pricePerImpression'),
clickPrice => $self->get('pricePerClick'), minimumClicks => $adSpace->get('minimumClicks'),
impressionPrice => $self->get('pricePerImpression'), minimumImpressions => $adSpace->get('minimumImpressions'),
clickDiscount => $self->getClickDiscountText, clickDiscount => $self->getClickDiscountText,
impressionDiscount => $self->getImpressionDiscountText, impressionDiscount => $self->getImpressionDiscountText,
); );
return $self->processTemplate(\%var,undef,$self->{_viewTemplate}); return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
} }
@ -521,66 +535,72 @@ Add this subscription to the cart.
=cut =cut
sub www_addToCart { sub www_addToCart {
my $self = shift; my $self = shift;
return $self->session->privilege->insufficient() unless $self->canView;
my $session = $self->session; my $session = $self->session;
my $i18n = $self->i18n; my $i18n = $self->i18n;
if ($self->canView) { my $form = $session->form;
my $form = $session->form; my @errors;
my @errors; #my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($session); # LATER should be createTemp
#my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($session); # LATER should be createTemp my $imageStorageId = $form->process('formImage', 'image'); # , $self->getOptions->{image});
my $imageStorageId = $form->process('formImage', 'image'); # , $self->getOptions->{image}); my $imageStorage = WebGUI::Storage->get($session,$imageStorageId);
my $imageStorage = WebGUI::Storage->get($session,$imageStorageId); my $code;
my $code; if( not defined $imageStorage ) {
if( not defined $imageStorage ) { $code = 1; } $code = 1;
elsif( $imageStorage->getErrorCount > 0 ) { $code = 2; } }
elsif( scalar(@{$imageStorage->getFiles}) == 0 ) { $code = 3; } elsif( $imageStorage->getErrorCount > 0 ) {
elsif( $imageStorage->isImage((@{$imageStorage->getFiles})[0]) ) { $code = 4; } $code = 2;
if( not defined $imageStorage }
or $imageStorage->getErrorCount > 0 elsif( scalar(@{$imageStorage->getFiles}) == 0 ) {
or scalar(@{$imageStorage->getFiles}) == 0 $code = 3;
# or $imageStorage->isImage((@{$imageStorage->getFiles})[0]) # not currently working }
) { elsif( $imageStorage->isImage((@{$imageStorage->getFiles})[0]) ) {
push @errors, $i18n->get('form error no image') . $code . eval { (@{$imageStorage->getFiles})[0] } ; $code = 4;
} }
my $title = $form->process('formTitle'); if( not defined $imageStorage
if($title eq '' ) { or $imageStorage->getErrorCount > 0
push @errors, $i18n->get('form error no title'); or scalar(@{$imageStorage->getFiles}) == 0) {
} push @errors, $i18n->get('form error no image') . $code . eval { (@{$imageStorage->getFiles})[0] } ;
my $link = $form->process('formLink','url'); }
if($link eq '' ) { my $title = $form->process('formTitle');
push @errors, $i18n->get('form error no link'); if($title eq '' ) {
} push @errors, $i18n->get('form error no title');
my $adId = $self->get('adSpace'); }
my $adSpace = WebGUI::AdSpace->new($session,$adId); my $link = $form->process('formLink','url');
my $clicks = $form->process('formClicks','integer'); if($link eq '' ) {
if($clicks < $adSpace->get('minimumClicks') ) { push @errors, $i18n->get('form error no link');
push @errors, sprintf($i18n->get('form error min clicks'), $adSpace->get('minimumClicks')); }
} my $adSpace = $self->getAdSpace;
my $impressions = $form->process('formImpressions','integer'); my $adId = $self->get('adId');
if($impressions < $adSpace->get('minimumImpressions') ) { my $clicks = $form->process('formClicks','integer');
push @errors, sprintf($i18n->get('form error min impressions'), $adSpace->get('minimumImpressions')); if($clicks < $adSpace->get('minimumClicks') ) {
} push @errors, sprintf($i18n->get('form error min clicks'), $adSpace->get('minimumClicks'));
if( @errors == 0 ) { }
$self->{_hasAddedToCart} = 1; my $impressions = $form->process('formImpressions','integer');
$self->addToCart({ if($impressions < $adSpace->get('minimumImpressions') ) {
adtitle => $title, push @errors, sprintf($i18n->get('form error min impressions'), $adSpace->get('minimumImpressions'));
link => $link, }
clicks => $clicks, if( @errors == 0 ) {
impressions => $impressions, $self->{_hasAddedToCart} = 1;
adId => $adId, $self->addToCart({
image => $imageStorageId, adtitle => $title,
}); link => $link,
} else { clicks => $clicks,
$self->applyOptions({ impressions => $impressions,
adtitle => $title, adId => $adId,
link => $link, image => $imageStorageId,
clicks => $clicks, });
impressions => $impressions, }
adId => $adId, else {
image => $imageStorageId, $self->applyOptions({
error_msg => join( '<br>', @errors ), adtitle => $title,
}); link => $link,
} clicks => $clicks,
impressions => $impressions,
adId => $adId,
image => $imageStorageId,
error_msg => join( '<br>', @errors ),
});
} }
return $self->www_view; return $self->www_view;
} }
@ -594,18 +614,18 @@ manage previously purchased ads
=cut =cut
sub www_manage { sub www_manage {
my $self = shift; my $self = shift;
my $check = $self->checkView; my $check = $self->checkView;
return $check if (defined $check); return $check if (defined $check);
$self->session->http->setLastModified($self->getContentLastModified); $self->session->http->setLastModified($self->getContentLastModified);
$self->session->http->sendHeader; $self->session->http->sendHeader;
$self->prepareManage; $self->prepareManage;
my $style = $self->processStyle($self->getSeparator); my $style = $self->processStyle($self->getSeparator);
my ($head, $foot) = split($self->getSeparator,$style); my ($head, $foot) = split($self->getSeparator,$style);
$self->session->output->print($head, 1); $self->session->output->print($head, 1);
$self->session->output->print($self->manage); $self->session->output->print($self->manage);
$self->session->output->print($foot, 1); $self->session->output->print($foot, 1);
return "chunked"; return "chunked";
} }
#------------------------------------------------------------------- #-------------------------------------------------------------------
@ -617,20 +637,20 @@ renew an ad
=cut =cut
sub www_renew { sub www_renew {
my $self = shift; my $self = shift;
my $session = $self->session; my $session = $self->session;
my $id = $session->form->get('Id'); my $id = $session->form->get('Id');
my $crud = WebGUI::AssetCollateral::Sku::Ad::Ad->new($session,$id); my $crud = WebGUI::AssetCollateral::Sku::Ad::Ad->new($session,$id);
my $ad = WebGUI::AdSpace::Ad->new($session,$crud->get('adId')); my $ad = WebGUI::AdSpace::Ad->new($session,$crud->get('adId'));
$self->applyOptions({ $self->applyOptions({
adtitle => $ad->get('title'), adtitle => $ad->get('title'),
clicks => $crud->get('clicksPurchased'), clicks => $crud->get('clicksPurchased'),
impressions => $crud->get('impressionsPurchased'), impressions => $crud->get('impressionsPurchased'),
link => $ad->get('url'), link => $ad->get('url'),
image => $ad->get('storageId'), image => $ad->get('storageId'),
adId => $crud->get('adId'), adId => $crud->get('adId'),
}); });
return $self->www_view; return $self->www_view;
} }
1; 1;

View file

@ -129,6 +129,18 @@ our $I18N = {
context => q|%f is the price charged for each impression of the ad.| context => q|%f is the price charged for each impression of the ad.|
}, },
'minimum impressions' => {
message => q|Must buy at least %d impressions|,
lastUpdated => 0,
context => q|%d is the number of impressions that must be bought.|
},
'minimum clicks' => {
message => q|Must buy at least %d clicks|,
lastUpdated => 0,
context => q|%d is the number of clicks that must be bought.|
},
'form manage title' => { 'form manage title' => {
message => q|Manage My Ads|, message => q|Manage My Ads|,
lastUpdated => 0, lastUpdated => 0,