Add the shippingDrivers entry to the config file.
Have the update script remove the old shipping plugin and add the new shipping driver entry to config files. Tests for Ship.t. getDrivers and some "new" code for Shop::Ship.
This commit is contained in:
parent
06e902c019
commit
f2c0a672f4
4 changed files with 141 additions and 7 deletions
|
|
@ -28,6 +28,7 @@ insertCommerceTaxTable($session);
|
|||
insertCommerceShipDriverTable($session);
|
||||
migrateToNewCart($session);
|
||||
createSkuAsset($session);
|
||||
addShippingDrivers($session);
|
||||
|
||||
finish($session); # this line required
|
||||
|
||||
|
|
@ -108,6 +109,15 @@ EOSQL
|
|||
|
||||
}
|
||||
|
||||
#-------------------------------------------------
|
||||
sub addShippingDrivers {
|
||||
my $session = shift;
|
||||
print "\tSet up the default shipping.\n" unless ($quiet);
|
||||
# and here's our code
|
||||
$session->config->delete('shippingPlugins');
|
||||
$session->config->addToArray('shippingDrivers', 'WebGUI::Shop::ShipDriver::FlatRate');
|
||||
}
|
||||
|
||||
|
||||
# --------------- DO NOT EDIT BELOW THIS LINE --------------------------------
|
||||
|
||||
|
|
|
|||
|
|
@ -173,10 +173,10 @@
|
|||
|
||||
"paymentPlugins" : ["ITransact","Cash"],
|
||||
|
||||
# List the shipping plugins you have installed and wish to be
|
||||
# List the shipping drivers you have installed and wish to be
|
||||
# available for configuration on the site.
|
||||
|
||||
"shippingPlugins" : ["ByPrice", "ByWeight", "PerTransaction"],
|
||||
"shippingDrivers" : ["WebGUI::Shop::ShipDriver::FlatRate"],
|
||||
|
||||
# Specify the list of template parsers available in the system.
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ use strict;
|
|||
use Carp qw(croak);
|
||||
use WebGUI::International;
|
||||
use WebGUI::Shop::ShipDriver;
|
||||
use WebGUI::Pluggable;
|
||||
use WebGUI::Utility;
|
||||
|
||||
=head1 NAME
|
||||
|
||||
|
|
@ -58,29 +60,38 @@ A list of properties to assign to this ShipperDriver. See C<definition> for det
|
|||
sub create {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
croak "Definition requires a session object"
|
||||
croak "create requires a session object"
|
||||
unless ref $session eq 'WebGUI::Session';
|
||||
my $requestedClass = shift;
|
||||
croak "create requires the name of a class to create an object"
|
||||
unless defined $requestedClass;
|
||||
croak "The requested class $class is not enabled in your WebGUI configuration file"
|
||||
unless isIn($requestedClass, @{ WebGUI::Shop::Ship->getDrivers($session) } );
|
||||
my $options = shift;
|
||||
croak "You must pass a hashref of options to create a new ShipDriver object"
|
||||
unless defined($options) and ref $options eq 'HASH' and scalar keys %{ $options };
|
||||
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 getDrivers ( $session )
|
||||
|
||||
This subroutine returns an arrayref of hashrefs, used to validate data put into
|
||||
the object by the user, and to automatically generate the edit form to show
|
||||
the user.
|
||||
This subroutine returns an arrayref of available shipping driver classes
|
||||
from the WebGUI config file.
|
||||
|
||||
=head3 $session
|
||||
|
||||
A WebGUI::Session object.
|
||||
|
||||
=cut
|
||||
|
||||
sub getDrivers {
|
||||
my $class = shift;
|
||||
my $session = shift;
|
||||
croak "Definition requires a session object"
|
||||
croak "getDrivers requires a session object"
|
||||
unless ref $session eq 'WebGUI::Session';
|
||||
return $session->config->get('shippingDrivers');
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
|
@ -90,6 +101,10 @@ sub getDrivers {
|
|||
Returns a list of options for the user to ship, along with the cost of using each one. It is a hash of hashrefs,
|
||||
with the key of the primary hash being the shipperId of the driver, and sub keys of label and price.
|
||||
|
||||
=head3 $session
|
||||
|
||||
A WebGUI::Session object.
|
||||
|
||||
=head3
|
||||
|
||||
=cut
|
||||
|
|
@ -108,6 +123,14 @@ sub getOptions {
|
|||
Looks up an existing ShipperDriver in the db by shipperId and returns
|
||||
that object.
|
||||
|
||||
=head3 $session
|
||||
|
||||
A WebGUI::Session object.
|
||||
|
||||
=head3 $shipperId
|
||||
|
||||
The ID of a shipper to look up and instanciate.
|
||||
|
||||
=cut
|
||||
|
||||
sub new {
|
||||
|
|
|
|||
101
t/Shop/Ship.t
Normal file
101
t/Shop/Ship.t
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
# vim:syntax=perl
|
||||
#-------------------------------------------------------------------
|
||||
# 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
|
||||
#------------------------------------------------------------------
|
||||
|
||||
# Write a little about what this script tests.
|
||||
#
|
||||
#
|
||||
|
||||
use FindBin;
|
||||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use JSON;
|
||||
use HTML::Form;
|
||||
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Init
|
||||
my $session = WebGUI::Test->session;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 7;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# put your tests here
|
||||
|
||||
my $loaded = use_ok('WebGUI::Shop::Ship');
|
||||
|
||||
my $storage;
|
||||
|
||||
SKIP: {
|
||||
|
||||
skip 'Unable to load module WebGUI::Shop::Ship', $tests unless $loaded;
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# getDrivers
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
my $drivers;
|
||||
|
||||
eval { $drivers = WebGUI::Shop::Ship->getDrivers(); };
|
||||
like ($@, qr/getDrivers requires a session object/, 'getDrivers croaks without session');
|
||||
|
||||
$drivers = WebGUI::Shop::Ship->getDrivers($session);
|
||||
|
||||
cmp_deeply(
|
||||
$drivers,
|
||||
[ 'WebGUI::Shop::ShipDriver::FlatRate' ],
|
||||
'getDrivers: WebGUI only ships with 1 default shipping driver',
|
||||
);
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# create
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
eval { $drivers = WebGUI::Shop::Ship->create(); };
|
||||
like ($@, qr/create requires a session object/, 'create croaks without session');
|
||||
|
||||
eval { $drivers = WebGUI::Shop::Ship->create($session); };
|
||||
like ($@, qr/create requires the name of a class/, 'create croaks without a class');
|
||||
|
||||
eval { $drivers = WebGUI::Shop::Ship->create($session, 'WebGUI::Shop::ShipDriver::FreeShipping'); };
|
||||
like ($@, qr/The requested class \S+ is not enabled in your WebGUI configuration file/, 'create croaks without a configured class');
|
||||
|
||||
eval { $drivers = WebGUI::Shop::Ship->create($session, 'WebGUI::Shop::ShipDriver::FlatRate'); };
|
||||
like ($@, qr/You must pass a hashref of options to create a new ShipDriver object/, 'create croaks without options to build a object with');
|
||||
|
||||
eval { $drivers = WebGUI::Shop::Ship->create($session, 'WebGUI::Shop::ShipDriver::FlatRate', {}); };
|
||||
like ($@, qr/You must pass a hashref of options to create a new ShipDriver object/, 'create croaks without options to build a object with');
|
||||
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# new
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
$session->db->write('delete from shipper');
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue