From 0e257e7c940c2f7a07c98d3bf5f500db2f077312 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Mon, 19 May 2008 01:48:31 +0000 Subject: [PATCH] got transaction management working well enough to notice that there are a few things broken about it =) --- lib/WebGUI/Content/Shop.pm | 28 +++++ lib/WebGUI/Exception.pm | 17 +++ lib/WebGUI/Shop/Address.pm | 1 + lib/WebGUI/Shop/Transaction.pm | 188 ++++++++++++++++++++++++++++++-- lib/WebGUI/i18n/English/Shop.pm | 6 + 5 files changed, 232 insertions(+), 8 deletions(-) diff --git a/lib/WebGUI/Content/Shop.pm b/lib/WebGUI/Content/Shop.pm index 85e3c40e3..2ddebabd0 100644 --- a/lib/WebGUI/Content/Shop.pm +++ b/lib/WebGUI/Content/Shop.pm @@ -16,6 +16,7 @@ package WebGUI::Content::Shop; use strict; use WebGUI::AdminConsole; +use WebGUI::Exception::Shop; use WebGUI::Shop::AddressBook; use WebGUI::Shop::Cart; use WebGUI::Shop::Pay; @@ -66,6 +67,9 @@ sub handler { if ($function ne "www_" && (my $sub = __PACKAGE__->can($function))) { $output = $sub->($session); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $function", method=>$function); + } return $output; } @@ -86,6 +90,9 @@ sub www_address { if ($cart->can($method)) { $output = $cart->$method(); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -105,6 +112,9 @@ sub www_admin { if ($admin->can($method)) { $output = $admin->$method(); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -124,6 +134,9 @@ sub www_cart { if ($cart->can($method)) { $output = $cart->$method(); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -143,6 +156,9 @@ sub www_pay { if ($method ne "www_" && $pay->can($method)) { $output = $pay->$method(); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -162,6 +178,9 @@ sub www_ship { if ($method ne "www_" && $ship->can($method)) { $output = $ship->$method($session); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -181,6 +200,9 @@ sub www_tax { if ($method ne "www_" && $tax->can($method)) { $output = $tax->$method(); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -199,6 +221,9 @@ sub www_transaction { if ($method ne "www_" && WebGUI::Shop::Transaction->can($method)) { $output = WebGUI::Shop::Transaction->$method($session); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } @@ -217,6 +242,9 @@ sub www_vendor { if ($method ne "www_" && WebGUI::Shop::Vendor->can($method)) { $output = WebGUI::Shop::Vendor->$method($session); } + else { + WebGUI::Error::MethodNotFound->throw(error=>"Couldn't call non-existant method $method", method=>$method); + } return $output; } diff --git a/lib/WebGUI/Exception.pm b/lib/WebGUI/Exception.pm index 078bb2a5c..d3ea5cb0a 100644 --- a/lib/WebGUI/Exception.pm +++ b/lib/WebGUI/Exception.pm @@ -24,6 +24,11 @@ use Exception::Class ( isa => 'WebGUI::Error', description => 'This method should be overridden by subclasses.', }, + 'WebGUI::Error::MethodNotFound' => { + isa => 'WebGUI::Error', + description => q|Called a method that doesn't exist.|, + fields => 'method' + }, 'WebGUI::Error::InvalidObject' => { isa => 'WebGUI::Error::InvalidParam', description => "Expected to get a reference to an object type that wasn't gotten.", @@ -137,6 +142,18 @@ Used when an object is trying to be retrieved, but does not exist. ISA WebGUI::E The id of the object to be retrieved. +=head2 WebGUI::Error::MethodNotFound + +Tried calling a method that doesn't exist. + +=head3 method + +The method called. + +=head2 WebGUI::Error::OverrideMe + +An interface was not overriden as expected. + =cut diff --git a/lib/WebGUI/Shop/Address.pm b/lib/WebGUI/Shop/Address.pm index 0674e5f74..de47ec9eb 100644 --- a/lib/WebGUI/Shop/Address.pm +++ b/lib/WebGUI/Shop/Address.pm @@ -118,6 +118,7 @@ sub getHtmlFormatted { $address .= $self->get("state") . " " if ($self->get("state") ne ""); $address .= $self->get("code") if ($self->get("code") ne ""); $address .= '
' . $self->get("country"); + return $address; } #------------------------------------------------------------------- diff --git a/lib/WebGUI/Shop/Transaction.pm b/lib/WebGUI/Shop/Transaction.pm index e23dfe804..c377fa303 100644 --- a/lib/WebGUI/Shop/Transaction.pm +++ b/lib/WebGUI/Shop/Transaction.pm @@ -181,6 +181,31 @@ sub denyPurchase { #------------------------------------------------------------------- +=head2 formatAddress ( address ) + +Returns a formatted address. + +=head3 address + +A hash reference with the address properties. + +=cut + +sub formatAddress { + my ($self, $address) = @_; + my $formatted = $address->{name} . "
" . $address->{address1} . "
"; + $formatted .= $address->{address2} . "
" if ($address->{address2} ne ""); + $formatted .= $address->{address3} . "
" if ($address->{address3} ne ""); + $formatted .= $address->{city} . ", "; + $formatted .= $address->{state} . " " if ($address->{state} ne ""); + $formatted .= $address->{code} if ($address->{code} ne ""); + $formatted .= '
' . $address->{country}; + $formatted .= '
' . $address->{phoneNumber}; + return $formatted; +} + +#------------------------------------------------------------------- + =head2 formatCurrency ( amount ) Formats a number as a float with two digits after the decimal like 0.00. @@ -537,7 +562,7 @@ STOP }; YAHOO.widget.DataTable.formatViewTransaction = function(elCell, oRecord, oColumn, orderNumber) { STOP - $output .= q{elCell.innerHTML = 'page(q{shop=transaction;method=view}) .q{;transactionId=' + oRecord.getData('transactionId') + '">' + orderNumber + ''; }; $output .= ' }; @@ -571,6 +596,19 @@ STOP } +#------------------------------------------------------------------- + +=head2 www_print () + +Makes transaction information printable. + +=cut + +sub www_print { + my ($class, $session) = @_; + $class->www_view($session, 1); +} + #------------------------------------------------------------------- =head2 www_thankYou () @@ -586,21 +624,41 @@ sub www_thankYou { #------------------------------------------------------------------- -=head2 www_viewTransaction () +=head2 www_view () Displays the admin view of an individual transaction. =cut -sub www_viewTransaction { - my ($class, $session) = @_; +sub www_view { + my ($class, $session, $print) = @_; my $admin = WebGUI::Shop::Admin->new($session); return $session->privilege->insufficient() unless $admin->canManage; my $i18n = WebGUI::International->new($session, 'Shop'); my ($style, $url) = $session->quick(qw(style url)); my $transaction = $class->new($session, $session->form->get('transactionId')); + + # set up all the files that we need + $style->setLink($url->extras('/yui/build/fonts/fonts-min.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setLink($url->extras('/yui/build/datatable/assets/skins/sam/datatable.css'), {rel=>'stylesheet', type=>'text/css'}); + $style->setScript($url->extras('/yui/build/utilities/utilities.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('/yui/build/json/json-min.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('/yui/build/datasource/datasource-beta-min.js'), {type=>'text/javascript'}); + $style->setScript($url->extras('/yui/build/datatable/datatable-beta-min.js'), {type=>'text/javascript'}); + + #render page my $output = q{ - + }; + unless ($print) { + $output .= q{ +
}.$i18n->get('print').q{
+ }; + } + $output .= q{ +
@@ -608,17 +666,131 @@ sub www_viewTransaction { - + - + - +
}. $i18n->get("transaction id") .q{}. $transaction->getId .q{
}. $i18n->get("order number") .q{}. $transaction->get('orderNumber') .q{
}. $i18n->get("shipping address") .q{}. join(" ",$transaction->get('shippingAddressName'),$transaction->get('shippingAddress1'),$transaction->get('shippingAddress2'),$transaction->get('shippingAddress3'),$transaction->get('shippingCity'),$transaction->get('shippingState'),$transaction->get('shippingCode'),$transaction->get('shippingCountry'),$transaction->get('shippingPhoneNumber')) .q{}. $i18n->get("shipping address") .q{}. $transaction->formatAddress({ + name => $transaction->get('shippingAddressName'), + address1 => $transaction->get('shippingAddress1'), + address2 => $transaction->get('shippingAddress2'), + address3 => $transaction->get('shippingAddress3'), + city => $transaction->get('shippingCity'), + state => $transaction->get('shippingState'), + code => $transaction->get('shippingCode'), + country => $transaction->get('shippingCountry'), + phoneNumber => $transaction->get('shippingPhoneNumber'), + }) .q{
}. $i18n->get("payment address") .q{}. join(" ",$transaction->get('paymentAddressName'),$transaction->get('paymentAddress1'),$transaction->get('paymentAddress2'),$transaction->get('paymentAddress3'),$transaction->get('paymentCity'),$transaction->get('paymentState'),$transaction->get('paymentCode'),$transaction->get('paymentCountry'),$transaction->get('paymentPhoneNumber')) .q{}. $i18n->get("payment address") .q{}. $transaction->formatAddress({ + name => $transaction->get('paymentAddressName'), + address1 => $transaction->get('paymentAddress1'), + address2 => $transaction->get('paymentAddress2'), + address3 => $transaction->get('paymentAddress3'), + city => $transaction->get('paymentCity'), + state => $transaction->get('paymentState'), + code => $transaction->get('paymentCode'), + country => $transaction->get('paymentCountry'), + phoneNumber => $transaction->get('paymentPhoneNumber'), + }) .q{
}. $i18n->get("price") .q{}. $transaction->get('amount') .q{}. $i18n->get("price") .q{}. sprintf("%.2f", $transaction->get('amount')) .q{
}; + + # item detail + $output .= q{ +
+ + + + + + + + + + + + + }; + foreach my $item (@{$transaction->getItems}) { + my $sku = $item->getSku; + $output .= q{ + + + + + + }; + if ($item->get('shippingAddressId') eq $transaction->get('shippingAddressId')) { + $output .= q{}; + } + else { + $output .= q{ + + }; + } + $output .= q{ + + + + }; + } + $output .= q{ + +
ItemPriceQuantityStatusAddressDateTracking #
}.$item->get('configuredTitle').q{}.$transaction->formatCurrency($item->get('price')).q{}.$item->get('quantity').q{}.$item->get('shippingStatus').q{}. $transaction->formatAddress({ + name => $item->get('shippingAddressName'), + address1 => $item->get('shippingAddress1'), + address2 => $item->get('shippingAddress2'), + address3 => $item->get('shippingAddress3'), + city => $item->get('shippingCity'), + state => $item->get('shippingState'), + code => $item->get('shippingCode'), + country => $item->get('shippingCountry'), + phoneNumber => $item->get('shippingPhoneNumber'), + }) .q{}.$item->get('shippingDate').q{}.$item->get('shippingTrackingNumber').q{
+ }; + + # render data table + $output .= < + YAHOO.util.Event.addListener(window, "load", function() { + YAHOO.example.EnhanceFromMarkup = new function() { + var myColumnDefs = [ + {key:"item",sortable:true}, + {key:"price",sortable:true}, + {key:"quantity",formatter:YAHOO.widget.DataTable.formatNumber,sortable:true}, + {key:"status",sortable:true}, + {key:"address"}, + {key:"date",sortable:true,formatter:YAHOO.widget.DataTable.formatDate}, + {key:"tracking"} + ]; + + this.myDataSource = new YAHOO.util.DataSource(YAHOO.util.Dom.get("transactionItems")); + this.myDataSource.responseType = YAHOO.util.DataSource.TYPE_HTMLTABLE; + this.myDataSource.responseSchema = { + fields: [ + {key:"item"}, + {key:"price", parser:this.parseNumberFromCurrency}, + {key:"quantity", parser:YAHOO.util.DataSource.parseNumber}, + {key:"status"}, + {key:"address"}, + {key:"date", parser:YAHOO.util.DataSource.parseDate}, + {key:"tracking"} + ] + }; + + this.myDataTable = new YAHOO.widget.DataTable("transactionItemWrapper", myColumnDefs, this.myDataSource,{}); + }; +}); + +STOP + + # send output + if ($print) { + return $output; + } return $admin->getAdminConsole->render($output, $i18n->get('transactions')); } diff --git a/lib/WebGUI/i18n/English/Shop.pm b/lib/WebGUI/i18n/English/Shop.pm index ce69077d7..3b8b23d2b 100644 --- a/lib/WebGUI/i18n/English/Shop.pm +++ b/lib/WebGUI/i18n/English/Shop.pm @@ -3,6 +3,12 @@ package WebGUI::i18n::English::Shop; use strict; our $I18N = { + 'print' => { + message => q|Print|, + lastUpdated => 0, + context => q|a link label|, + }, + 'view cart' => { message => q|View Cart|, lastUpdated => 0,