I have been going back and forth trying to figure stuff out with the Amazon help people. One of the things I'm trying to do is have Amazon default to selecting the cheapest shipping option--right now it lists them in this order:
USPS - Express Mail (1 - 2 days) - 13.95
USPS - Priority Mail (2 - 3 days) - 6.2
USPS - First-Class Mail (2 - 5 days) - 2.95
And it's preselected Express Mail, the most expensive option. The message I got back from Amazon was: "They have informed us that to know how shipping rates are displaying, please refer <zencart>/checkout_by_amazon/amazoncallback.php and refer "CalculateShippingRates" method."
So I looked and found that, and here it is... but I don't know php well enough to know what to change. Can anyone help?
PHP Code:
function CalculateShippingRates($weight, $country_code,$postal_code,$weight,$country_id,$zone_id){
global $order, $shipping_weight, $shipping_num_boxes, $total_weight, $shipping, $cart;
$shipping_weight = $weight;
$total_weight = $weight;
$shipping_num_boxes = 1;
$order = new zencartorder();
$order->delivery['country']['iso_code_2'] = (string)$country_code;
$order->delivery['country']['id'] = $country_id;
$order->delivery['postcode'] = $postal_code;
$order->delivery['zone_id'] = $zone_id;
if((int)SHIPPING_ORIGIN_COUNTRY != (int)$country_id){
$this->PreDefinedRegion="WorldAll";
}else{
$this->PreDefinedRegion="USAll";
}
writelog("PreDefinedRegion -> " . $this->PreDefinedRegion);
$shipping = new shipping();
$quotes_all = $shipping->quote();
/* Setting the shipping method */
$costArray = array();
$quoteArray = array();
$cnt = 0;
for ($j = 0; $j < count($quotes_all); $j++) {
$quotes=$quotes_all[$j];
$cnt = $cnt + count($quotes['methods']);
for ($i = 0; $i < count($quotes['methods']); $i++) {
$method = $quotes['methods'][$i];
$cost = (float)$method['cost'];
$shipping_id = $method['id'];
array_push($costArray,$cost);
array_push($quoteArray, strtoupper($quotes['id']) . " - " . $method['title'] . " - " . $cost);
}
}
/* sort the cost in values */
asort($costArray);
$shippingMethodsArray = array();
$shippingMethodArray = array();
$shippingMethodsArray['ShippingMethod'] = array();
$MAX_SHIPPING_METHODS = 24;
$standard = 8;
$expedited = 15;
$oneday = 20;
$twoday = 25;
$cnt = count($costArray);
$id = 1;
if($cnt > $MAX_SHIPPING_METHODS) {
$standard = round(7 * $cnt / $MAX_SHIPPING_METHODS) + 1;
$expedited = round(7 * $cnt / $MAX_SHIPPING_METHODS) + 1 + $standard;
$oneday = round(5 * $cnt / $MAX_SHIPPING_METHODS) + 1 + $expedited;
$twoday = $cnt - ($standard + $expedited + $oneday) + 1;
}
$servicelevel = "Standard";
foreach ($costArray as $key => $cost) {
switch($id) {
case ($id < $standard):
$servicelevel = "Standard";
break;
case ($id < $expedited):
$servicelevel = "Expedited";
break;
case ($id < $oneday):
$servicelevel = "OneDay";
break;
case ($id < $twoday):
$servicelevel = "TwoDay";
break;
}
$shippingMethodArray['ShippingMethodId'] = "ship-method-" . $id;
$shippingMethodArray['ServiceLevel'] = $servicelevel;
$shippingMethodArray['Rate']['ShipmentBased']['Amount'] = $cost;
$shippingMethodArray['Rate']['ShipmentBased']['CurrencyCode'] = $this->CurrencyCode;
$shippingMethodArray['IncludedRegions']['PredefinedRegion'] = $this->PreDefinedRegion;
$shippingMethodArray['DisplayableShippingLabel'] = $quoteArray[$key];
array_push($shippingMethodsArray['ShippingMethod'],$shippingMethodArray);
$id = $id + 1;
}
if($shippingMethodsArray){
ob_writelog("Got shipping amount from shipping carrier: ", $shippingMethodsArray);
return $shippingMethodsArray;
}else{
writelog("Shipping Carrier and Shipping Override are None. Please change in Checkout by Amazon 2.0 Payment module");
}
}
Bookmarks