order_total modules update total but this update is not available to payment modules
Hello,
I am hoping someone can clarify how order_total and payment modules are supposed to work with the $order global.
I am running ZC v2.1.0, and noticed that although the order_total modules update order->info['total'] in the first part of the checkout, this updated information does not appear to be available to the payment modules later in the checkout.
Instead, different payment modules appear to be either redoing the order_total calculations entirely (paypalwpp for example), others seem to selectively add certain order_total components (e.g., stripe module considers low order fee).
Re: order_total modules update total but this update is not available to payment modu
The discussion in the Stripe payment module thread is probably sufficient, my take-aways have been as follows, regarding the order_total.php module:
- order_total module processing is a little messy and depends on best practices being followed.
- process() seems to have two side effects: (a) change the value of the order total order->info['total'] by adding any order total fees/adjustments; (b) add HTML to the output array for addition to the page.
- I think it might help if the HTML output array were initialized to an empty array in the processing() function, as this function is called either directly, or from the pre_confirmation_check() function, sometimes only to return the correct order total in order->info['total']. Otherwise, duplicate HTML output is generated if processing() is called multiple times on a page before the output array is actually output there.
- I understood that pre_confirmation_check(true) can be used to obtain just the order total with various order total adjustments/fees added. However, as this also changes the output array regardless through the call to process() it might be useful to exclude output array being modified in case of calling with true. Since we do not know what output already is, or when pre_confirmation_check(true) might be called, that could be delegated to the individual order total functions via a parameter to the process() function, or more simply repeat the exercise of saving original order->info['total'] by also saving the initial state of the output array and then restoring it at the end likewise.
- Having process() called multiple times might be necessary, but maybe the info from any run could be kept in the order or some related object to be referenced easily instead? No idea on the trade-off of processing and other overheads, not to mention code to refer to such new items.