Which is the best way to Alter Product Pricing in a complex scenario?
I'm a Drupal Commerce newbie (almost a Drupal newbie too). I'm testing Drupal Commerce to see if i could use it for my e-commerce projects instead of another solutions like Magento, osCommerce, and so on. I've installed Commerce Kickstart and I've been testing it, i've been reading the Drupal Commerce documentation, etc. Drupal Commerce seems pretty nice, but I need anybody who points me in the right direction so i can customize it for my scenario.
This is my scenario:
I'll have N types of customers, being N and integer (2,3...).
I'll have a user field who will identify the type of customer for each user.
The price of a product needs to be different for each type of customer.
So, I need to have N different prices for each product. When a customer of type X is browsing the commerce site, it must see the prices for the X type of customer and those prices must be the prices used for that type of customer along all the shopping process (displaying prices, viewing prices in the shopping cart, prices in the order, etc).
I've been trying to do that for a scenario with N=2. In this secenario, for the first type of customer i want to show one price and for the second type of customer i want to show a different price, so:
I've created a second price field of type "Price" for the "Product" content type.
I've added a new field to the user entity for the information about the type of customer.
Then, I've tried to change the product prices using a "Product Pricing Rule" reacting to the "Calculating the sell price of a product" event.
I've added a "Entity has field" condition to load the current user and the type of customer field in the context.
Then, I've added another condition of type "Data comparison" to compare the type of customer field with the second type of customer.
Then, I've added an action of type "Set the unit price to a specific amount".
If i set manually the amount it works fine. It is useless, but it lets me know that the type of customer condition is working. I've tried to change the action to change the price for the value in the second price field i've created for the "Product" content type but i couldn't achieve it. I couldn't select the second price field to set the unit price value.
After having tried many things, i've stopped trying this way and I started to try new ways to achieve the desired results. So, I've been reading the documentation about the Drupal Commerce code, reviewing Drupal Commerce's code and so on.
So, I've created a new module which implements the "hook_commerce_product_calculate_sell_price_line_item_alter". This way i can change the price of the products showed in the site, but when i add a product to the cart, the price showed in the cart is not the price i've seen prior to click on the "Add to cart" button.
I've tried a few other hooks: "hook_commerce_cart_product_prepare", "hook_commerce_cart_product_add", "hook_commerce_price_field_formatter_prepare_view" and "hook_commerce_price_formatted_components_alter" but i couldn't achieve the desired results.
So these are my questions about Drupal Commerce:
1.- Is there a way to do what i need using a "Product Pricing Rule"?.
2.- Which is the way to do it programatically? Which are the involved hooks i'd need to implement?.
3.- Whis is the recommended way to achieve the desired results? Using "Product Pricing Rules" or implementing hooks?.
And that's all for the moment. Many thanks in advance, i'll keep trying while waiting for responses from the Drupal Commerce gurus...