Drupal 7.4 + Drupal Commerce: Adding Fees to Orders?

Events happening in the community are now at Drupal community events on www.drupal.org.
jessSchn's picture

I have a Drupal 7.4 Website setup (winginitairventures.com) using Drupal Commerce 7.x1.x-beta4 and Commerce PayPal 7.x-1.x-dev.

Issue: On the orders page I need to add two fees:
* (General Admission Ticket QTY + Reserve Seating Ticket QTY) * 25 = Admin Fee Total.
* (Hotel Package A QTY + Hotel Package B QTY) * 20 = Hospitality Fee Total.

Attempted Solutions:
1) I've searched for a Fee Module, but I have not found one
2) I've searched for a Bundling Feature (might work), but I have not found one
3) Setup Admin Fee as a Product and then tried to create a rule that would automatically add this product into the shopping cart. I'd also need to strip away the remove button and QTY feature if this would work.
4) I tried using the Tax Module that comes with Drupal Commerce but that only allows percents to be entered not dollar amounts

I'm thinking I'm close with wanting to use rules to get this Admin Fee setup but I'm struggling with how Rules work. The more specific issue with Rules is I'm not confident in my Data Selector options, for example: "commerce-line-item:order:owner:" .... what is with the ending ":" in that Data Selector? How do I know what's suppose to go after the ":" ?

Any help or suggestion would be appreciated. This project is very close to getting dumped and this Admin Fee and Hospitality Fee are the last two things to go in. :(

Comments

zkrebs's picture

However, if you use Drupal 6, or (pressflow 6.x), and Ubercart you will be able to solve the needs of Bundling and Fees rather nicely.
http://drupal.org/project/uc_fee

Bundling is done via "Product Kits" -

Best of luck, and if someone can help you with D7/Commerce, that's great too! There are many paths in life, I just take the ones with the least resistance.

2) I've searched for a

tormi's picture

2) I've searched for a Bundling Feature (might work), but I have not found one

Seems like this is something you should check out: http://drupal.org/project/commerce_product_bundle

Tormi

Commerce Product Bundle

jessSchn's picture

thanks for that suggestion. I installed the Commerce Product Bundle (and the required Commerce Product Attributes), when I selected to enable the modules I would receive this error: Fatal error: Unsupported operand types in /home//public_html/winginitairventures.com/modules/field/field.crud.inc on line 595

Also with only 26 websites using this module, I'm a little shy of this one... :(

Hi, I'm working with the

m_wiking's picture

Hi,

I'm working with the Commerce module right now also. I need to add some extra things to a order so I've been looking around a bit. The shipping module does what you want but it adds it as shipping cost. If you can code a bit you could change this so it becomes fees instead of shipping. Just a thought: http://drupal.org/project/commerce_shipping

If I come up with anything interesting in the near future I will send you the info.

Mattias

Did you ever solve this?

spaolucci's picture

Same issue here with using tax. Can only apply as percentage...

Divide by line item quantity...

occucopy's picture

..and add to unit price.

I had the same problem, but I managed around it by putting in three actions:

  1. Under Data, select "Add a variable", saving the fee amount to the new variable. (remembering Commerce Rules handle prices in cents, not dollars; so a $5.00 fee would be a "price" of 500).

  2. Under Data, select "Calculate a value". Divide that variable by commerce-line-item:quantity. Save it a second variable.

  3. Under Commerce Line Item, add this second variable to the unit price. Set the "Price component type" to Fee, and set "Price rounding" to "Do not round at all".

Basically, you're splitting the fee up into little bits that are split equally between all of the items in the line item, so that they end up giving the whole fee when multiplied back together. While this does run the risk of some funky rounding errors, it's worked for my purposes so far... and I haven't had to meddle with any code or make my own module or anything like that.

It would be nice (both for accuracy and UX) for Commerce to have its own equivalent of http://drupal.org/project/uc_fee, but alas, that is not the case for now...

This is a brilliant solution

aryosys's picture

Thanks

This is the top result for

mengi's picture

This is the top result for 'drupal commerce fee'... Has anyone come up with a solution to the task of adding a fee?

The best I've come up with is adding a rule that adds a product (the fee) to the cart. But the user can simply remove the fee and/or change the quantity of the fee through the cart interface. Also the fee remains after the original product is removed from the cart, so a 2nd Rule has to be made to remove the fee after the original product is removed.

The other issue is that I have about 50+ products that need the fee, and the condition 'order contains a particular product' only allows for a single SKU to be entered. So the Rule would need to have 50+ OR conditions, which doesn't seem like the right way to do it.

Any help would be much appreciated!

found this, haven't tried it, but...

zkrebs's picture

"Go to http://website.com/admin/commerce/config/shipping/calculation-rules and add a calculation rule. (..) add $3.50 to the calculated shipping fee. This adds the amount directly to the calculated shipping cost, in essence hiding it, which what my client wanted. If you wanted it as an additional line item, this is not the way."

Thanks for the tip. I have

mengi's picture

Thanks for the tip. I have looked at that option before, but the problem I had is that the fee is only added once. I need to the fee to be multiplied by the quantity of that product. Is there a way to do that with shipping rules?

Finally figured it out

mengi's picture

Here are the steps I went through. I plan on making a guide later on when I have more time. Hopefully this will help someone out.

Add boolean field to product type
  Machine Name: field_fee

Mark a product with the field_fee checkbox
 
Goto >Shipping>Calculation Rules
Add Calculation Rule
  Name: Fee for Product (or whatever you want)
  Add Loop
    data selector: commerce-line-item:order:commerce-line-items
    Variable Label: Line Item
    Variable Name: line_item
Goto >Rules>Components
Add Component
  Component Plugin: Rule
    Name: Adding Fee Action (or whatever you want)
    Add 2 Variables:
    Variable 1
       Data Type: Commerce Line Item
      Label: Line Item
       Machine Name: line_item
        Usage: Parameter
      Variable 2
      Data Type: Commerce Line Item
      Label: Shipping Line
       Machine Name: shipping_line
        Usage: Parameter
   Add 3 Conditions
     Condition 1
      Entity has field
         Data Selector: line-item
       Value: commerce-product
      Condition 2
        Entity has field
         Data Selector: line-item:commerce-product
          Value: field_fee
   Condition 3
      Data Comparison
          Data Selector: line-item:commerce-product:field-fee
        Operator: equals
       Data Value: (Mark the checkbox)
    Add 2 Actions
      Action 1
     Calculate a Value
        Data Selector: line-item:quantity
          Operator: *
        Input Value 2: 500 (for $5.00)(Change to whatever fee you want to charge)
          Label: Fee Result
          Name: fee_result
   Action 2
     Add an amount to the unit price
          Data Selector: shipping-line
       Amount: (switch to data selection): fee-result
         Value: Shipping
Go back to original shipping calculation rule
  Add action to the loop (MAKE SURE IT'S TO THE LOOP, NOT 'add action' to actions...it is to the right, under 'operations')
    Rule: Adding Fee Action (The Rule Component we just made)
          Data Selector 1(Line Item): line-item
          Data Selector 2(Shipping Line): commerce-line-item
WHEW! Done, test and make sure it is working. Remember that the product must have the field_fee boolean marked in order for this to work.

Try Commerce Fees module >>

Horroshow's picture

Try Commerce Fees module >> https://drupal.org/project/commerce_fees