lat9:
So, in a nutshell, your Clause5 replaces my Clause3 ... which at least lines the results up but still doesn't answer the question as to whether/not the cheapest method should be called at all when there are no shipping modules available. That processing, BTW, winds up setting $_SESSION['shipping'] = false;
The processing of the shipping class' cheapest function handles the condition regardless (modules assigned in ZC admin or not and if at least one is then a notifier is also available), the question seems to have become what should be done to see if shipping is in a condition where it would be of benefit to identify a cheapest option (ie. a method is not selected).
Basically if a method hasn't been assigned, then the header_php.php version of the file attempts to choose one. Being unset and one not existing at all are two different things. If I remember correctly, when the test of !isset($_SESSION['shipping']) was added to the list, there was a challenge then about whether the check should include the count of available options or not as well. The result seems to be that the functionality within $shipping->cheapest negated the need for the verification to begin with and was effectively double work, even though there is a nifty function that has a name identifying the type of useful information being provided.
From a line by line everything in the code is human readable, makes sense, is methodical, then I would say that these few lines of code need to be expanded and a little more added; to provide operation, results and perhaps a bit more rigidity, then actually the code could be trimmed down a little.
But in short at this point in the processing (includes/modules/pages/checkout_shipping/header_php.php), the goal is to ensure that a method is chosen (if one exists) or if shipping is not yet customer/store identified then to identify the status of shipping... In looking at just the ZC 1.5.x history of this area of code, there have been several changes to the determination of when to assign $_SESSION['shipping'] to the cheapest value; however, the cheapest function has remained unchanged in all of that... In 1.5.0, the code was similar to what carlwhat has thrown into this mix, basically the only time that the cheapest value was obtained was when $_SESSION['shipping'] was loosely a false value. Yes there was a function shown to maybe "make a difference" but, it wasn't called.
Even in ZC 1.5.0 there was this portion of code in the includes/modules/pages/checkout_shipping/header_php.php file. The second part of the if statement ```
( $_SESSION['shipping'] && ($_SESSION['shipping'] == false) && (zen_count_shipping_modules() > 1) )
never provides a true condition especially that processing never makes it past the second parameter. Either $_SESSION['shipping'] is somehow false and the remainder of the statement is not processed or it is in some way true which means that it fails the second parameter because if it is true it is not also false.
In the end... what I'm saying is that the header_php.php file for ZC 1.5.5+ would work just fine at determining/assigning a shipping setting if it were:
if ((!isset($_SESSION['shipping']) || !isset($_SESSION['shipping']['id']) || $_SESSION['shipping']['id'] == '') $_SESSION['shipping'] = $shipping_modules->cheapest();
If though the desire is to "feel good" about trying to determine the cheapest module because it is "known" that a module not only exists but is enabled then the code would need to be expanded to:
if (((!isset($_SESSION['shipping']) || !isset($_SESSION['shipping']['id']) || $_SESSION['shipping']['id'] == '') && zen_count_shipping_modules() >= 1)) $_SESSION['shipping'] = $shipping_modules->cheapest();
// This if ensures that $_SESSION['shipping'] has the same value as it would have before the above code change ensuring that there was >=1 shipping module that is both installed and enabled.
if (!isset($_SESSION['shipping'])) {
$_SESSION['shipping'] = false;
]
or when managing/displaying shipping information that it needs to evaluate the absence of a $_SESSION['shipping'] value understanding that if there is no shipping method selected/assigned then when any are displayed, none will be default selected. This could ultimately be a problem for say PayPal Express checkout where the cheapest method is to be chosen to expedite checkout...
As far as strict controls go... It looks like for stores that only have in store pickup, they will get a warning on their checkout_shipping page (assuming they even access that page considering only one method exists and would be available) because the cheapest module would skip an instore pickup as an option to choose as cheapest, resulting in no button being selected by default (same "issue" would occur for any module set to be skipped by the cheapest function). But in a default store this is then caught when accessing the checkout_payment page because $_SESSION['shipping'] is not set sending the code back to the checkout_shipping area.
The question has in a way always been, what defines a method as being not chosen or how should a method be unchosen? Currently it stands within the ZC default shipping modules as $_SESSION['shipping'] being unset, or $_SESSION['shipping']['id'] being unset or == ''... Meaning that it would all work the same if the quantity were checked or not because calling cheapest in any of those conditions would only provide a shipping method if a method was installed, enabled (and not storepickup), otherwise the result (a non-shipment method) would be false. Certainly if it is identified early enough what methods are present then there would be no benefit in calling the cheapest function, why would there be?
But it doesn't exactly look like there is a need to check for the number of existing/available methods to obtain the result for requesting the cheapest module, it is how does one further process knowing that information. Even looking at the template code for checkout_shipping, if it determines that there are no installed/enabled shipping methods, then it reports that no methods are available and it doesn't at that point matter what $_SESSION['shipping'] is set to as processing can not continue further. Now it somewhat does appear to mean that if one knew what the "next" page was that if they have a session that is set to false they could carry on with checkout and not pay for shipping. So if anything, it seems that cheapest should return null instead of false when no match is found, when shipping is disabled, etc... And/or the header of checkout_payment should inspect $_SESSION['shipping'] differently than it does now...
So, are you trying to replicate the functionality, or trying to be sure that appropriate options are displayed/made available?