Here is my hack (since I do not trust my programming skills) for function cheapest() in includes/classes/shipping.php
to use the preferred postage method even when it is not the cheapest. In this case, refrigerated service "yupackchilled".
It only becomes the preferred method between 1st May and 30th September each year.
Code:
/../
$cheapest = false;
$preferred_found = false; // to indicate if already found preferred method
$size = sizeof($rates);
// override normal YuPack with refrigerated Yupack during the below period
// 1st May - 30th September
$curr_date = date("m-d");
$date_start = "04-30"; // use previous day
$date_end = "10-01"; // use following day
for ($i=0; $i<$size; $i++) {
if (is_array($cheapest)) { // if it is an array or not
// override with yupackchilled
// if this module is active we will use its quote
if ( $rates[$i]['module'] == 'yupackchilled' and $curr_date > $date_start and $curr_date < $date_end ) {
$cheapest = $rates[$i];
$preferred_found = true;
}
// never quote storepickup as lowest - needs to be configured in shipping module
//if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup') {
if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup' and $preferred_found == false) {
// update if the current rate is cheaper than the current cheapest rate
// but make sure not to override preferred method
$cheapest = $rates[$i];
}
} else { // if it is not an array
if ($rates[$i]['module'] != 'storepickup') {
// override with yupackchilled
// if this module is active we will use its quote
if ( $rates[$i]['module'] == 'yupackchilled' and $curr_date > $date_start and $curr_date < $date_end ) {
$cheapest = $rates[$i];
$preferred_found = true;
}
if ( $preferred_found == false ) {
// update but
// make sure not to override preferred method
$cheapest = $rates[$i];
}
}
}
}
$this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest, $cheapest, $rates);
return $cheapest;
/../
Note to self: Probably adding such functionality would be nice to have, in future Zen Cart versions. As I get more comfortable I might consider adding this myself. Still need to learn how to use observers though.
Bookmarks