Tags/topics: 
2
Answers
Vote up!
0
Vote down!

How to calculate the sell price of a commerce product?

I know this question might sound elementary but I have been struggling with this for over a week. I have seen most of the screencasts and read most of the discussions. Somehow, I am not able to get this to work. Any help will be appreciated.

I have a customized Commerce Product Type.

1. I have a Base Price (which could be in 6 different currencies - Products are sourced from 6 different countries). This base price needs to be converted to store's default currency. I am able to convert the product sell price to default currency by using product pricing rules. How should I do this for a custom price field?

2. Need to apply a profit margin to the calculated base price. I have a custom field with a default float value. Need to calculate
Base Price * Profit Margin.

3. Need to add two types of service fee to the above amount.

Sell Price = (Base Price * Profit Margin) + Service Fee 1 + Service Fee 2

This should be a very simple to implement. However, I am totally lost.

Asked by: dragoncoder
on September 14, 2012

2 Answers

Vote up!
1
Vote down!

Thank you svdv. I did something on the lines of your suggestion. And I have totally fallen for Rules. It's amazing like Drupal (& Views & Drupal Commerce...) once you start getting a hang of it. :)

I got this to work by using static currency values for all six currency pairs and created a component (rule set) which has six rules that do data comparison on the basis of base price currency and convert the base price value to store's default currency.

There is a conditional rules module under development which adds if/else and switch clauses to rules which has the potential to convert the entire rule set of six rules to a single rule. Rules is going to rock even more sometime in near future.

This is what I did. Let me know if someone wants the exported ruleset for a similar use case. I will be happy to share.

These are the steps that I followed.

1. Do a data comparison for the Base price currency
2. Multiply the base price by currency conversion rate (static value) *
3. Multiply the above value with the profit margin
4. Add the Service Fee 1
5. Add the Service Fee 2
6. Set the value in commerce_price field

* Wanted to do a dynamic currency conversion but the customized price fields did not behave as line items even after adding them to a custom line item type. I am still not clear on the line items concept.

Answer by: dragoncoder
Posted: Sep 17, 2012
Vote up!
1
Vote down!

Hi,

I think you just need to add an extra pricing rule where you add your custom fields to the conditions group. So you add "Entity has field" for Profit Margin, for Service Fee 1 and for Service Fee 2.
You need to do this to be able to select those fields in the actions.
For the actions I would suggest you add an action "Multiply the unit price by some amount" and via the Data selector choose .....:Profit Margin:amount. This needs to be muliplied with the base price.
After that add an action "Add an amount to the unit price" where you add the Service Fee amount (use Data selector).
Then add another action "Add an amount to the unit price" where you add the Service Fee 2 amount (use Data selector).

Regards

Answer by: svdv
Posted: Sep 17, 2012