merge to 10219

This commit is contained in:
Colin Kuskie 2009-04-08 16:35:31 +00:00
parent ae28bf79c8
commit 4c1307e3d0
194 changed files with 8203 additions and 2134 deletions

View file

@ -152,6 +152,13 @@ sub www_editSettings {
label => $i18n->get('who is a cashier'),
hoverHelp => $i18n->get('who is a cashier help'),
);
$form->float(
name => 'shopCartCheckoutMinimum',
value => $setting->get('shopCartCheckoutMinimum'),
defaultValue=> '0.00',
label => $i18n->get('cart checkout minimum'),
hoverHelp => $i18n->get('cart checkout minimum help'),
);
$form->template(
name => "shopCartTemplateId",
value => $setting->get("shopCartTemplateId"),
@ -203,13 +210,21 @@ sub www_editSettingsSave {
my $self = shift;
return $self->session->privilege->adminOnly() unless ($self->session->user->isAdmin);
my ($setting, $form) = $self->session->quick(qw(setting form));
# Save shop templates
foreach my $template (qw(shopMyPurchasesDetailTemplateId shopMyPurchasesTemplateId
shopCartTemplateId shopAddressBookTemplateId shopAddressTemplateId)) {
$setting->set($template, $form->get($template, "template"));
}
# Save group settings
foreach my $group (qw(groupIdCashier groupIdAdminCommerce)) {
$setting->set($group, $form->get($group, "group"));
}
# Save mininmum cart checkout
$setting->set( 'shopCartCheckoutMinimum', $form->get( 'shopCartCheckoutMinimum', 'float' ) );
return $self->www_editSettings();
}

View file

@ -175,7 +175,7 @@ sub create {
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
}
my $cartId = $session->id->generate;
$session->db->write('insert into cart (cartId, sessionId) values (?,?)', [$cartId, $session->getId]);
$session->db->write('insert into cart (cartId, sessionId, creationDate) values (?,?,UNIX_TIMESTAMP())', [$cartId, $session->getId]);
return $class->new($session, $cartId);
}
@ -498,21 +498,23 @@ Returns whether all the required properties of the the cart are set.
sub readyForCheckout {
my $self = shift;
# Check if the shipping address is set and correct
my $address = eval{$self->getShippingAddress};
return 0 if WebGUI::Error->caught;
# Check if the ship driver is chosen and existant
my $ship = eval {$self->getShipper};
return 0 if WebGUI::Error->caught;
# Check if the cart has items
return 0 unless scalar @{ $self->getItems };
# fail if there are multiple recurring items or if
return 0 if ($self->hasMixedItems);
# Check minimum cart checkout requirement
my $requiredAmount = $self->session->setting->get( 'shopCartCheckoutMinimum' );
if ( $requiredAmount > 0 ) {
return 0 if $self->calculateTotal < $requiredAmount;
}
# All checks passed so return true
return 1;
}
@ -559,6 +561,10 @@ The unique id of the configured shipping driver that will be used to ship these
The ID of a user being checked out, if they're being checked out by a cashier.
=head4 creationDate
The date the cart was created.
=cut
sub update {
@ -567,7 +573,7 @@ sub update {
WebGUI::Error::InvalidParam->throw(error=>"Need a properties hash ref.");
}
my $id = id $self;
foreach my $field (qw(shippingAddressId posUserId shipperId)) {
foreach my $field (qw(shippingAddressId posUserId shipperId creationDate)) {
$properties{$id}{$field} = (exists $newProperties->{$field}) ? $newProperties->{$field} : $properties{$id}{$field};
}
$self->session->db->setRow("cart","cartId",$properties{$id});
@ -801,6 +807,10 @@ sub www_view {
shipToButton => WebGUI::Form::submit($session, {value=>$i18n->get("ship to button"),
extras=>q|onclick="setCallbackForAddressChooser(this.form);"|}),
subtotalPrice => $self->formatCurrency($self->calculateSubtotal()),
minimumCartAmount => $session->setting->get( 'shopCartCheckoutMinimum' ) > 0
? sprintf( '%.2f', $session->setting->get( 'shopCartCheckoutMinimum' ) )
: 0
,
);
# get the shipping address
@ -846,10 +856,11 @@ sub www_view {
# calculate price adjusted for in-store credit
$var{totalPrice} = $var{subtotalPrice} + $var{shippingPrice} + $var{tax};
my $credit = WebGUI::Shop::Credit->new($session, $posUser->userId);
$var{inShopCreditAvailable} = $credit->getSum;
$var{inShopCreditDeduction} = $credit->calculateDeduction($var{totalPrice});
$var{totalPrice} = $self->formatCurrency($var{totalPrice} + $var{inShopCreditDeduction});
$var{ inShopCreditAvailable } = $credit->getSum;
$var{ inShopCreditDeduction } = $credit->calculateDeduction($var{totalPrice});
$var{ totalPrice } = $self->formatCurrency($var{totalPrice} + $var{inShopCreditDeduction});
$var{ readyForCheckout } = $self->readyForCheckout;
# render the cart
my $template = WebGUI::Asset::Template->new($session, $session->setting->get("shopCartTemplateId"));
return $session->style->userStyle($template->process(\%var));

View file

@ -175,7 +175,7 @@ sub getSku {
my ($self) = @_;
my $asset = '';
$asset = WebGUI::Asset->newByDynamicClass($self->cart->session, $self->get("assetId"));
$asset->applyOptions($self->get("options"));
$asset->applyOptions($self->get("options")) if $asset;
return $asset;
}
@ -229,7 +229,8 @@ Removes this item from the cart and calls $sku->onRemoveFromCart. See also delet
sub remove {
my $self = shift;
$self->getSku->onRemoveFromCart($self);
my $sku = $self->getSku;
$sku->onRemoveFromCart($self) if $sku;
return $self->delete;
}

View file

@ -226,6 +226,18 @@ Returns a reference to the current session.
=cut
#-------------------------------------------------------------------
=head2 www_addPaymentGateway ( $session )
Add a new payment gateway, based on the className form variable. It will throw
an error, WebGUI::Error::InvalidParram if no className is passed.
=head3 $session
A reference to the current session object.
=cut
sub www_addPaymentGateway {
my $self = shift;
my $session = $self->session;

View file

@ -9,7 +9,7 @@ use base qw/WebGUI::Shop::PayDriver/;
#-------------------------------------------------------------------
=head2 canCheckOutCart ( )
=head2 canCheckoutCart ( )
Returns whether the cart can be checked out by this plugin.
@ -85,12 +85,6 @@ sub processPayment {
#-------------------------------------------------------------------
sub www_displayStatus {
}
#-------------------------------------------------------------------
=head2 www_getCredentials ( [ addressId ] )
Displays the checkout form for this plugin.

View file

@ -119,6 +119,48 @@ sub getId {
#-------------------------------------------------------------------
=head2 getPayoutTotals ( )
Returns a hash ref, containing the payout details for this vendor. The keys in the hash are:
=head3 paid
The amount of money already transfered to the vendor.
=head3 scheduled
The amount of money scheduled to be transfered to the vendor.
=head3 notPaid
The amount of money that is yet to be scheduled for payment to the vendor.
=head3 total
The sum of these three values.
=cut
sub getPayoutTotals {
my $self = shift;
my %totals = $self->session->db->buildHash(
'select vendorPayoutStatus, sum(vendorPayoutAmount) as amount from transactionItem '
.'where vendorId=? group by vendorPayoutStatus ',
[ $self->getId ]
);
# Format the payout categories and calc the total those.
%totals =
map { lcfirst $_ => sprintf '%.2f', $totals{ $_ } }
qw( Paid Scheduled NotPaid );
$totals{ total } = sprintf '%.2f', sum values %totals;
return \%totals;
}
#-------------------------------------------------------------------
=head2 getVendors ( session, options )
Class method. Returns an array reference of WebGUI::Shop::Vendor objects.
@ -152,6 +194,26 @@ sub getVendors {
#-------------------------------------------------------------------
=head2 isVendorInfoComplete ( )
Returns a boolean indicating whether the payoutinformation entered by the vendor is complete.
=cut
sub isVendorInfoComplete {
my $self = shift;
my $complete =
defined $self->get( 'name' )
&& defined $self->get( 'userId' )
&& defined $self->get( 'preferredPaymentType' )
&& defined $self->get( 'paymentInformation' );
return $complete
}
#-------------------------------------------------------------------
=head2 new ( session, vendorId )
Constructor. Returns a WebGUI::Shop::Vendor object.
@ -407,47 +469,144 @@ sub www_manage {
return $console->render($output, $i18n->get("vendors"));
}
#-------------------------------------------------------------------
=head2 getPayoutTotals ( )
=head2 www_managePayouts ( )
Returns a hash ref, containing the payout details for this vendor. The keys in the hash are:
=head3 paid
The amount of money already transfered to the vendor.
=head3 scheduled
The amount of money scheduled to be transfered to the vendor.
=head3 notPaid
The amount of money that is yet to be scheduled for payment to the vendor.
=head3 total
The sum of these three values.
Displays the payout manager.
=cut
sub getPayoutTotals {
my $self = shift;
sub www_managePayouts {
my $class = shift;
my $session = shift;
my %totals = $self->session->db->buildHash(
'select vendorPayoutStatus, sum(vendorPayoutAmount) as amount from transactionItem '
.'where vendorId=? group by vendorPayoutStatus ',
[ $self->getId ]
);
my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->adminOnly() unless ($admin->canManage);
# Load the required YUI stuff.
my $style = $session->style;
my $url = $session->url;
# Format the payout categories and calc the total those.
%totals =
map { lcfirst $_ => sprintf '%.2f', $totals{ $_ } }
qw( Paid Scheduled NotPaid );
$totals{ total } = sprintf '%.2f', sum values %totals;
$style->setLink($url->extras('yui/build/paginator/assets/skins/sam/paginator.css'), {type=>'text/css', rel=>'stylesheet'});
$style->setLink($url->extras('yui/build/datatable/assets/skins/sam/datatable.css'), {type=>'text/css', rel=>'stylesheet'});
$style->setLink($url->extras('yui/build/button/assets/skins/sam/button.css'), {type=>'text/css', rel=>'stylesheet'});
return \%totals;
$style->setScript($url->extras('yui/build/yahoo-dom-event/yahoo-dom-event.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/element/element-beta-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/connection/connection-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/json/json-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/paginator/paginator-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/datasource/datasource.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/datatable/datatable-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('yui/build/button/button-min.js'), {type=>'text/javascript'});
$style->setScript($url->extras('VendorPayout/vendorPayout.js'), {type=>'text/javascript'});
# Add css for scheduled payout highlighting
$style->setRawHeadTags(<<CSS);
<style type="text/css">
.yui-skin-sam .yui-dt tr.scheduled,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-asc,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-desc,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-asc,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-desc {
background-color : #080;
color : #fff;
}
</style>
CSS
my $output = q{<div id="vendorPayoutContainer" class="yui-skin-sam"></div>}
.q{<script type="text/javascript">var vp = new WebGUI.VendorPayout( 'vendorPayoutContainer' );</script>};
my $console = WebGUI::Shop::Admin->new($session)->getAdminConsole;
my $i18n = WebGUI::International->new($session, 'Shop');
return $console->render($output, $i18n->get('vendor payouts'));
}
#-------------------------------------------------------------------
=head2 www_payoutDataAsJSON ( )
Returns a JSON string containing paginated payout data for a specific vendor.
The following form params should be passed:
=head3 vendorId
The vendorId of the vendor you want the payout data for.
=head3 results
The number of results to be returned. Defaults to 100.
=head3 startIndex
The index of the record at which the payout data should start.
=cut
sub www_payoutDataAsJSON {
my $class = shift;
my $session = shift;
my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->adminOnly() unless ($admin->canManage);
my $vendorId = $session->form->process('vendorId');
my $startIndex = $session->form->process('startIndex');
my $rowsPerPage = $session->form->process('results') || 100;
my $pageNumber = int( $startIndex / $rowsPerPage ) + 1;
my $sql =
"select t1.* from transactionItem as t1 join transaction as t2 on t1.transactionId=t2.transactionId "
." where vendorId=? and vendorPayoutAmount > 0 and vendorPayoutStatus <> 'Paid' order by t2.orderNumber";
my $placeholders = [ $vendorId ];
my $paginator = WebGUI::Paginator->new( $session, '', $rowsPerPage, '', $pageNumber );
$paginator->setDataByQuery( $sql, undef, 0, $placeholders );
my $data = {
totalRecords => $paginator->getRowCount,
results => $paginator->getPageData,
};
$session->http->setMimeType( 'application/json' );
return JSON::to_json( $data );
}
#-------------------------------------------------------------------
=head2 www_setPayoutStatus ( )
Sets the vendorPayoutStatus flag for each transaction passed by the form param 'itemId'. The new status is passed
by the form param 'status'. Status can either be 'NotPaid' or 'Scheduled' and may only be applied on items that do
not have their vendorPayoutStatus set to 'Paid'.
Returns the status to which the item(s) are set.
=cut
sub www_setPayoutStatus {
my $class = shift;
my $session = shift;
my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->adminOnly() unless ($admin->canManage);
my @itemIds = $session->form->process('itemId');
my $status = $session->form->process('status');
return "error: wrong status [$status]" unless isIn( $status, qw{ NotPaid Scheduled } );
foreach my $itemId (@itemIds) {
my $item = WebGUI::Shop::TransactionItem->newByDynamicTransaction( $session, $itemId );
return "error: invalid transactionItemId [$itemId]" unless $item;
return "error: cannot change status of a Paid item" if $item->get('vendorPayoutStatus') eq 'Paid';
$item->update({ vendorPayoutStatus => $status });
}
return $status;
}
#-------------------------------------------------------------------
@ -477,43 +636,14 @@ sub www_submitScheduledPayouts {
#-------------------------------------------------------------------
=head2 www_setPayoutStatus ( )
Sets the vendorPayoutStatus flag for each transaction passed by the form param 'itemId'. The new status is passed
by the form param 'status'. Status can either be 'NotPaid' or 'Scheduled' and may only be applied on items that do
not have their vendorPayoutStatus set to 'Paid'.
Returns the status to which the item(s) are set.
=cut
sub www_setPayoutStatus {
my $class = shift;
my $session = shift;
my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->adminOnly() unless ($admin->canManage);
my @itemIds = $session->form->process('itemId');
my $status = $session->form->process('status');
return "error: wrong status [$status]" unless isIn( $status, qw{ NotPaid Scheduled } );
foreach my $itemId (@itemIds) {
my $item = WebGUI::Shop::TransactionItem->newByDynamicTransaction( $session, $itemId );
return "error: invalid transactionItemId [$itemId]" unless $item;
return "error: cannot change status of a Paid item" if $item->get('vendorPayoutStatus') eq 'Paid';
$item->update({ vendorPayoutStatus => $status });
}
return $status;
}
#-------------------------------------------------------------------
=head2 www_vendorTotalsAsJSON ( )
Returns a JSON string containing all vendors and their payout details. If a vendor id is passed through form param
'vendorId' only results for that vendor will be returned.
Returns a JSON string containing all vendors and their payout details. The following
form parameters can be passed:
=head3 vendorId
If passed, the results will include only the totals of this vendor.
=cut
@ -555,78 +685,5 @@ sub www_vendorTotalsAsJSON {
return JSON::to_json( { vendors => \@dataset } );
}
#-------------------------------------------------------------------
sub www_payoutDataAsJSON {
my $class = shift;
my $session = shift;
my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->adminOnly() unless ($admin->canManage);
my $vendorId = $session->form->process('vendorId');
my $startIndex = $session->form->process('startIndex');
my $rowsPerPage = $session->form->process('results') || 100;
my $pageNumber = int( $startIndex / $rowsPerPage ) + 1;
my $sql =
"select t1.* from transactionItem as t1 join transaction as t2 on t1.transactionId=t2.transactionId "
." where vendorId=? and vendorPayoutAmount > 0 and vendorPayoutStatus <> 'Paid' order by t2.orderNumber";
my $placeholders = [ $vendorId ];
my $paginator = WebGUI::Paginator->new( $session, '', $rowsPerPage, '', $pageNumber );
$paginator->setDataByQuery( $sql, undef, 0, $placeholders );
my $data = {
totalRecords => $paginator->getRowCount,
results => $paginator->getPageData,
};
$session->http->setMimeType( 'application/json' );
return JSON::to_json( $data );
}
#-------------------------------------------------------------------
sub www_managePayouts {
my $class = shift;
my $session = shift;
my $admin = WebGUI::Shop::Admin->new($session);
return $session->privilege->adminOnly() unless ($admin->canManage);
# Load the required YUI stuff.
$session->style->setLink('/extras/yui/build/paginator/assets/skins/sam/paginator.css', {type=>'text/css', rel=>'stylesheet'});
$session->style->setLink('/extras/yui/build/datatable/assets/skins/sam/datatable.css', {type=>'text/css', rel=>'stylesheet'});
$session->style->setLink('/extras/yui/build/button/assets/skins/sam/button.css', {type=>'text/css', rel=>'stylesheet'});
$session->style->setScript('/extras/yui/build/yahoo-dom-event/yahoo-dom-event.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/element/element-beta-min.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/connection/connection-min.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/json/json-min.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/paginator/paginator-min.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/datasource/datasource.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/datatable/datatable-min.js', {type=>'text/javascript'});
$session->style->setScript('/extras/yui/build/button/button-min.js', {type=>'text/javascript'});
$session->style->setScript('/extras/VendorPayout/vendorPayout.js', {type=>'text/javascript'});
# Add css for scheduled payout highlighting
$session->style->setRawHeadTags(<<CSS);
<style type="text/css">
.yui-skin-sam .yui-dt tr.scheduled,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-asc,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-desc,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-asc,
.yui-skin-sam .yui-dt tr.scheduled td.yui-dt-desc {
background-color : #080;
color : #fff;
}
</style>
CSS
my $output = q{<div id="vendorPayoutContainer" class="yui-skin-sam"></div>}
.q{<script type="text/javascript">var vp = new WebGUI.VendorPayout( 'vendorPayoutContainer' );</script>};
my $console = WebGUI::Shop::Admin->new($session)->getAdminConsole;
return $console->render($output, 'Vendor payout'); #$i18n->get("vendors"));
}
1;