diff --git a/lib/WebGUI/Asset/Sku/Ad.pm b/lib/WebGUI/Asset/Sku/Ad.pm index 3ee39f897..7605916ed 100644 --- a/lib/WebGUI/Asset/Sku/Ad.pm +++ b/lib/WebGUI/Asset/Sku/Ad.pm @@ -1,8 +1,5 @@ package WebGUI::Asset::Sku::Ad; -use lib '/root/pb/lib'; -use dav; - =head1 LEGAL ------------------------------------------------------------------- @@ -222,20 +219,13 @@ get the price for this purchase sub getPrice { my $self = shift; -dav::log 'getPrice'; my $options = $self->getOptions; my $impressionCount = $options->{impressions} || $self->{formImpressions}; -dav::log 'getPrice::impressionCount=', $impressionCount; my $clickCount = $options->{clicks}; -dav::log 'getPrice::clickCount=', $clickCount; my $impressionDiscount = getDiscountAmount($self->get('impressionDiscounts'),$impressionCount ); -dav::log 'getPrice::impressionDiscount=', $impressionDiscount; my $clickDiscount = getDiscountAmount($self->get('clickDiscounts'),$clickCount ); -dav::log 'getPrice::clickDiscount=', $clickDiscount; my $impressionPrice = $self->get('pricePerImpression') * ( 100 - $impressionDiscount ) / 100 ; -dav::log 'getPrice::impressionPrice=', $impressionPrice; my $clickPrice = $self->get('pricePerClick') * ( 100 - $clickDiscount ) / 100 ; -dav::log 'getPrice::clickPrice=', $clickPrice; return sprintf "%.2f", $impressionPrice * $impressionCount + $clickPrice * $clickCount; } @@ -355,7 +345,7 @@ sub onRemoveFromCart { my $self = shift; my $item = shift; 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 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 { my $discountDescription = shift; -dav::log $discountDescription; my @lines = split "\n", $discountDescription; my @discounts; foreach my $line ( @lines ) { -dav::log $line; if( $line =~ /^(\d+)\@(\d+)/ ) { -dav::log 'match'; push @discounts, [ $1, $2 ]; } } @@ -508,7 +513,6 @@ sub www_addToCart { my $form = $self->session->form; my $imageStorage = $self->getOptions->{image} || WebGUI::Storage->create($self->session); # LATER should be createTemp my $imageStorageId = $form->process('formImage', 'image', $imageStorage->getId); - # TODO error in case image does not upload my $cartInfo = { adtitle => $form->process('formTitle'), link => $form->process('formLink','url'), @@ -517,7 +521,6 @@ sub www_addToCart { adId => $form->process('formAdId'), image => $imageStorageId, }; -dav::dump 'addToCart:data:', $cartInfo; $self->addToCart($cartInfo); } return $self->www_view; @@ -558,7 +561,6 @@ sub www_renew { my $self = shift; my $session = $self->session; my $id = $session->form->get('Id'); -dav::log 'id=',$id; my $crud = WebGUI::AssetCollateral::Sku::Ad::Ad->new($session,$id); my $ad = WebGUI::AdSpace::Ad->new($session,$crud->get('adId')); $self->applyOptions({ diff --git a/lib/WebGUI/i18n/English/Asset_AdSku.pm b/lib/WebGUI/i18n/English/Asset_AdSku.pm index 1f8519f28..f292e2149 100644 --- a/lib/WebGUI/i18n/English/Asset_AdSku.pm +++ b/lib/WebGUI/i18n/English/Asset_AdSku.pm @@ -120,13 +120,13 @@ our $I18N = { 'form purchase per click' => { message => q|@ %f per click|, lastUpdated => 0, - context => q|TODO| + context => q|%f is the price charged for each click on the ad| }, 'form purchase per impression' => { message => q|@ %f per impression|, lastUpdated => 0, - context => q|TODO| + context => q|%f is the price charged for each impression of the ad| }, 'form manage title' => { diff --git a/t/Asset/Sku/Ad.t b/t/Asset/Sku/Ad.t index af44c13b0..5055c8e35 100644 --- a/t/Asset/Sku/Ad.t +++ b/t/Asset/Sku/Ad.t @@ -24,6 +24,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules use WebGUI::Session; use WebGUI::Asset; use WebGUI::Asset::Sku::Ad; +use WebGUI::AdSpace; 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 $sku = $root->addChild({ className => "WebGUI::Asset::Sku::Ad", title => "Ad Space For Sale", - adSpace => 'qwerty', # don't need this unless I test onCompletePurchase... + adSpace => 'qwert', priority => 1, pricePerClick => 0.01, pricePerImpression => 0.0001, @@ -101,7 +103,8 @@ $sku->applyOptions({ is($sku->getConfiguredTitle, 'Ad Space For Sale (Sold!)', 'configured title'); 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