diff --git a/lib/WebGUI/Commerce/Shipping/ByPrice.pm b/lib/WebGUI/Commerce/Shipping/ByPrice.pm new file mode 100644 index 000000000..5f752f68e --- /dev/null +++ b/lib/WebGUI/Commerce/Shipping/ByPrice.pm @@ -0,0 +1,52 @@ +package WebGUI::Commerce::Shipping::ByPrice; + +our @ISA = qw(WebGUI::Commerce::Shipping); + +use strict; + +#------------------------------------------------------------------- +sub calc { + my ($self, $items, $price); + $self = shift; + + $items = $self->getShippingItems; + + foreach (@$items) { + $price += $_->{totalPrice}; + } + + return $price * $self->get('percentageOfPrice') / 100; +}; + +#------------------------------------------------------------------- +sub configurationForm { + my ($self, $f); + $self = shift; + + $f = WebGUI::HTMLForm->new; + $f->float( + -name => $self->prepend('percentageOfPrice'), + -label => WebGUI::International::get('percentage of price', 'CommerceShippingByPrice'), + -value => $self->get('percentageOfPrice') + ); + + return $self->SUPER::configurationForm($f->printRowsOnly); +} + +#------------------------------------------------------------------- +sub init { + my ($class, $self); + $class = shift; + + $self = $class->SUPER::init('ByPrice'); + + return $self; +} + +#------------------------------------------------------------------- +sub name { + return WebGUI::International::get('title', 'CommerceShippingByPrice'); +} + +1; + diff --git a/lib/WebGUI/Commerce/Shipping/ByWeight.pm b/lib/WebGUI/Commerce/Shipping/ByWeight.pm new file mode 100644 index 000000000..dc6176763 --- /dev/null +++ b/lib/WebGUI/Commerce/Shipping/ByWeight.pm @@ -0,0 +1,52 @@ +package WebGUI::Commerce::Shipping::ByWeight; + +our @ISA = qw(WebGUI::Commerce::Shipping); + +use strict; + +#------------------------------------------------------------------- +sub calc { + my ($self, $items, $weight); + $self = shift; + + $items = $self->getShippingItems; + + foreach (@$items) { + $weight += $_->{item}->weight * $_->{quantity}; + } + + return $weight * $self->get('pricePerUnitWeight'); +}; + +#------------------------------------------------------------------- +sub configurationForm { + my ($self, $f); + $self = shift; + + $f = WebGUI::HTMLForm->new; + $f->float( + -name => $self->prepend('pricePerUnitWeight'), + -label => WebGUI::International::get('price per weight', 'CommerceShippingByWeight'), + -value => $self->get('pricePerUnitWeight') + ); + + return $self->SUPER::configurationForm($f->printRowsOnly); +} + +#------------------------------------------------------------------- +sub init { + my ($class, $self); + $class = shift; + + $self = $class->SUPER::init('ByWeight'); + + return $self; +} + +#------------------------------------------------------------------- +sub name { + return WebGUI::International::get('title', 'CommerceShippingByWeight'); +} + +1; + diff --git a/lib/WebGUI/Commerce/Shipping/PerTransaction.pm b/lib/WebGUI/Commerce/Shipping/PerTransaction.pm new file mode 100644 index 000000000..e8f91ad70 --- /dev/null +++ b/lib/WebGUI/Commerce/Shipping/PerTransaction.pm @@ -0,0 +1,48 @@ +package WebGUI::Commerce::Shipping::PerTransaction; + +our @ISA = qw(WebGUI::Commerce::Shipping); + +use strict; + +#------------------------------------------------------------------- +sub calc { + my ($self); + $self = shift; + + return 0 unless (scalar(@{$self->getShippingItems})); + + return $self->get('pricePerTransaction'); +}; + +#------------------------------------------------------------------- +sub configurationForm { + my ($self, $f); + $self = shift; + + $f = WebGUI::HTMLForm->new; + $f->float( + -name => $self->prepend('pricePerTransaction'), + -label => WebGUI::International::get('price', 'CommerceShippingPerTransaction'), + -value => $self->get('pricePerTransaction') + ); + + return $self->SUPER::configurationForm($f->printRowsOnly); +} + +#------------------------------------------------------------------- +sub init { + my ($class, $self); + $class = shift; + + $self = $class->SUPER::init('PerTransaction'); + + return $self; +} + +#------------------------------------------------------------------- +sub name { + return WebGUI::International::get('title', 'CommerceShippingPerTransaction'); +} + +1; +