This tutorial allows one or more donations to be made on your site. It can also be used for other types of payments where the payer specifies the amount, for example a simple invoice payment where the user enters the invoice number and amount.
1. Install the necessary modules.
- Download Commerce and install the whole profusion.
- Download and install Customizable Products
- Download and install Rules.
2. Add the donation product line item type
- Go to Store > Configuration > Line item types > Add a product line item type
- Enter a name, such as “Donation”
- Go to Manage Fields and add a field “Donation amount” of type Price. (Alternatively, add and use the Select or Other module if you want to provide donation options rather than a textbox.)
- In the settings under Add to Cart Form Settings, check the checkbox. This will allow the “customer” to enter the donation amount.
- You may also want to add other fields such as, Donate in Honor of, etc.
3. Add the product
- Go to Store > Products > Add a Product
- Enter the SKU; for example, “Donation”.
- Enter the Title; for example, “Donation”.
- The price should be 0.
4. Add a content type for the Donation product display
- Go to Structure > Content types > Add content type
- Call it something like “Donation product display” and set settings as desired.
- Go to Manage Fields and add a field of type Product reference.
- In the settings, make it a required field, choose the product types that can be referenced (probably “Product”). Save.
- Go to Manage Display.
- Product should be displayed as an Add to Cart form.
- Edit the settings for the Add to Cart form.
- All the checkboxes should be unchecked, default quantity is 1, and Add to Cart line item type should be Donation. Click Update, and save.
5. Create a product display node for donations.
- Go to Content > Add content > Donation product display.
- Call it perhaps “Donate Today!”
- Add some encouraging text in the body.
- Select “Donation: Donation” as the Product.
6. Make a rule to set the product price based on the user’s donation amount, since we set it to 0 by default.
- Go to Configuration > Workflow > Rules
- Add a rule and name it “Add donation to price”
- Add the events “Calculating the sell price of a product” and “Before saving a commerce line item”.
- Add the condition “Entity has field”, with entity set to commerce-line-item and field set to field_donation_amount
- Add the action “Set the unit price to a specific amount” with line item set to commerce-line-item and amount set to commerce-line-item:field-donation-amount:amount, and price component type set to base price.
7. Test the product.
- Go to the Donate Today! node page.
- Fill in the amount and any other relevant fields.
- When you click “Add to cart”, the donation will be added to the cart (add a link to the cart will be in the notification at the top of the page) and you will be redirected to the Donate Today! page in case the visitor wants to add more donations.
Customizations you may want to make:
- Change the Add to cart button text.
- Redirect to the cart page or have text next to the button explaining that more donations can be made after the form is submitted.
- Have a persistent link to the cart in addition to the one that appears in the notification.
7. Inspect the cart.
You should see the cart total reflecting the donation amounts.
The table may not show exactly what you want. The cart is a View, so you can edit it to add, remove, or rename columns.
Bibliography:
General usage of Customizable Products and advice on editing cart and order views:
https://commerceguys.com/blog/commerce-module-tuesday-commerce-customiza...
Advice on setting up the rule:
https://commerceguys.com/blog/using-custom-line-items-provide-donation-f...
https://www.drupal.org/project/commerce_donate
Comments
can't add custom product from
can't add custom product from line item type. Here is no option
How to tell Paypal that was a donation and not a sale
Paypal is charging fees on this!
Paypal should ask the user if it's a payment for a product/service or a donation