[ic] shipping.asc not working right
Paul Jordan
paul at gishnetwork.com
Tue Jun 25 15:55:28 UTC 2013
> On 06/25/2013 10:40 AM, Paul Jordan wrote:
> >>> On 2013-06-23, at 10:18 AM, kerry blalock wrote:
> >>>
> >>>> I am trying to add an additions shipping method to my site and seem
> >>>> to be having a problem with the logic. Here is the code that is
> >>>> giving me an error on the truckbig method:
> >>>>
> >>>> truckbigger: Oversize Truck Shipping
> >>>> criteria <<EOC
> >>>> [calcn]
> >>>> foreach my $item (@$Items) {
> >>>> if ($item->{width} >= 160) {
> >>>> # We have to use this shipping method
> >>>> return 1;
> >>>> }
> >>>> }
> >>>> return 0;
> >>>> [/calcn]
> >>>> EOC
> >>>> min 1
> >>>> max 1
> >>>> cost 170.00
> >>>>
> >>>> truckbig: Truck Shipping
> >>>> criteria <<EOC
> >>>> [calcn]
> >>>> foreach my $item (@$Items) {
> >>>> if (($item->{width} >= 108 and ($item->{width} <=160)) {
> >>>> # We have to use truckbigger shipping method
> >>>> return 1;
> >>>> }
> >>>> }
> >>>> return 0;
> >>>> [/calcn]
> >>>> EOC
> >>>> min 1
> >>>> max 1
> >>>> cost 85.00
> >>>>
> >>>> Truckbigger works as is. But when I want to charge less for rods
> >>>> between
> >>>> 108 and 160, I get an error,
> >>>>
> >>>> Note: No match found for mode 'ground', quantity '', returning 0.
> >>>> Shipping defaults to the shippin method just below truckbig method.
> >>>> Need fresh eyes to help me figure out why this is not working.
> >>>>
> >>>> Kerry
> >>>> _______________________________________________
> >>>> interchange-users mailing list
> >>>> interchange-users at icdevgroup.org
> >>>> http://www.icdevgroup.org/mailman/listinfo/interchange-users
> >>>
> >>>
> >>>> if (($item->{width} >= 108 and ($item->{width} <=160)) {
> >>>
> >>> Looks like you are missing a closing bracket between "108" and "and".
> >>> HTH
> >>> Angus
> >>>
> >> Thanks Angus,
> >>
> >> I did find the missing bracket and added, but it still did not work.
> >>
> >> I finally have it kinda working with this:
> >>
> >> truckbig: Truck Shipping
> >> criteria <<EOC
> >> [calcn]
> >> foreach my $item (@$Items) {
> >> if ($item->{width} >= 160) {
> >> # We have to use truckbigger shipping method
> >> return 2;
> >> }
> >>
> >> if ($item->{width} >= 108) {
> >> # We have to use truckbig shipping method
> >> return 1;
> >> }
> >> }
> >> return 0;
> >> [/calcn]
> >> EOC
> >> min 1
> >> max 1
> >> cost 85.00
> >>
> >> min 2
> >> max 2
> >> cost 170.00
> >>
> >> min 3
> >> max 3
> >> cost 200.00
> >>
> >> The problem I have now is if a customer adds a item that is 144" and
> >> then adds another that is 192", to the same cart, it does not pick up
> >> the
> > higher
> >> shipping cost. That was why I was trying to use the conditional
> >> statement
> > and
> >> two different methods.
> >>
> >> Not sure why the one above is not picking up the higher cost, but itt
> > seems
> >> to hold the first if statement used by each method. If I add a 192"
> >> and
> > then
> >> add a 144", it retains the higher cost for the 192" which is fine,
> >> but the
> > other
> >> way around is not.
> > Because you have return's inside your if's, so it pretty much
> > guarantee's the logic will cease once it encounters its first item
> > that is longer than 108".
> >
> > You need to try and sort the widths before looping through them, or
> > have two foreach's, or leave it as you have it and instead of
> > returning inside the foreach, track a value to help you determine what
> > the longest item your foreach encounters.
> >
> > Paul
> >
> >
> >
> > _______________________________________________
> > interchange-users mailing list
> > interchange-users at icdevgroup.org
> > http://www.icdevgroup.org/mailman/listinfo/interchange-users
> I have not tried this as I am not sure if it is even close to right and do
not want
> to blowup the program.
> Am I on the right track? A little info on me: I am not a
> programmer, just a hacker. :-)
> truckbig: Truck Shipping
> criteria <<EOC
> [calcn]
> $big=0;
> $bigger=0;
> foreach my $item (@$Items) {
> if ($item->{width} >= 160) {
> # We have to use oversize shipping
> $bigger = 2;
>
> }
>
> if ($item->{width} >= 108) {
> # We have to use base truck shipping
>
> $big = 1;
> }
> }
> return 0;
> [/calcn]
> EOC
> min 1
> max 2
> cost f if ($bigger > $big) {return 170.00} elseif ($big =1)
> {return 85.00}
>
> min 3
> max 3
> cost 200.00
>
What about something like this (untested):
[calcn]
my $big=0;
foreach my $item (@$Items) {
if ($item->{width} >= 160) {
# We have to use the largest shipping available, no
need to check anymore
return 2;
} elsif ($item->{width} >= 108) {
# We have to use base truck shipping
$big = 1;
}
}
return $big;
[/calcn]
EOC
min 1
max 1
cost 85
min 2
max 2
cost 170
min 3
max 3
cost 200.00
Paul
More information about the interchange-users
mailing list