Custom Shipping API: Additive Pricing Based on Product SKU
Posted: Mon Mar 17, 2014 12:10 pm
I'm trying to write some custom shipping that adds costs to shipping differently based on the product type. I need to use the shipping API because the magazines we sell have shipping based on our packaging (i.e. <= 6 fits in a sleeve, <= 35 fits in one box). However, we sell other items too, that do not follow that pricing.
Here's what I have so far:
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:
What can I do to get this working?
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?