Commerce Custom Donation Amount

SG
SG
Vote:
 

Hello,

I am buildling a shopping cart for the charity organization and need some help with what will be the best practice to implement a donation feature in Commerce. So, basically when customer purchase any product and when checkout we ask them if they want to donate anything - customer can select pre-defined value £1, £5, £10 etc. or can type in any amount ( ex: £3.85 ).

Question is do I have to create donation as product/variant? In that case how to set dynamic price that typed by customer. Or any other way to add donation amout to the purchased product.

TIA,

#323414
Jun 11, 2024 13:46
Vote:
 

Hi SG

You have two design options

  1. Use Product/Variant approach OR
  2. Single Variant approach

For #1, You create Donation product, then create a couple variants that populate the pre-defined value (e.g.£1, £5, £10) and one variant doesn't have price set and programatically populate the price in your business logic by set LineItem.PlacedPrice for the dynamic price variant

For #2, You hard coded the display option in UI, then use the same technique to populate the price for Donation variant.

I don't see big differences between these approaches. With option #1, you have some flexbilities to manage content through Commerce instead of hard code in UI.

I hope it helps.

#323457
Jun 12, 2024 6:40
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.