90% functionally complete
This commit is contained in:
parent
df234709f4
commit
e9d54a3171
5 changed files with 132 additions and 45 deletions
|
|
@ -31,10 +31,37 @@ my $quiet; # this line required
|
|||
my $session = start(); # this line required
|
||||
|
||||
# upgrade functions go here
|
||||
adSkuInstall($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Describe what our function does
|
||||
sub adSkuInstall {
|
||||
my $session = shift;
|
||||
print "\tCreate AdSku database table\n" unless $quiet;
|
||||
$session->db->write("CREATE TABLE AdSku (
|
||||
assetId VARCHAR(22) BINARY NOT NULL,
|
||||
revisionDate BIGINT NOT NULL,
|
||||
purchaseTemplate VARCHAR(22) BINARY NOT NULL,
|
||||
manageTemplate VARCHAR(22) BINARY NOT NULL,
|
||||
adSpace VARCHAR(22) BINARY NOT NULL,
|
||||
priority INTEGER DEFAULT '1',
|
||||
pricePerClick Float DEFAULT '0',
|
||||
pricePerImpression Float DEFAULT '0',
|
||||
clickDiscounts VARCHAR(1024) default '',
|
||||
impressionDiscounts VARCHAR(1024) default '',
|
||||
PRIMARY KEY (assetId,revisionDate)
|
||||
)");
|
||||
print "\tCreate Adsku crud table\n" unless $quiet;
|
||||
use WebGUI::AssetCollateral::Sku::Ad::Ad;
|
||||
WebGUI::AssetCollateral::Sku::Ad::Ad->crud_createTable($session);
|
||||
print "\tinstall the AdSku Asset\n" unless $quiet;
|
||||
$session->config->addToHash("assets", 'WebGUI::Asset::Sku::Ad' => { category => 'shop' } );
|
||||
print "DONE!\n" unless $quiet;
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Describe what our function does
|
||||
#sub exampleFunction {
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ sub install {
|
|||
print "Installing asset.\n";
|
||||
my $session = WebGUI::Session->open($home, $confg);
|
||||
print "create crud table";
|
||||
WebGUI::AssetCollateral::Sku::Ad::Ad->crud_dropTable($session);
|
||||
WebGUI::AssetCollateral::Sku::Ad::Ad->crud_createTable($session);
|
||||
if(0) {
|
||||
print "Add wobject to confg file\n";
|
||||
$session->config->addToHash("assets",$className => { category => 'shop' } );
|
||||
print "Create database tables\n";
|
||||
|
|
@ -32,6 +32,7 @@ if(0) {
|
|||
impressionDiscounts VARCHAR(1024) default '',
|
||||
PRIMARY KEY (assetId,revisionDate)
|
||||
)");
|
||||
if(0) {
|
||||
print "Create a folder asset to store the default templates\n";
|
||||
my $importNode = WebGUI::Asset->getImportNode($session);
|
||||
my $newFolder = $importNode->addChild({
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use WebGUI::Asset::Template;
|
|||
use WebGUI::Form;
|
||||
use WebGUI::Shop::Pay;
|
||||
use WebGUI::AssetCollateral::Sku::Ad::Ad;
|
||||
use WebGUI::AdSpace::Ad;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -268,22 +269,18 @@ sub manage {
|
|||
$var{purchaseLink} = $self->getUrl;
|
||||
my $iterator = WebGUI::AssetCollateral::Sku::Ad::Ad->getAllIterator($session,{
|
||||
constraints => [ { "adSkuPurchase.userId = ?" => $self->session->user->userId } ],
|
||||
joinUsing => [ { "advertisement" => "adId" }, ],
|
||||
'join' => [ "transactionItem on transactionItem.itemId = adSkuPurchase.transactionItemId",
|
||||
"transaction on transaction.transactionId = transactionItem.transactionId",
|
||||
],
|
||||
orderBy => 'transaction.dateOfPurchase',
|
||||
orderBy => 'dateOfPurchase',
|
||||
});
|
||||
my %testHash; # used to eliminate duplicate ads
|
||||
my %ads;
|
||||
while( my $object = $iterator->() ) {
|
||||
next if exists $testHash{$object->get('adId')};
|
||||
$testHash{$object->get('adId')} = 1;
|
||||
next if exists $ads{$object->get('adId')};
|
||||
my $ad = $ads{$object->get('adId')} = WebGUI::AdSpace::Ad->new($session,$object->get('adId'));
|
||||
push @{$var{myAds}}, {
|
||||
rowTitle => $object->get('title'),
|
||||
rowClicks => $object->get('clicks') . '/' . $object->get('clicksBought'),
|
||||
rowImpressions => $object->get('impressions') . '/' . $object->get('impressionsBought'),
|
||||
rowTitle => $ad->get('title'),
|
||||
rowClicks => $ad->get('clicks') . '/' . $ad->get('clicksBought'),
|
||||
rowImpressions => $ad->get('impressions') . '/' . $ad->get('impressionsBought'),
|
||||
rowDeleted => $object->get('isDeleted'),
|
||||
rowRenewLink => $self->getUrl('renew=' . $object->get('adId') ),
|
||||
rowRenewLink => $self->getUrl('func=renew;adId=' . $object->get('adId') ),
|
||||
};
|
||||
}
|
||||
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});
|
||||
|
|
@ -299,11 +296,12 @@ inserts the ad intothe adspace...
|
|||
|
||||
sub onCompletePurchase {
|
||||
my $self = shift;
|
||||
my $item = shift;
|
||||
my $options = $self->getOptions;
|
||||
|
||||
# TODO insert crud
|
||||
# LATER: if we use Temp Storage for the image we need to move it to perm storage
|
||||
|
||||
WegGUI::AdSpace::Ad->create($self->session,$self->get('adSpace'),{
|
||||
my $ad = WebGUI::AdSpace::Ad->create($self->session,$self->get('adSpace'),{
|
||||
title => $options->{'adtitle'},
|
||||
clicksBought => $options->{'clicks'},
|
||||
impressionsBought => $options->{'impressions'},
|
||||
|
|
@ -313,8 +311,49 @@ sub onCompletePurchase {
|
|||
isActive => 1,
|
||||
type => 'image',
|
||||
priority => $self->get('priority'),
|
||||
adSpace => $self->get('adSpace'),
|
||||
});
|
||||
|
||||
WebGUI::AssetCollateral::Sku::Ad::Ad->create($self->session,{
|
||||
userId => $item->transaction->get('userId'),
|
||||
transactionItemId => $item->getId,
|
||||
adId => $ad->getId,
|
||||
clicksPurchased => $options->{'clicks'},
|
||||
impressionsPurchased => $options->{'impressions'},
|
||||
dateOfPurchase => $item->transaction->get('dateOfPurchase'),
|
||||
storedImage => $options->{'image'},
|
||||
isDeleted => 0,
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 onRemoveFromCart
|
||||
|
||||
deletes the image if it gets removed from the cart
|
||||
|
||||
LATER: if we switch to using Temp Storage we do not need to do this.
|
||||
|
||||
=cut
|
||||
|
||||
sub onRemoveFromCart {
|
||||
my $self = shift;
|
||||
my $item = shift;
|
||||
my $options = $self->getOptions;
|
||||
WebGUI::Storage->new($self->session,$options->{'image'})->delete;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 onRefund
|
||||
|
||||
delete the add if it gets refunded
|
||||
|
||||
=cut
|
||||
|
||||
sub onRefund {
|
||||
# TODO delete the ad...
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -438,6 +477,40 @@ my $options = $self->getOptions();
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_addToCart
|
||||
|
||||
Add this subscription to the cart.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_addToCart {
|
||||
my $self = shift;
|
||||
if ($self->canView) {
|
||||
$self->{_hasAddedToCart} = 1;
|
||||
my $form = $self->session->form;
|
||||
my $imageStorage = WebGUI::Storage->create( $self->session); # LATER should be createTemp
|
||||
$imageStorage->addFileFromFormPost('formImage',1);
|
||||
my $imageStorageId = $imageStorage->getId;
|
||||
# TODO error in case image does not upload
|
||||
dav::log 'addToCart:data:',
|
||||
'adtitle:' => $form->get('formTitle'),',',
|
||||
'link:' => $form->get('formLink','url'),',',
|
||||
'image:' => $imageStorageId,',',
|
||||
'clicks:' => $form->get('formClicks'),',',
|
||||
'impressions:' => $form->get('formImpressions');
|
||||
$self->addToCart({
|
||||
adtitle => $form->get('formTitle'),
|
||||
link => $form->process('formLink','url'),
|
||||
clicks => $form->process('formClicks','integer'),
|
||||
impressions => $form->process('formImpressions','integer'),
|
||||
image => $imageStorageId,
|
||||
});
|
||||
}
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_manage
|
||||
|
||||
manage previously purchased ads
|
||||
|
|
@ -461,32 +534,18 @@ sub www_manage {
|
|||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_addToCart
|
||||
=head2 www_renew
|
||||
|
||||
Add this subscription to the cart.
|
||||
renew an ad
|
||||
|
||||
=cut
|
||||
|
||||
sub www_addToCart {
|
||||
my $self = shift;
|
||||
if ($self->canView) {
|
||||
$self->{_hasAddedToCart} = 1;
|
||||
my $form = $self->session->form;
|
||||
dav::log 'addToCart:data:',
|
||||
'adtitle:' => $form->get('formTitle'),',',
|
||||
'link:' => $form->get('formLink','url'),',',
|
||||
'image:' => $form->get('formImage'),',',
|
||||
'clicks:' => $form->get('formClicks'),',',
|
||||
'impressions:' => $form->get('formImpressions');
|
||||
$self->addToCart({
|
||||
adtitle => $form->get('formTitle'),
|
||||
link => $form->process('formLink','url'),
|
||||
clicks => $form->process('formClicks','integer'),
|
||||
impressions => $form->process('formImpressions','integer'),
|
||||
image => $form->get('formImage'),
|
||||
});
|
||||
}
|
||||
return $self->www_view;
|
||||
sub www_renew {
|
||||
my $self = shift;
|
||||
my $adPurchaseId = ''; # TODO get the adPurchaseId param
|
||||
my $crud = WebGUI::AssetCollateral::Sku::Ad::Ad->new($self->session,$adPurchaseId);
|
||||
# TODO assign params for purchase form
|
||||
return $self->www_view;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ transactionItemid = the id if the transaction item that completes this purchase
|
|||
adId = th id if the ad purchased
|
||||
clicksPurchased = the number of clicks the user purchased
|
||||
impressionsPurchased = the number of impressions the user purchased
|
||||
storedImage = temp storage for the image
|
||||
isRenewal = indicates if this purchase is a renewal -- are the counts increased or just assigned
|
||||
dateOfPurchase = the date of purchase
|
||||
storedImage = storage for the image
|
||||
isDeleted = boolean that indicates whether the ad has been deleted from the system
|
||||
|
||||
=cut
|
||||
|
|
@ -39,7 +39,7 @@ sub crud_definition {
|
|||
my ($class, $session) = @_;
|
||||
my $definition = $class->SUPER::crud_definition($session);
|
||||
$definition->{tableName} = 'adSkuPurchase';
|
||||
$definition->{tableKey} = 'userId';
|
||||
$definition->{tableKey} = 'adSkuPurchaseId';
|
||||
$definition->{properties} = {
|
||||
userId => {
|
||||
fieldType => 'user',
|
||||
|
|
@ -61,14 +61,14 @@ sub crud_definition {
|
|||
fieldType => 'integer',
|
||||
defaultValue => undef,
|
||||
},
|
||||
dateOfPurchase => {
|
||||
fieldType => 'date',
|
||||
defaultValue => undef,
|
||||
},
|
||||
storedImage => {
|
||||
fieldType => 'guid',
|
||||
defaultValue => undef,
|
||||
},
|
||||
isRenewal => {
|
||||
fieldType => 'yesNo',
|
||||
defaultValue => 0,
|
||||
},
|
||||
isDeleted => {
|
||||
fieldType => 'yesNo',
|
||||
defaultValue => 0,
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ sub create {
|
|||
$posUser = $cart->getPosUser;
|
||||
}
|
||||
$session->db->write('insert into transaction (transactionId, userId, username, cashierUserId, dateOfPurchase) values (?,?,?,?,now())',
|
||||
[$transactionId, $posUser->userId, $posUser->username, $cashier->userId]);
|
||||
[$transactionId, $posUser->userId, $posUser->username || 'noname', $cashier->userId]);
|
||||
my $self = $class->new($session, $transactionId);
|
||||
$self->update($properties);
|
||||
return $self;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue