Re: Conditional shipping option?
Quote:
Originally Posted by
Ajeh
You could try customizing the class:
/includes/classes/shipping.php
Code:
for ($i=0; $i<$size; $i++) {
if (is_array($cheapest)) {
// never quote storepickup as lowest - needs to be configured in shipping module
if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup' and $rates[$i]['module'] != 'usps') {
$cheapest = $rates[$i];
}
} else {
if ($rates[$i]['module'] != 'storepickup' and $rates[$i]['module'] != 'usps') {
$cheapest = $rates[$i];
}
}
}
I made that change, but nothing happened.
Just to be clear. There are two cases:
1. Domestic shipping - Always and only USPS priority
2. International shipping, Always Fedex, and sometimes also USPS FC if FedEx>$40
It is case #2 that we are discussing. When the FedEx is >$40, USPS FC appears, but USPS FC is always by default selected. I want FedEx to always be default selected.
Re: Conditional shipping option?
Check your code for:
/includes/classes/shipping.php
Code:
$cheapest = false;
$size = sizeof($rates);
for ($i=0; $i<$size; $i++) {
echo 'Shipping cheapest: ' . $rates[$i]['module'] . ' cost: ' . $cheapest['cost'] . '<br>';
if (is_array($cheapest)) {
// never quote storepickup as lowest - needs to be configured in shipping module
if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup' and $rates[$i]['module'] != 'usps') {
$cheapest = $rates[$i];
}
} else {
if ($rates[$i]['module'] != 'storepickup' and $rates[$i]['module'] != 'usps') {
$cheapest = $rates[$i];
}
}
}
$this->notify('NOTIFY_SHIPPING_MODULE_CALCULATE_CHEAPEST', $cheapest);
return $cheapest;
and make sure it matches and add the line in RED ...
Next, logout, then login and try the checkout ...
What do you see from the echo? And, now does the cheapest stop showing as USPS?
Re: Conditional shipping option?
I don't quite understand why, but in order for the changes to take effect I did have to log out then back in.
Once I tried your test above and saw that it did work, I then retried your code changes to make it default to FedEx. It worked.
But it had a side effect that for the US domestic shipping case, where only USPS priority is offered, USPS was not selected. Hence when Continue was selected, an error is displayed that no shipping was selected even though there was only one choice.
Re: Conditional shipping option?
Change the echo to this:
Code:
echo 'Shipping cheapest: ' . $rates[$i]['module'] . ' cost: ' . $cheapest['cost'] . ' $size: ' . $size . '<br>';
Logout and login and try that again and post what the echo reads when you just have the 1 choice and cannot continue ...
Re: Conditional shipping option?
Made the change and this printed.
Shipping cheapest: usps cost: $size: 1
This is with the original code, that is without this:
Code:
and $rates[$i]['module'] != 'usps'
Re: Conditional shipping option?
What happens if you try this:
Code:
for ($i=0; $i<$size; $i++) {
echo 'Shipping cheapest: ' . $rates[$i]['module'] . ' cost: ' . $cheapest['cost'] . ' $size: ' . $size . '<br>';
if (is_array($cheapest)) {
// never quote storepickup as lowest - needs to be configured in shipping module
if ($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup' and ($rates[$i]['module'] != 'usps' && $size > 1)) {
$cheapest = $rates[$i];
}
} else {
if ($rates[$i]['module'] != 'storepickup' and ($rates[$i]['module'] != 'usps' && $size > 1)) {
$cheapest = $rates[$i];
}
}
}
Re: Conditional shipping option?
Added the change above, tried it several times, logging in, then out, then back in again. Each time USPS Priority was not checked for the Domestic US case
Re: Conditional shipping option?
You have FedEx installed and USPS ... which options are selected on each one?
What is the weight of the order that you are testing?
Re: Conditional shipping option?
I have to go to bed ... if you just have the 1 USPS option selected, then try this:
Code:
for ($i=0; $i<$size; $i++) {
//echo 'Shipping cheapest: ' . $rates[$i]['module'] . ' cost: ' . $cheapest['cost'] . ' $size: ' . $size . '<br>';
if (is_array($cheapest)) {
// never quote storepickup as lowest - needs to be configured in shipping module
if (($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup' and $rates[$i]['module'] != 'usps') or $size == 1) {
$cheapest = $rates[$i];
}
} else {
if (($rates[$i]['cost'] < $cheapest['cost'] and $rates[$i]['module'] != 'storepickup' and $rates[$i]['module'] != 'usps') or $size == 1) {
$cheapest = $rates[$i];
}
}
}
Re: Conditional shipping option?
1. Domestic shipping - Always and only USPS priority
2. International shipping, Always Fedex, and sometimes also USPS FC if FedEx>$40
So for USPS, only 1 domestic option is checked; Priority. And for USPS international, only USPS FC.
FedEx is also only used for International.
Weight < 1 lbs
It seems to be working with that last change. I need to do more testing to be sure