Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I've searched everywhere for a hint about how to set this up and finally decided to ask.
My cart needs to only checkout when a minimum number of products from a taxonomy / catalog term are added. So, instead of the minimum order being applied to a specific product or all products, it's done by taxonomy term.
Any ideas on how to make this happen? Is there a module out there that already does this? The existing Min/Max modules I found only apply to individual products, and not taxonomy.
Thank you for any help you can provide.
Comment | File | Size | Author |
---|---|---|---|
#10 | uc_cart_checkout_start-1334970-10.patch | 1.84 KB | DanZ |
#8 | uc_cart_checkout_start-1334970-8.patch | 1.97 KB | DanZ |
#6 | uc_cart_checkout_start-1334970-6.patch | 3.29 KB | DanZ |
#5 | uc_cart_checkout_start-1334970-5.patch | 3.2 KB | DanZ |
Comments
Comment #1
longwaveI think you will need a custom module for this at present.
Having said that I think a useful feature request would be a "Before displaying the checkout page" CA/Rules event that lets you run conditions on the order and then show a message, run conditions against the order, etc. if the conditions are not met. So, let's refocus this issue on that.
Comment #2
TR CreditAttribution: TR commentedNew features go in to 7.x-3.x first. Please submit a patch if you'd like to see this put into Ubercart.
Comment #3
DanZ CreditAttribution: DanZ commentedIt would be simple enough to add an event that is invoked before displaying the checkout page. The problem is a matter of getting some sort of proceed/abort signal after executing a rule. I don't know the best way to get information back from a rules_invoke_event() call, as it doesn't support passing variables by reference.
Once that's figured out, it would reasonable to add an "Abort Checkout" action which would print an error message and indicate that checkout shouldn't proceed.
I intend to write a module to do something similar in the next month or so. It maintains a list of Rules conditions that must be true for checkout to complete. It lets the customer get to the checkout page, but displays a checkout pane with appropriate error messages if the checkout can't proceed. Attempting to complete checkout will just update the error pane and cycle back to the checkout page if there is a problem.
Comment #4
DanZ CreditAttribution: DanZ commentedAlso, BullMoose asked for the order to be checked for a minimum number of products from a specified taxonomy term. There isn't a Rules condition for this at this time, right? There probably should be.
Comment #5
DanZ CreditAttribution: DanZ commentedOk, this patch adds a "Customer starts checkout" event and an "Abort Ubercart checkout" action.
The "Customer starts checkout" event is invoked right before generating the checkout form.
If a rule is triggered by a "Customer starts checkout" event and executes an "Abort Ubercart checkout" action, the user is sent to the cart page and Drupal puts a user-configured error message on the page.
I've tested this to enforce order quantity on customers with a "wholesale customer" role. It works and it's exactly what I needed.
Comment #6
DanZ CreditAttribution: DanZ commentedOops, left out a t() or two.
I'm feeling pretty uninspired with my messages ("You can not check out") and labels. Feel free to suggest something better.
Comment #7
longwaveCan we not do this a much simpler way? Just invoke the event, don't do any special processing, and let the user use the "Display a message on the site" and "Page redirect" Rules actions to display a message and abort checkout if that's what they want. This way we don't need the separate "Abort Ubercart checkout" event at all, and it's even more flexible in terms of messages and deciding where to redirect the user to.
Comment #8
DanZ CreditAttribution: DanZ commentedI didn't know about using page redirection to abort something like this. Now I do.
Here's a patch with just the event, with no extra actions. I tested it with system messages and page redirects, and it works just fine.
I also added a hook for starting checkout.
In other news, I noticed that the uc_checkout_complete Rules event really ought to be named uc_cart_checkout_complete, and hook_uc_checkout_complete() really ought to be named hook_uc_cart_checkout_complete(). It's obviously too late to just change that, as it may break things. What's the right approach here? Just leave it until Ubercart 4? Duplicate them with the correct names, deprecate the old names, and remove them in a year?
Comment #9
longwaveThis looks better. Though, if we're going to pass $account to the hook, we should pass it to Rules as well for consistency. But do we even need to pass $account? Isn't the current user (ie. global $user) going to be the user that starts checkout?
Comment #10
DanZ CreditAttribution: DanZ commentedWe don't need to pass $account. I did it that way because that's how hook_uc_checkout_complete() does it, and I was trying to maintain consistency.
Note that hook_uc_checkout_complete() also doesn't need it. It takes $account straight out of $order, and any hook implementation could do the same thing.
Here's a version without $account. Use it if making sense is a better idea than maintaining consistency.
Comment #11
longwaveCommitted #10, thanks for working on this.
Comment #12
DanZ CreditAttribution: DanZ commentedYou're welcome.
Bullmoose's original request also requires checking to see if there are min/max products with a given taxonomy term. Should we create a new feature request to add that as a Rules condition?
Comment #13
longwaveI guess that should be a new feature request, but I would hope for a more generic solution, entirely Rules based if possible. There is a "list contains item" condition, I wonder if we can extend or reuse this somehow to look through the list of products in the order, and ideally filter on any other available Rules condition.