Made a little progress on the sku tests and base class.
This commit is contained in:
parent
e9327db8d8
commit
2ca95d8586
3 changed files with 236 additions and 3 deletions
|
|
@ -12,6 +12,7 @@ The following fields are needed to construct this assets table called
|
||||||
assetId guid The unique id assigned to this sku that may never change. It's with all assets
|
assetId guid The unique id assigned to this sku that may never change. It's with all assets
|
||||||
sku varchar(35) unique The unique id that the shop keeper assigns to this item. It may be changed by the shop keeper. By default this is set equal to assetId.
|
sku varchar(35) unique The unique id that the shop keeper assigns to this item. It may be changed by the shop keeper. By default this is set equal to assetId.
|
||||||
vendorId guid The unique id of the vendor associated with this sku, if any
|
vendorId guid The unique id of the vendor associated with this sku, if any
|
||||||
|
overrideTaxRate yesNo Do you want to use an override for tax rate?
|
||||||
taxRateOverride float An override value for the default tax rate.
|
taxRateOverride float An override value for the default tax rate.
|
||||||
|
|
||||||
=head2 Method Dictionary
|
=head2 Method Dictionary
|
||||||
|
|
@ -23,6 +24,8 @@ class.
|
||||||
|
|
||||||
Adds this sku to the shopping cart.
|
Adds this sku to the shopping cart.
|
||||||
|
|
||||||
|
param: optionsHash - Takes an options hash and calls applyOptions() if specified as a shortcut.
|
||||||
|
|
||||||
=head3 applyOptions
|
=head3 applyOptions
|
||||||
|
|
||||||
Accepts a configuration data hash reference that can configure a sku a
|
Accepts a configuration data hash reference that can configure a sku a
|
||||||
|
|
@ -31,12 +34,12 @@ t-shirt" instead of just "a
|
||||||
t-shirt".
|
t-shirt".
|
||||||
|
|
||||||
param: options - a hash reference containing the
|
param: options - a hash reference containing the
|
||||||
configuration properties returned from getConfiguration()
|
configuration properties returned from getOptions()
|
||||||
|
|
||||||
=head3 getOptions
|
=head3 getOptions
|
||||||
|
|
||||||
Returns a hash reference of configuration data that can return this sku
|
Returns a hash reference of configuration data that can return this sku
|
||||||
to a configured state. See applyConfiguration() for details.
|
to a configured state. See applyOptions() for details.
|
||||||
|
|
||||||
=head3 getMaxAllowedInCart
|
=head3 getMaxAllowedInCart
|
||||||
|
|
||||||
|
|
@ -58,7 +61,9 @@ By default return 0. Should be overridden by subclasses.
|
||||||
|
|
||||||
=head3 newBySku
|
=head3 newBySku
|
||||||
|
|
||||||
Instanciates based on an existing sku, rather than an assetId.
|
Class method.
|
||||||
|
|
||||||
|
Instanciates based on an existing sku, rather than an assetId. Dynamically looks up class and creates appropriate object.
|
||||||
|
|
||||||
param: session - a reference to the current session
|
param: session - a reference to the current session
|
||||||
|
|
||||||
|
|
|
||||||
159
lib/WebGUI/Asset/Sku.pm
Normal file
159
lib/WebGUI/Asset/Sku.pm
Normal file
|
|
@ -0,0 +1,159 @@
|
||||||
|
package WebGUI::Asset::Sku;
|
||||||
|
|
||||||
|
=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 Tie::IxHash;
|
||||||
|
use base 'WebGUI::Asset';
|
||||||
|
use WebGUI::Utility;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Package WebGUI::Asset::Sku
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
This is the base class for all products in the commerce system.
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
use WebGUI::Asset::Sku;
|
||||||
|
|
||||||
|
$self = WebGUI::Asset::Sku->newBySku($session, $sku);
|
||||||
|
|
||||||
|
$self->addToCart;
|
||||||
|
$self->applyOptions;
|
||||||
|
$hashRef = $self->getOptions;
|
||||||
|
$integer = $self->getMaxAllowedInCart;
|
||||||
|
$float = $self->getPrice;
|
||||||
|
$float = $self->getTaxRate;
|
||||||
|
$boolean = $self->isShippingRequired;
|
||||||
|
$html = $self->processStyle($output);
|
||||||
|
|
||||||
|
=head1 METHODS
|
||||||
|
|
||||||
|
These methods are available from this class:
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 definition ( session, definition )
|
||||||
|
|
||||||
|
See super class.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub definition {
|
||||||
|
my $class = shift;
|
||||||
|
my $session = shift;
|
||||||
|
my $definition = shift;
|
||||||
|
my %properties;
|
||||||
|
tie %properties, 'Tie::IxHash';
|
||||||
|
my $i18n = WebGUI::International->new($session, "Asset_NewAsset");
|
||||||
|
%properties = (
|
||||||
|
templateId => {
|
||||||
|
# Determines which tab this property appears in
|
||||||
|
tab=>"display",
|
||||||
|
#See the list of field/control types in /lib/WebGUI/Form/
|
||||||
|
fieldType=>"template",
|
||||||
|
defaultValue=>'NewAssetTmpl0000000001',
|
||||||
|
#www_editSave will ignore anyone's attempts to update this field if this is set to 1
|
||||||
|
noFormPost=>0,
|
||||||
|
#This is an option specific to the template fieldType.
|
||||||
|
namespace=>"NewAsset",
|
||||||
|
#This is what will appear when the user hovers the mouse over the label
|
||||||
|
# of your form field.
|
||||||
|
hoverHelp=>$i18n->get('templateId label description'),
|
||||||
|
# This is the text that will appear to the left of your form field.
|
||||||
|
label=>$i18n->get('templateId label')
|
||||||
|
},
|
||||||
|
foo => {
|
||||||
|
tab=>"properties",
|
||||||
|
fieldType=>"text",
|
||||||
|
defaultValue=>undef,
|
||||||
|
label=>$i18n->get("foo label"),
|
||||||
|
hoverHelp=>$i18n->get("foo label help")
|
||||||
|
}
|
||||||
|
);
|
||||||
|
push(@{$definition}, {
|
||||||
|
assetName=>$i18n->get('assetName'),
|
||||||
|
icon=>'NewAsset.gif',
|
||||||
|
autoGenerateForms=>1,
|
||||||
|
tableName=>'NewAsset',
|
||||||
|
className=>'WebGUI::Asset::NewAsset',
|
||||||
|
properties=>\%properties
|
||||||
|
});
|
||||||
|
return $class->SUPER::definition($session, $definition);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 indexContent ( )
|
||||||
|
|
||||||
|
Adding sku as a keyword. See WebGUI::Asset::indexContent() for additonal details.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub indexContent {
|
||||||
|
my $self = shift;
|
||||||
|
my $indexer = $self->SUPER::indexContent;
|
||||||
|
$indexer->addKeywords($self->get('sku'));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_edit ( )
|
||||||
|
|
||||||
|
Web facing method which is the default edit page
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_edit {
|
||||||
|
my $self = shift;
|
||||||
|
return $self->session->privilege->insufficient() unless $self->canEdit;
|
||||||
|
return $self->session->privilege->locked() unless $self->canEditIfLocked;
|
||||||
|
return $self->getAdminConsole->render($self->getEditForm->print,WebGUI::International::get('edit asset',"Asset_NewAsset"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
|
||||||
|
=head2 www_view ( )
|
||||||
|
|
||||||
|
Renders self->view based upon current style, subject to timeouts. Returns Privilege::noAccess() if canView is False.
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
sub www_view {
|
||||||
|
my $self = shift;
|
||||||
|
my $check = $self->checkView;
|
||||||
|
return $check if (defined $check);
|
||||||
|
$self->session->http->setLastModified($self->getContentLastModified);
|
||||||
|
$self->session->http->sendHeader;
|
||||||
|
$self->prepareView;
|
||||||
|
my $style = $self->processStyle("~~~");
|
||||||
|
my ($head, $foot) = split("~~~",$style);
|
||||||
|
$self->session->output->print($head, 1);
|
||||||
|
$self->session->output->print($self->view);
|
||||||
|
$self->session->output->print($foot, 1);
|
||||||
|
return "chunked";
|
||||||
|
}
|
||||||
|
|
||||||
69
t/Asset/Sku.t
Normal file
69
t/Asset/Sku.t
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# This tests WebGUI::Asset::Sku, which is the base class for commerce items
|
||||||
|
|
||||||
|
use FindBin;
|
||||||
|
use strict;
|
||||||
|
use lib "$FindBin::Bin/../lib";
|
||||||
|
use Test::More;
|
||||||
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
|
use WebGUI::Session;
|
||||||
|
use WebGUI::Asset;
|
||||||
|
use WebGUI::Asset::Sku;
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Init
|
||||||
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Tests
|
||||||
|
|
||||||
|
plan tests => 8; # Increment this number for each test you create
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# put your tests here
|
||||||
|
my $root = WebGUI::Asset->getRoot($session);
|
||||||
|
my $sku = $root->addChild({
|
||||||
|
className=>"WebGUI::Asset::Sku",
|
||||||
|
title=>"Test Sku",
|
||||||
|
});
|
||||||
|
isa_ok($sku, "WebGUI::Asset::Sku");
|
||||||
|
|
||||||
|
$sku->addToCart;
|
||||||
|
|
||||||
|
$sku->applyOptions({
|
||||||
|
test1 => "YY"
|
||||||
|
});
|
||||||
|
|
||||||
|
my %options = $sku->getOptions;
|
||||||
|
is($options{test1}, "YY", "Can set and get an option.");
|
||||||
|
|
||||||
|
|
||||||
|
is($sku->getMaxAllowedInCart, 99999999, "Got a valid default max in cart.");
|
||||||
|
is($sku->getPrice, 0.00, "Got a valid default price.");
|
||||||
|
is($sku->getTaxRate, undef, "Tax rate is not overridden.");
|
||||||
|
$sku->update({overrideTaxRate=>1, taxRateOverride=>5});
|
||||||
|
is($sku->getTaxRate, 5, "Tax rate is overridden.");
|
||||||
|
isnt($sku->processStyle, "", "Got some style information.");
|
||||||
|
|
||||||
|
my $loadSku = WebGUI::Asset::Sku->newBySku($session, $sku->get("sku"));
|
||||||
|
is($loadSku->getId, $sku->getId, "newBySku() works.");
|
||||||
|
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
# Cleanup
|
||||||
|
END {
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue