I would like to add a new line item to the order that sums a fee, when the user selects the COD payment (Created with payment).
After reading several posts on how to create a rule that adds a Cash on Delivery fee to an order, and not finding explained examples, I have created a rule called “COD payment add line item”:
Event:
Select available payment methods for an order
Conditions:
Selected payment method comparison
Actions:
- Fetch entity by property
Parameter: Entity type: Commerce order, Property: Order ID, Value: [commerce-order:order-id], Limit result count: 1
Provides variables: Fetched order (order_fetched)
- Fetch entity by property
Parameter: Entity type: Payment, Property: User ID, Value: [site:current-user:uid], Limit result count: 1
Provides variables: Fetched payment entity (payment_entity_fetched)
- Add a line item
Parameter: Payment: [payment-entity-fetched:0], Machine name: COD payment fee, Description: COD payment fee line item, Amount: 450
The idea is to fetch the unrelated entities of commerce order and payment, and then adding a line item to the commerce-order:line-items, but if I use Add a line item does not add anything to the order, and if I use Add an item to the list (commerce-order:line-items), the payment entity is not available.
I would like to know if there is any way of using this approach, and what are the alternatives,
Cheers.
Comments
Comment #1
xanoMoving this to Drupal Commerce, as this sounds like it belongs there.
I am not familiar with loading entities within Rules. What you should be aware of, is that Payment payments are related to Commerce Payment transactions, and those in turn are related to Commerce orders.
Comment #2
rszrama commentedWe don't actually handle support requests in this queue, deferring to http://www.drupalcommerce.org/questions. However, I can say that the event you've chosen won't work - that is specifically for building the checkout form to determine what payment methods should be available. Honestly, I wouldn't use Rules at all for this. I believe something of this nature requires a custom module at this point in time.
Comment #3
Anthony Goode commentedThanks for your reply. I changed the approach and like you suggested I used a module. That is commerce fees. I used the action rule called “Apply a fee to an order”, that can be triggered on the Completing the checkout process and with the condition of Payment method is Cash on delivery.
The problem was that it had a bug that it added the COD fee to the product total amount, and the COD fee as a line item, so in the end the fee was added twice to the order total.
Fortunately I could fix it. I wrote down the solution that works for me in an issue comment of the commerce fees module. I hope this helps.
Cheers!
Comment #4
giorgoskAnyone still looking for something like this
commerce fees could be used
even though it does not work perfectly
would be a good choice
https://drupal.org/project/commerce_fees