Drupal Ubercart non shippable workflow changes

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:

  1. This problem only occurs if the customer is not logged in during the checkout.
  2. 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.
  3. 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:

  1. Anonymous checkout creating new account. With or without "Login user on checkout" option.
  2. Anonymous checkout matching email address of existing account but completing checkout without logging the user in.
  3. 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. 

Add your comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account associated with the e-mail address you provide, it will be used to display your avatar.
     d5MMS    .d9M58b.   H5@@HE98E8   .d5E9Sb.    .dS9S@b.  
dSPM98 dHMP YH9b d5HP d@8P Y95b dE5P Y@5b
dMP S@H HES dH5P 895 .dHHP
dSP E5M .dH8P dMEP 95@dM88b. MES8"
d5@ @9E .od5MMP" HM5S@SSM S@8P "YS9b "YMb.
8@EESE@@H9 dMHP" dS@P MMM @9M E8H 58H
5H8 MME" d59P YMMb d95P Y@9b dE@P
858 8HM8H8S@H dS5P "YES@EP" "YE589P"