t('AustraliaPost'),
'#description' => t('AustraliaPost')
);
$methods['australiapost']['STANDARD'] = array(
'#title' => t('Standard delivery within Australia'),
);
$methods['australiapost']['EXPRESS'] = array(
'#title' => t('Express Post delivery within Australia'),
);
$methods['australiapost']['AIR'] = array(
'#title' => t('Airmail for International delivery'),
);
$methods['australiapost']['SEA'] = array(
'#title' => t('Shipping via Sea for International Delivery'),
);
$methods['australiapost']['ECI_M'] = array(
'#title' => t('Express Courier International'),
);
return $methods;
}
/**
* Shipcalc _settings_form hook.
*
* Create a form for CANADAPOST-specific configuration.
*/
function australiapost_settings_form(&$form) {
$form['australiapost'] = array(
'#type' => 'fieldset',
'#title' => t('AustraliaPost settings')
);
$form['australiapost']['australiapost_postalcode'] = array(
'#type' => 'textfield',
'#title' => t('Postal Code'),
'#description' => t('This is the Postal Code of your business and is used for calculating shipping costs.'),
'#default_value' => variable_get('shipcalc_australiapost_postalcode', ''),
'#required' => TRUE
);
$form['australiapost']['australiapost_turnaround'] = array(
'#type' => 'textfield',
'#title' => t('Turn Around Time'),
'#description' => t('This is the turn around time between receiving the order and shipping the product. (ie. enter 24 for a 24 hour turn around time.)'),
'#default_value' => variable_get('shipcalc_australiapost_turnaround', ''),
'#required' => TRUE
);
$form['australiapost']['australiapost_url'] = array(
'#type' => 'textfield',
'#title' => t('AustraliaPost Server URL'),
'#description' => t('Enter the fully qualified URL of the AustraliaPost shipping rate server, as provided by AustraliaPost.'),
'#default_value' => (variable_get('shipcalc_australiapost_url', '') ? variable_get('shipcalc_australiapost_url', '') : 'http://drc.edeliver.com.au/ratecalc.asp'),
'#required' => TRUE
);
// TODO: Testing to help admin set up site. Not fully implemented yet.
$form['australiapost']['test'] = array(
'#type' => 'fieldset',
'#title' => t('Testing'),
'#collapsible' => TRUE,
'#collapsed' => TRUE
);
$form['australiapost']['test']['australiapost_test_url'] = array(
'#type' => 'textfield',
'#title' => t('AustraliaPost Test Server URL'),
'#description' => t('AustraliaPost provides a test server to test your site configuration prior to launch. Clicking Test configuration below will use your Access Key, User ID and Password to test several transactions against the AustraliaPost Test Server URL.'),
'#default_value' => (variable_get('shipcalc_australiapost_test_url', '') ? variable_get('shipcalc_australiapost_test_url', '') : 'http://drc.edeliver.com.au/ratecalc.asp'),
'#required' => TRUE
);
$form['australiapost']['test']['submit'] = array(
'#type' => 'submit',
'#value' => t('Test Australia Post configuration')
);
}
/**
* Shipcalc _settings_form_submit hook.
*
* Save data from our AustraliaPost-specific configuration form.
*/
function australiapost_settings_form_submit(&$form) {
global $form_values;
$op = $_POST['op'];
if ($form_values['shipping_partner'] == 'australiapost') {
variable_set('shipcalc_australiapost_postalcode', $form_values['australiapost_postalcode']);
variable_set('shipcalc_australiapost_turnaround', $form_values['australiapost_turnaround']);
variable_set('shipcalc_australiapost_url', $form_values['australiapost_url']);
variable_set('shipcalc_australiapost_test_url', $form_values['australiapost_test_url']);
}
if ($op == t('Test Australia Post configuration')) {
// Populate a fake transfer.
// Find the first 'shippable' product type.
$ptypes = product_get_ptypes();
foreach (array_keys($ptypes) as $ptype) {
if (product_is_shippable(NULL, $ptype)) {
// Load the first product of this type.
$nid = db_result(db_query(db_rewrite_sql('SELECT n.nid FROM {node} n INNER JOIN {ec_product} p ON n.nid = p.nid WHERE p.ptype = "%s" LIMIT 1', $ptype)));
if ($nid) {
$node = node_load($nid);
}
break;
}
}
if (!$node) {
drupal_set_message(t('To test UPS configuration you must first create a %ptype_nice and assign it shippable properties.', array('%ptype' => $ptype, '%ptype_nice' => $ptypes[$ptype])));
return;
}
$txn = new StdClass();
$txn->items[] = $node;
$txn->address['shipping']->zip = 2096;
$txn->address['shipping']->country = 'AU';
$rates = australiapost_get_rates($txn, 'http://206.191.4.228:30000', TRUE);
drupal_set_message(theme('shipcalc_testing_results', $rates));
}
}
/**
* Shipcalc _product_attributes hook.
*
* Update the product form with fields that we need. It is possible for
* multiple carriers to define the same field -- that is fine. So long as
* the field as the same name (e.g. 'weight'), it will only be displayed
* once, and the data will be saved and restored for use by all shipping
* partners that define it.
*/
function australiapost_product_attributes($form) {
$fields = array();
$fields['weight'] = array(
'#type' => 'textfield',
'#title' => t('Product Weight'),
'#description' => t('The weight of the product (in Kilograms)'),
'#default_value' => $form['#node']->product_attributes['weight']
);
$fields['width'] = array(
'#type' => 'textfield',
'#title' => t('Product Width'),
'#description' => t('The width of the product (in Centimeters)'),
'#default_value' => $form['#node']->product_attributes['width']
);
$fields['height'] = array(
'#type' => 'textfield',
'#title' => t('Product Height'),
'#description' => t('The height of the product (in Centimeters)'),
'#default_value' => $form['#node']->product_attributes['height']
);
$fields['length'] = array(
'#type' => 'textfield',
'#title' => t('Product Length'),
'#description' => t('The length of the product (in Centimeters).'),
'#default_value' => $form['#node']->product_attributes['length']
);
return $fields;
}
/**
* Shipcalc _get_rates_form hook.
*
* Request rates from UPS for the current transaction. Return a form of all
* shipping options that the shipcalc module will display during the checkout
* process.
*/
function australiapost_get_rates($txn, $testing = FALSE) {
$myfile=file('http://drc.edeliver.com.au/ratecalc.asp?Pickup_Postcode='variable_get('shipcalc_australiapost_postalcode', '').'&Destination_Postcode='.$txn->address['shipping']->zip.'&Country='.$txn->address['shipping']->country.'&Weight='.$weight.'&Service_Type='.$method.'&Length='$length.'&Width='.$width.'&Height='.$height.'&Quantity='.$var_quantity);
return $rates;
}