Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
Problem/Motivation
My client wants to offer a discount off each qualifying item, but not the first item.
Proposed resolution
This simple patch adds a new discount type, "Fixed amount off per qualifying item except first".
Remaining tasks
It may need additional logic to ensure a minimum quantity of at least 2. Right now, you need to set that minimum quantity manually.
User interface changes
The new discount type appears on the "edit discount" screen.
API changes
None.
(Patch to follow.)
Comment | File | Size | Author |
---|---|---|---|
#10 | uc_discounts_alt.zip | 84.63 KB | philsward |
#5 | uc_discounts_alt_qualifying_except_first_d7.patch | 3.19 KB | Anonymous (not verified) |
#2 | add-discount-type-except-first-1285404.patch | 1.66 KB | Anonymous (not verified) |
Comments
Comment #1
jrust CreditAttribution: jrust commentedI wonder if this sort of (relatively) custom need wouldn't be better handled using the hook_uc_discount() and then putting up the recipe in docs or something?
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedHere's the patch. It's against what I got with a "git clone" -- might be the wrong version?
Thanks for the quick response. I'll check out hook_uc_discount().
Comment #3
Anonymous (not verified) CreditAttribution: Anonymous commentedHmm, the "times applied" in "this discount was applied X times" seems to be off now. Not sure what I did wrong there.
Comment #4
Anonymous (not verified) CreditAttribution: Anonymous commentedUpgrading a site to D7, so I include the patch here. Note that this patch replaces the "qualifying items" with this custom behavior. (It defines the new constant as 4 and the old constant as 6.) You can easily change this back, though. I did it this way to preserve the data on my site (as I think I'll be the only one using this patch.)
I did look at hook_uc_discount, but it does not seem to expose how many times the discount is being applied on a particular order, so it won't work here.
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedLet me try that patch again.
Comment #6
radioflyer CreditAttribution: radioflyer commentedThank you for this patch. It's exactly what I need. Can the most recent version of this patch be applied to 7.x-2.0-alpha3, or do you recommend reverting back to alpha1 if this functionality is required?
Comment #7
tinker CreditAttribution: tinker commented@srfarnsworth, This patch will not apply to any releases after 7.x-2.0-alpha1.
@all, if you want this included in module:
- Need to be re-rolled against 7.x-2.0-dev
- Constants DISCOUNT_TYPE_FIXED_AMOUNT_OFF_PER_QUALIFYING_ITEM should remain as 4 and new DISCOUNT_TYPE_FIXED_AMOUNT_OFF_PER_QUALIFYING_ITEM_EXCEPT_FIRST should be 6 to ensure backwards compatibility.
- Messages should not be changed as they apply to all discounts - @times_applied should be included and correctly calculated.
When/if new patch is provided set status to "Needs review". Others will then need to test to make sure this addition does not have any effect on existing discounts that do not use it and it works properly for new discount type. Once reviewed by at least 3 people it can be set "Reviewed and Tested" and I will look at it again.
Comment #8
philsward CreditAttribution: philsward commentedToo bad this hasn't gained traction... I need this exact approach.
First item has shipping cost built in. Subsequent items up to a certain qty, can ship in the exact same box, making the subsequent shipping irrelevant.
This should be extended though to deal with a "between" qty.
Between 1 - 4, apply discount for qty 2, 3 and 4. Start over if qty is 5 and goes up in multiples of the between amount.
Comment #9
philsward CreditAttribution: philsward commentedI had someone add this functionality to Disc. Alt if anyone is interested. At this point, there isn't a "patch" for the changes but I "might" be able to get ahold of one? I think there were 3 or 4 (maybe more) files that were altered in order to pull it off. The change adds 2 new columns to the DB to store the data for the scenario of Discount for items after X. It isn't limited to the first item. You set the max number in the batch, say 6, then discount 4 after the first 2. This would allow someone to have a shopping cart setup where a customer purchases 2 items at full price, then gets a discount for 3,4,5 and 6. After 6, it resets again.
So far it's been working well for me with the limited testing I've done. If no one is opposed, I can dump the entire module into a zip and upload it for someone to extract and pick apart. Creating patches is beyond my ability unless I contact the developer and request one. Just easier for me to upload the zip.
Comment #10
philsward CreditAttribution: philsward commentedAttaching full patched version with "Discount off of first (x) items". Sorry for not applying an official patch.