Add an option to the Sku to require individual shipping of this sku, separate
from other items in the cart. Update the FlatRate driver to support calculating that.
This commit is contained in:
parent
e98fc02e9b
commit
db290f91f9
8 changed files with 141 additions and 14 deletions
|
|
@ -56,7 +56,8 @@ These methods are available from this class:
|
|||
|
||||
=head2 addToCart ( options )
|
||||
|
||||
Adds this sku to the current session's cart.
|
||||
Adds this sku to the current session's cart. Returns a copy of the Shop::Cart::Item
|
||||
object added to the cart.
|
||||
|
||||
=head3 options
|
||||
|
||||
|
|
@ -137,6 +138,13 @@ sub definition {
|
|||
fieldType => 'hidden',
|
||||
defaultValue => '{}',
|
||||
},
|
||||
shipsSeparately => {
|
||||
tab => 'shop',
|
||||
fieldType => 'yesNo',
|
||||
defaultValue => 0,
|
||||
label => $i18n->get('shipsSeparate'),
|
||||
hoverHelp => $i18n->get('shipsSeparate help'),
|
||||
},
|
||||
);
|
||||
push(@{$definition}, {
|
||||
assetName=>$i18n->get('assetName'),
|
||||
|
|
@ -594,6 +602,15 @@ sub processStyle {
|
|||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 setTaxConfiguration ($namespace, $configuration)
|
||||
|
||||
=head3 $namespace
|
||||
|
||||
=head3 $configuration
|
||||
|
||||
=cut
|
||||
|
||||
sub setTaxConfiguration {
|
||||
my $self = shift;
|
||||
my $namespace = shift;
|
||||
|
|
@ -615,6 +632,19 @@ sub setTaxConfiguration {
|
|||
} );
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 shipsSeparately
|
||||
|
||||
Returns a boolean indicating whether this item must be shipped separately from other items.
|
||||
|
||||
=cut
|
||||
|
||||
sub shipsSeparately {
|
||||
return shift->get('shipsSeparately');
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_view ( )
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ our $HELP = {
|
|||
{ 'name' => 'description', description=>'description help' },
|
||||
{ 'name' => 'displayTitle', description=>'display title help' },
|
||||
{ 'name' => 'vendorId', description=>'vendor help' },
|
||||
{ 'name' => 'shipsSeparately', description=>'shipsSeparately help' },
|
||||
],
|
||||
related => []
|
||||
},
|
||||
|
|
|
|||
|
|
@ -29,9 +29,9 @@ base methods. These methods are customized in this class:
|
|||
Returns a shipping price. Calculates the shipping price using the following formula:
|
||||
|
||||
total price of shippable items * percentageOfPrice
|
||||
+ flatFee
|
||||
+ total weight of shippable items * pricePerWeight
|
||||
+ total quantity of shippable items * pricePerItem
|
||||
+ flatFee * numberOfSeparatelyShippedItems
|
||||
|
||||
=head3 $cart
|
||||
|
||||
|
|
@ -45,17 +45,31 @@ sub calculate {
|
|||
my ($self, $cart) = @_;
|
||||
my $cost = 0;
|
||||
my $anyShippable = 0;
|
||||
my $separatelyShipped = 0;
|
||||
my $looseBundle = 0;
|
||||
foreach my $item (@{$cart->getItems}) {
|
||||
my $sku = $item->getSku;
|
||||
if ($sku->isShippingRequired) {
|
||||
$cost += ($item->get("quantity") * $sku->getPrice * $self->get("percentageOfPrice") / 100) # cost by price
|
||||
+ ($item->get("quantity") * $sku->getWeight * $self->get("pricePerWeight") / 100) # cost by weight
|
||||
+ ($item->get("quantity") * $self->get("pricePerItem")); # cost by item
|
||||
my $quantity = $item->get('quantity');
|
||||
$cost += ($quantity * $sku->getPrice * $self->get("percentageOfPrice") / 100) # cost by price
|
||||
+ ($quantity * $sku->getWeight * $self->get("pricePerWeight") / 100) # cost by weight
|
||||
+ ($quantity * $self->get("pricePerItem")); # cost by item
|
||||
$anyShippable = 1;
|
||||
##Account for items which must be shipped separately, and with those that can be shipped
|
||||
##together.
|
||||
## Two items shipped separately = two bundles
|
||||
## 1 shipped separately plus 1 not = two bundles
|
||||
## two items shipped together = one bundle
|
||||
if ($sku->shipsSeparately) {
|
||||
$separatelyShipped += $quantity;
|
||||
}
|
||||
else {
|
||||
$looseBundle = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ($anyShippable) {
|
||||
$cost += $self->get('flatFee');
|
||||
$cost += $self->get('flatFee') * ($separatelyShipped + $looseBundle);
|
||||
}
|
||||
return $cost;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,18 @@ our $I18N = {
|
|||
context => q|help for vendor field|
|
||||
},
|
||||
|
||||
'shipsSeparately' => {
|
||||
message => q|Ships Separately?|,
|
||||
lastUpdated => 0,
|
||||
context => q|label in the edit form. Ships, as in ships via post or mail or shipping. Separately, independently of other items in the cart.|,
|
||||
},
|
||||
|
||||
'shipsSeparately help' => {
|
||||
message => q|If set to yes, then this Sku will incur additional, independent shipping costs, rather than sharing costs with other items in a cart.|,
|
||||
lastUpdated => 0,
|
||||
context => q|help for shipsSeparate field in the edit form|
|
||||
},
|
||||
|
||||
'add to cart' => {
|
||||
message => q|Add To Cart|,
|
||||
lastUpdated => 0,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue