From 152e96f695562cb9f915d1ff7e0065590f092585 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Wed, 27 Feb 2008 16:30:10 +0000 Subject: [PATCH] added commerce ui glue --- docs/upgrades/upgrade_7.5.2-7.5.3.pl | 15 +++ lib/WebGUI/Content/Shop.pm | 151 +++++++++++++++++++++++++++ 2 files changed, 166 insertions(+) create mode 100644 lib/WebGUI/Content/Shop.pm diff --git a/docs/upgrades/upgrade_7.5.2-7.5.3.pl b/docs/upgrades/upgrade_7.5.2-7.5.3.pl index d98305391..1a3afca66 100644 --- a/docs/upgrades/upgrade_7.5.2-7.5.3.pl +++ b/docs/upgrades/upgrade_7.5.2-7.5.3.pl @@ -30,10 +30,25 @@ migrateToNewCart($session); createSkuAsset($session); createDonationAsset($session); addShippingDrivers($session); +addShoppingHandler($session); finish($session); # this line required +#------------------------------------------------- +sub addShoppingHandler { + my $session = shift; + print "\tInstalling shopping handler.\n" unless ($quiet); + my @changed = (); + foreach my $handler (@{$session->config->get("contentHandlers")}) { + if ($handler eq "WebGUI::Content::Asset") { + push(@changed, "WebGUI::Content::Shop"); + } + push(@changed, $handler); + } + $session->config->set("contentHandlers", \@changed); +} + #------------------------------------------------- sub createDonationAsset { my $session = shift; diff --git a/lib/WebGUI/Content/Shop.pm b/lib/WebGUI/Content/Shop.pm new file mode 100644 index 000000000..709114908 --- /dev/null +++ b/lib/WebGUI/Content/Shop.pm @@ -0,0 +1,151 @@ +package WebGUI::Content::Shop; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2008 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use WebGUI::AdminConsole; +use WebGUI::Shop::Cart; +#use WebGUI::Shop::Pay; +use WebGUI::Shop::Ship; +use WebGUI::Shop::Tax; + +=head1 NAME + +Package WebGUI::Content::Shop + +=head1 DESCRIPTION + +A content handler that opens up all the commerce functionality. + +=head1 SYNOPSIS + + use WebGUI::Content::Shop; + my $output = WebGUI::Content::Shop::handler($session); + +=head1 SUBROUTINES + +These subroutines are available from this package: + +=cut + +#------------------------------------------------------------------- + +=head2 handler ( session ) + +The content handler for this package. + +=cut + +sub handler { + my ($session) = @_; + my $output = undef; + my $function = "www_".$session->form->get("shop"); + if ($function ne "www_" && __PACKAGE__->can($function)) { + $output = &$function($session); + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 www_cart () + +Hand off to the cart. + +=cut + +sub www_cart { + my $session = shift; + my $output = undef; + my $method = "www_".$session->form->get("method"); + my $cart = WebGUI::Shop::Cart->create($session); + if ($method ne "www_" && $cart->can($method)) { + $output = $cart->$method(); + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 www_manageSettings () + +Display the commerce settings page. + +=cut + +sub www_manageSettings { + my $session = shift; +} + +#------------------------------------------------------------------- + +=head2 www_pay () + +Hand off to the payment gateway. + +=cut + +sub www_pay { + my $session = shift; + my $output = undef; + my $method = "www_".$session->form->get("method"); + my $pay = WebGUI::Shop::Pay->create($session); + if ($method ne "www_" && $pay->can($method)) { + $output = $pay->$method(); + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 www_ship () + +Hand off to the shipper. + +=cut + +sub www_ship { + my $session = shift; + my $output = undef; + my $method = "www_".$session->form->get("method"); + my $ship = WebGUI::Shop::Ship->create($session); + if ($method ne "www_" && $ship->can($method)) { + $output = $ship->$method(); + } + return $output; +} + +#------------------------------------------------------------------- + +=head2 www_tax () + +Hand off to the tax system. + +=cut + +sub www_tax { + my $session = shift; + my $output = undef; + my $method = "www_".$session->form->get("method"); + my $tax = WebGUI::Shop::Tax->create($session); + if ($method ne "www_" && $tax->can($method)) { + $output = $tax->$method(); + } + return $output; +} + + +1; +