The default UberCart workflow for non shippable products, such as downloadable or non physical products (e.g. role or group access) is to mark the order "completed" only if it only contains these type of products. In most cases this is fine but a problem occurs when a customer purchases mixed physical and non shippable products. In this case access to non shippable products is not immediate. This workflow deviates from the common presumption that non physical transaction should occur instantly and be processed independantly from physical goods. Unfortunately modifying the Conditional action to trigger on a order status change to "Completed" instead of the more appropriate "Payment received" has negative repercusions. The proposed solution helps to alleviate this situation.
First three caveats:
- This problem only occurs if the customer is not logged in during the checkout.
- The solution may have problems with certain Payment processors, such as PayPal, where the "uc_cart_complete_sale" function may be eroneously called twice during checkout. This is another problem that should be addressed elsewhere.
- This solution may cause issues if File Grants have to be renewed because the customer could not complete a successful download within the specified configuration. e.g. 3 downloads from 2 IP addresses.
File access grant on payment received
Switching the "Renew purchased files" Conditional Action, to trigger on order status change to "Payment received" instead of "Completed," causes problems because it appears to trigger at the wrong time. Looking at customized store logs it is apparent that the trigger can execute before the "uc_checkout_complete," or "Customer completes checkout" predicate, which is the only action that changes the order status to "Complete." When this trigger executes, the customer information has not been created or loaded, which results in a UID (User ID) of 0 (annonymous), which in turn causes the file grants to fail. This is because file grants require a user account to track, and prepare the file for download, even though the customer may be under the assuption that they are using a truely anonymous checkout.
Switch to "Customer completes checkout" trigger
If we recreate the file grant action we can set the trigger to use the "uc_checkout_complete" or "Customer completes checkout" predicate. We cannot edit the existing "Meta Data" if "Conditions" or "Actions" are already assigned (which by default they are). Adding the contditions Order status is "Completed" OR Order Status is "Payment received", we can safely execute the file grant function knowing that the customer account information is loaded and the file grant will succeed. The psuedo conditional action code is:
Trigger: Customer completes checkout
Conditions: Check the order status is "Completed" OR Check the order status is "Payment received"
Action: Renewal - Renew the files on an order
Weight: Greater than "Update order status upon checkout completion with full payment" action
Be sure to disable the default "Renew purchased files" Conditional Action so that it does not cause unexpected.
Instant File, Role, and Group access on purchase
The new conditional action will execute after the customer information has been loaded for all three possible checkout scenarions if the weighting is correct:
- Anonymous checkout creating new account. With or without "Login user on checkout" option.
- Anonymous checkout matching email address of existing account but completing checkout without logging the user in.
- Logged in customer before checkout.
When a customer purchases physical and non physical products they will get instant access to the non physical product (file, role, group) and the standard shipping workflow can complete normally, with the order being marked "completed" only when access to all non physical products is granted and all shippable products have been sent.