Here's what I have so far:
- Code: Select all
#!/usr/bin/perl
if ($ENV{'REQUEST_METHOD'} =~ /get/i) {
$buffer = $ENV{'QUERY_STRING'};
print "buffer=$buffer\n";
$method = "Get";
}
else {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
$method = "Post";
}
@nvpairs = split(/&/, $buffer);
foreach $pair (@nvpairs)
{
($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
print "$name = $value\n";
$pos = index($name,"cust_country");
if ($pos != -1)
{
$country = $value;
}
$pos = index($name,"quantity");
if ($pos != -1)
{
$quantity = $value;
}
$pos = index($name,"weight");
if ($pos != -1)
{
$total += ($quantity * $value);
}
}
# output status=pass if everything is okay
print "status=pass\n";
print "option_count=1\n";
if ($country eq "US")
{
print "s1option=United%20States\n";
if ($total<=1){
printf ("s1price=%0.2f\n",3.00);}
elsif ($total<=6){
printf ("s1price=%0.2f\n",5.05);}
elsif ($total<=35){
printf ("s1price=%0.2f\n",11.30);}
elsif ($total<=70){
printf ("s1price=%0.2f\n",22.60);}
else{ #$total> 70
printf ("s1price=%0.2f\n",33.90);}
}
#...
The value $total holds how many magazines are counted in order to determine the magazine shipping pricing. Other items we sell can have the "additional shipping costs" value filled for their respective products.
I've found that each product has a value for SKU as seen here:
http://www.shopsite.com/help/current/en-US/sc/pro/index.htm?page=/help/current/en-US/sc/pro/shipping.api.spec.html
If the SKU starts with a predetermined value (i.e. "MAG"), then it will add to $total.
In perl, I tried this:
- Code: Select all
#the $sku value is defined like the other values
$pos = index($name,"sku");
#...
$pos = index($name,"quantity");
if ($pos != -1)
{
if (substr($sku,0,3) == "MAG")
$total += ($value);
}
What can I do to get this working?