I need to add a gratuity to my site when user add a product to a cart. The function is the same to the ioby.org site. Each time the cart is updated we will update the gratuity on the cart. I have read the solution for this function from newsignature who developed this site but it's hard for me to using rules to do it. Anyone can help me? Thanks so much!
Here is the solution from newsignature:
Gratuity was at first going to be a tax type in the Commerce system. However, one of the requirements was to also give the user the ability to remove the gratuity if they felt that they didn’t want to cover the costs for it. Since tax isn't usually an optional item in shopping carts, the ability to remove it has not been placed in the Commerce tax module. To enable that ability, we place the gratuity into a line item that is calculated every time the cart is updated. Once again we used the Entity API to generate a new product, and this time the gratuity type that has an individual SKU, and a price that is a percentage of the order total. Another custom feature we added was to show a popup message when a user removes the gratuity, explaining to them the importance of gratuity for ioby. Since the view doesn’t discriminate between the different line items, it was necessary to use some front end javascript that handles this feature. And of course, with items being added and removed from the cart, it was necessary to change the price of the gratuity on the fly, assuming it wasn’t removed.