done!
I'd like to thank all the little people because I wouldn't be here if it wasn't for you. ;)
This commit is contained in:
parent
e0ef9d3c6e
commit
b1bd7e6205
3 changed files with 27 additions and 22 deletions
|
|
@ -1,8 +1,5 @@
|
||||||
package WebGUI::Asset::Sku::Ad;
|
package WebGUI::Asset::Sku::Ad;
|
||||||
|
|
||||||
use lib '/root/pb/lib';
|
|
||||||
use dav;
|
|
||||||
|
|
||||||
=head1 LEGAL
|
=head1 LEGAL
|
||||||
|
|
||||||
-------------------------------------------------------------------
|
-------------------------------------------------------------------
|
||||||
|
|
@ -222,20 +219,13 @@ get the price for this purchase
|
||||||
|
|
||||||
sub getPrice {
|
sub getPrice {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
dav::log 'getPrice';
|
|
||||||
my $options = $self->getOptions;
|
my $options = $self->getOptions;
|
||||||
my $impressionCount = $options->{impressions} || $self->{formImpressions};
|
my $impressionCount = $options->{impressions} || $self->{formImpressions};
|
||||||
dav::log 'getPrice::impressionCount=', $impressionCount;
|
|
||||||
my $clickCount = $options->{clicks};
|
my $clickCount = $options->{clicks};
|
||||||
dav::log 'getPrice::clickCount=', $clickCount;
|
|
||||||
my $impressionDiscount = getDiscountAmount($self->get('impressionDiscounts'),$impressionCount );
|
my $impressionDiscount = getDiscountAmount($self->get('impressionDiscounts'),$impressionCount );
|
||||||
dav::log 'getPrice::impressionDiscount=', $impressionDiscount;
|
|
||||||
my $clickDiscount = getDiscountAmount($self->get('clickDiscounts'),$clickCount );
|
my $clickDiscount = getDiscountAmount($self->get('clickDiscounts'),$clickCount );
|
||||||
dav::log 'getPrice::clickDiscount=', $clickDiscount;
|
|
||||||
my $impressionPrice = $self->get('pricePerImpression') * ( 100 - $impressionDiscount ) / 100 ;
|
my $impressionPrice = $self->get('pricePerImpression') * ( 100 - $impressionDiscount ) / 100 ;
|
||||||
dav::log 'getPrice::impressionPrice=', $impressionPrice;
|
|
||||||
my $clickPrice = $self->get('pricePerClick') * ( 100 - $clickDiscount ) / 100 ;
|
my $clickPrice = $self->get('pricePerClick') * ( 100 - $clickDiscount ) / 100 ;
|
||||||
dav::log 'getPrice::clickPrice=', $clickPrice;
|
|
||||||
return sprintf "%.2f", $impressionPrice * $impressionCount + $clickPrice * $clickCount;
|
return sprintf "%.2f", $impressionPrice * $impressionCount + $clickPrice * $clickCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -355,7 +345,7 @@ sub onRemoveFromCart {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $item = shift;
|
my $item = shift;
|
||||||
my $options = $self->getOptions;
|
my $options = $self->getOptions;
|
||||||
# TODO figure this out WebGUI::Storage->new($self->session,$options->{'image'})->delete;
|
WebGUI::Storage->new($self->session,$options->{'image'})->delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -367,7 +357,25 @@ delete the add if it gets refunded
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub onRefund {
|
sub onRefund {
|
||||||
# TODO delete the ad...
|
my $self = shift;
|
||||||
|
my $item = shift;
|
||||||
|
my $ad;
|
||||||
|
|
||||||
|
my $iterator = WebGUI::AssetCollateral::Sku::Ad::Ad->getAllIterator($self->session,{
|
||||||
|
constraints => [ { "transactionItemId = ?" => $item->getId } ],
|
||||||
|
});
|
||||||
|
my $crud = $iterator->();
|
||||||
|
|
||||||
|
my $ad = WebGUI::AdSpace::Ad->new($self->session,$crud->get('adId'));
|
||||||
|
$ad = WebGUI::AdSpace::Ad->new($self->session,$crud->get('adId'));
|
||||||
|
my $clicks = $ad->get('clicksBought') - $crud->get('clicksPurchased');
|
||||||
|
my $impressions = $ad->get('impressionsBought') - $crud->get('impressionsPurchased') ;
|
||||||
|
$ad->set({
|
||||||
|
clicksBought => $clicks,
|
||||||
|
impressionsBought => $impressions,
|
||||||
|
});
|
||||||
|
|
||||||
|
$crud->delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
@ -380,13 +388,10 @@ returns an array of array ref's that are extracted from the discount description
|
||||||
|
|
||||||
sub parseDiscountText {
|
sub parseDiscountText {
|
||||||
my $discountDescription = shift;
|
my $discountDescription = shift;
|
||||||
dav::log $discountDescription;
|
|
||||||
my @lines = split "\n", $discountDescription;
|
my @lines = split "\n", $discountDescription;
|
||||||
my @discounts;
|
my @discounts;
|
||||||
foreach my $line ( @lines ) {
|
foreach my $line ( @lines ) {
|
||||||
dav::log $line;
|
|
||||||
if( $line =~ /^(\d+)\@(\d+)/ ) {
|
if( $line =~ /^(\d+)\@(\d+)/ ) {
|
||||||
dav::log 'match';
|
|
||||||
push @discounts, [ $1, $2 ];
|
push @discounts, [ $1, $2 ];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -508,7 +513,6 @@ sub www_addToCart {
|
||||||
my $form = $self->session->form;
|
my $form = $self->session->form;
|
||||||
my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($self->session); # LATER should be createTemp
|
my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($self->session); # LATER should be createTemp
|
||||||
my $imageStorageId = $form->process('formImage', 'image', $imageStorage->getId);
|
my $imageStorageId = $form->process('formImage', 'image', $imageStorage->getId);
|
||||||
# TODO error in case image does not upload
|
|
||||||
my $cartInfo = {
|
my $cartInfo = {
|
||||||
adtitle => $form->process('formTitle'),
|
adtitle => $form->process('formTitle'),
|
||||||
link => $form->process('formLink','url'),
|
link => $form->process('formLink','url'),
|
||||||
|
|
@ -517,7 +521,6 @@ sub www_addToCart {
|
||||||
adId => $form->process('formAdId'),
|
adId => $form->process('formAdId'),
|
||||||
image => $imageStorageId,
|
image => $imageStorageId,
|
||||||
};
|
};
|
||||||
dav::dump 'addToCart:data:', $cartInfo;
|
|
||||||
$self->addToCart($cartInfo);
|
$self->addToCart($cartInfo);
|
||||||
}
|
}
|
||||||
return $self->www_view;
|
return $self->www_view;
|
||||||
|
|
@ -558,7 +561,6 @@ 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');
|
||||||
dav::log 'id=',$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({
|
||||||
|
|
|
||||||
|
|
@ -120,13 +120,13 @@ our $I18N = {
|
||||||
'form purchase per click' => {
|
'form purchase per click' => {
|
||||||
message => q|@ %f per click|,
|
message => q|@ %f per click|,
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
context => q|TODO|
|
context => q|%f is the price charged for each click on the ad|
|
||||||
},
|
},
|
||||||
|
|
||||||
'form purchase per impression' => {
|
'form purchase per impression' => {
|
||||||
message => q|@ %f per impression|,
|
message => q|@ %f per impression|,
|
||||||
lastUpdated => 0,
|
lastUpdated => 0,
|
||||||
context => q|TODO|
|
context => q|%f is the price charged for each impression of the ad|
|
||||||
},
|
},
|
||||||
|
|
||||||
'form manage title' => {
|
'form manage title' => {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
use WebGUI::Asset;
|
use WebGUI::Asset;
|
||||||
use WebGUI::Asset::Sku::Ad;
|
use WebGUI::Asset::Sku::Ad;
|
||||||
|
use WebGUI::AdSpace;
|
||||||
use WebGUI::Storage;
|
use WebGUI::Storage;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -74,10 +75,11 @@ is( WebGUI::Asset::Sku::Ad::getDiscountAmount($discounts,1050),10,'10% discount'
|
||||||
|
|
||||||
my $root = WebGUI::Asset->getRoot($session);
|
my $root = WebGUI::Asset->getRoot($session);
|
||||||
|
|
||||||
|
|
||||||
my $sku = $root->addChild({
|
my $sku = $root->addChild({
|
||||||
className => "WebGUI::Asset::Sku::Ad",
|
className => "WebGUI::Asset::Sku::Ad",
|
||||||
title => "Ad Space For Sale",
|
title => "Ad Space For Sale",
|
||||||
adSpace => 'qwerty', # don't need this unless I test onCompletePurchase...
|
adSpace => 'qwert',
|
||||||
priority => 1,
|
priority => 1,
|
||||||
pricePerClick => 0.01,
|
pricePerClick => 0.01,
|
||||||
pricePerImpression => 0.0001,
|
pricePerImpression => 0.0001,
|
||||||
|
|
@ -101,7 +103,8 @@ $sku->applyOptions({
|
||||||
|
|
||||||
is($sku->getConfiguredTitle, 'Ad Space For Sale (Sold!)', 'configured title');
|
is($sku->getConfiguredTitle, 'Ad Space For Sale (Sold!)', 'configured title');
|
||||||
is($sku->getPrice, '19.00', 'get Price');
|
is($sku->getPrice, '19.00', 'get Price');
|
||||||
# onCompletePurchase -- not sure how to test this
|
# $sku->onCompletePurchase($item); --> not really sure how to test the rest...
|
||||||
|
# $sku->onRefund
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Cleanup
|
# Cleanup
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue