Akopia Akopia Services

[Date Prev][Date Next][Thread Prev][Thread Next][Minivend by date ][Minivend by thread ]

[mv] Shipping finally working!



******    message to minivend-users from "Christopher P. Lindsey" <lindsey@mallorn.com>     ******

Hooray!  The shipping is finally working!  :) Here's how I did it, for those
who care about such things...

I created an entry in shipping.asc like:

   2-day   2nd day air     quantity        0       9999999 f [perl arg="sub values" interpolate=1]twoday({[item-list] '[item-code]' => {'price' => '[item-price]', 'shipping_id'  => '[item-field shipping_id]', 'quantity' => '[item-quantity]'},[/item-list]}) [/perl]

What this does is cycle through each item in the cart and build an
array of hashes of hashes (really only need a hash of hashes, but
for compatibility sake with other stuff I left it as an element in an
array) in real time, which is then passed to the subroutine twoday as
an argument.

twoday, in turn, is a sub that looks like this:

   Sub <<EOF
   sub twoday {
      @basket = @_;
      my $price, $multiplier, $minimum, $total;
      my $state = $Safe{'values'}->{state};
    
      if ($state =~ /^(?:OR|ID|CA|UT|NV)$/) {
         $multiplier = .20; $minimum = 10;
      } elsif ($state =~ /^AK$/) {
         $multiplier = .35; $minimum = 18;
      } else { 
         $multiplier = .30; $minimum = 10;
      }

      foreach my $i (keys %{ $basket[0] }) {
         if ($basket[0]{$i}{'shipping_id'} < 1) {
            $price = $basket[0]{$i}{'price'};
            $price =~ s/\$//g;
            $total += $price * $basket[0]{$i}{'quantity'};
         }
      }

      if ($total > 0) {
         return ($total * $multiplier > $minimum) ? 
                 $total * $multiplier : $minimum;  
      } else {
         return 0;
      }
   }
   EOF

This checks the state that the item is being shipped to, changes the 
multiplier and minimum order amount based on that value, then applies
it to all items that don't have 'shipping_id' set.

Thanks to Ryan for his message last night that got me thinking about
[item-list][/item-list] possibilities in shipping.asc.  Of course, this
is a Hack (with a capital 'H'), but if it works, I'm happy.


-
To unsubscribe from the list, DO NOT REPLY to this message.  Instead, send
email with 'UNSUBSCRIBE minivend-users' in the body to Majordomo@minivend.com.
Archive of past messages: http://www.minivend.com/minivend/minivend-list


Search for: Match: Format: Sort by: