[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] [repost] per item shipping cost schedule
I posted earlier on a shipping problem I was having and was basically
told
to either
1) Iterate over the cart items in Perl and watch the sun rising ... :-)
2) Or use an add-on product called shipd ...
I opted for 'roll-your-own' :-) and am being rolled over by a steam
roller.
I'm trying to calculate shipping for a set of items in a shopping cart.
Each item could potentially have its own shipping method.
This is intended to allow for widely varying types of goods. For
example,
shipping iron rods is different from shipping jewelry, yet both can be
bought
at the same time.
As far as I am aware, Interchange calculates shipping based on the
aggregate
weight/quantity of the items in a cart by applying a data table to this
aggregate quantity. We're shipping based on weight.
I've identified a strategy which seems workable except I do not know
all
the steps needed to achieve it.
1) Add a field to products database called ship. This field is the
class
of shipping (ie. the data table to be applied to this product)
2) Define tags that are used with [item-list] to be used as below:-
([]'s shifted around for clarity)
[reset-shipping]
[item-list]
[add-to-shipping
shipmode="[item-field ship]"
weight="[item-field weight]"
quantity="[item-quantity]"
]
[/item-list]
[calculate-shipping-to "New Jersey"]
3) These UserTags go into the catalog.cfg for the store.
This UserTag resets all shipping values to zero and should
be used each time one is going to do something related to
calculating shipping.
UserTag reset-shipping Routine <<EOR
sub { $Vend::Session->{SendToAfrica} = undef; return ""; }
EOR
This UserTag sorts the products into bins according to shipping class
and calculates the aggregate weight for each bin.
UserTag add-to-shipping Order shipmode weight quantity
UserTag add-to-shipping Routine <<EOR
sub {
my ($shipmode,$weight,$quantity) = @_;
$Vend::Session->{SendToAfrica}{$shipmode} += $weight *
$quantity;
return "";
}
EOR
This UserTag is supposed to apply a data table used in regular
Interchange
shipping to each bin. If the bin are called '1', '2' and '3', and we
are
shipping to 'USA', then this UserTag should apply data table USA1 to
the
aggregate weight of items in bin '1'; apply data table USA2 to the
aggregate weight of items in bin '2' etc.
I'm setting $::Values->{mv_shipmode} to the concatenation of the
shipping
destination and the shipping class. That would make data table 'USA1'
apply
to destination 'USA' and shipping class '1'.
Now I want to call an Interchange function, telling it to calculate
shipping
for the items in bin '1' for destination 'USA'. From looking at the
source
code for sub shipping in Interpolate.pm, I guess the next step is to
create
a cart for each bin, put all items in the bin into the cart.
I'm having problems trying to work out how to do the
calculate-shipping-to
UserTag properly. This code doesn't work ... and I need help with it
especially
as this is my first descent into the Perl side of developing with
Interchange.
Any ideas ? This would be much easier if Interchange had API level
documentation. If something like that exists, please let me know !!!!
I'm tearing my hair out trying to grok this Perl :) it's too
elite for me, maybe ... Maybe ?!?
UserTag calculate-shipping-to Order region
UserTag calculate-shipping-to Routine <<EOR
sub {
my $region = shift;
my $method = undef;
my $cat = undef;
my $total = undef;
foreach $cat (keys %{$Vend::Session->{SendToAfrica}}) {
# TODO: from region get shipping data table
# this is done by setting mv_shipmode
$::Values->{mv_shipmode} = $region . $cat;
print $Vend::Interpolate::shipping($region . $cat);
# TODO: use mv_shipmode on category weight
$total += $Vend::Session->{SendToAfrica}{$cat};
}
return "$total";
}
EOR
__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - Buy the things you want at great prices.
http://auctions.yahoo.com/
_______________________________________________
Interchange-users mailing list
Interchange-users@lists.akopia.com
http://lists.akopia.com/mailman/listinfo/interchange-users