Closed (fixed)
Project:
Commerce Core
Version:
7.x-1.x-dev
Component:
Documentation
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
24 Mar 2011 at 14:25 UTC
Updated:
5 Mar 2012 at 18:44 UTC
Im trying to figure out how-to or if its possible to create a rules that use a different price (i have already a different price field inside the product entity) on teasers or full nodes depending of the user role. Im looking for a tip to get me started with rules in this scenario.
At the moment I´m stuck with:
Create a new rule.
Event->User has logged in.
Condition->User has roles (check the role i´m interested)
Action-> Here i dont see any action that fit. I see some calc actions relate to line items.
I suppose along the way I will need my custom field price so it will be necessary to use components to access it ?¿?
Comments
Comment #1
rszrama commentedIf I understand your scenario right, you're just needing to create a "Product pricing rule" that discounts the price based on whether or not a user has a particular role. You can import this for an example (doubles product price for administrator role):
Does that get you far enough?
Comment #2
EndEd commentedwell thanks for that but what im really trying to do is to mimic the same behaviour you get with the Ubercart Price Per Role module (http://drupal.org/project/uc_price_per_role)
I´ll try to do my best to explain it:
So in the product entity i made a custom price field (apart from the default one 'commerce_price'). Lets call it 'field_product_role_price'. I fill both prices with Feeds so then every product entity have 2 prices. I create the product displays and by default, the price I see when i check the teaser or fullnode is the one that cames from commerce_price product entity field.
I want (if posible) to use rules to change the price you see on product display nodes by role. So change 'commerce_price' for 'field_product_role_price' as the default price at the display level.
If im Role1 the price i see in a node comes from 'commerce_price'
If im Role2 the price i see in a node comes from 'field_product_role_price' (my custom price)
Also this have to affect at the line-item level so the order get the right price.
Your solution is great to do calculations based on the commerce_price product entity field at the line-item level but I my case i get the role price via feeds with different pre-calculations per product so there is no pattern (double the price)
If rules alone can't handle it i'll try to make a module. Any advice about how you would do it will be great.
Comment #3
rszrama commentedIt's the same thing, just instead of using the "Multiply unit price by some amount" action, use the "Set the unit price to a specific amount" action using the data selector for your custom price field. The only problem is that w/ the Rules bug for accessing fields of referenced entities, I'm not sure if you'll be able to select your custom price field or not. You might have to come up with a custom action until that's fixed in Rules.
Comment #4
EndEd commentedWell, thanks for the tips and the patience. I finally done it using php evaluation.
Comment #5
pcambraProbably you'd better create your own custom action for this instead of having raw php there because it could cost you some security extra risks.
Comment #7
hozt commentedThanks for the code EndEnd, it works well as an interim solution until the rules module is fixed.
@pcambra do you have some insight how to do this as a custom action?
Here is the rules bug:
#1053850: Fix metadata-assertions for referenced entities.
Comment #8
rszrama commentedI'm going to reclose this issue, as the original post has been solved. The Commerce queue isn't really for general Rules discussions, though you can feel free to find help in the IRC channel or in a support request in the Rules tracker. I'd really just suggest looking at code that's similar to what you're trying to do and adapting it based on other Rules action definitions.
Comment #9
westie commentedI want to do something very similar but cant find out how to use the PHP evaluation in rules to pull a value from a product field...
Where are you able to find "$product-\u003efield_product_tapper_price['und'][0]['amount'];" from?
Comment #10
pitxels commented@rszrama
hi, having #1053850: Fix metadata-assertions for referenced entities. fixed , could you please point how Rules can be used for having a price per role scenario. I know this is not a Rules discussion, but comming from using ubercart and not knowing what is an entity, I am very noob at this concept. thanks
Comment #11
rszrama commentedI'd check the forums on DC.org for existing discussions first.
Comment #12
pitxels commentedPrice discounts were indeed documented, but not price per role.
I am posting here what I finally think is a clue (not tested yet)
I hope this link is more helpful that asking users to search, if not the case I apologize.
http://www.drupalcommerce.org/node/981
and http://www.drupal.ru/node/66535 (russian)