I need to have different discount rates for every customer.
I added a textfield in the user profile, where I store a Json object with all the discounts (there is a little GUI to manipulate it), so, for example, I can have this situation:
{
'product_B': 20,
'product_A': 15,
'product_C': 0
}
This means that this customer will have a fixed discount for all commerce_products
of type A, 15 on type B and 0 on type C.
I got stuck in the Rules
configuration: I created a rule for the Subtract an amount from the unit price
event; In the condition, i just check that the user and the line item match few pre-requisites, and it works, but I cant get the line_item
details in the action
:
// My action
global $user;
$ul = user_load($user->uid);
if(isset($ul->field_discounts))
{
$user_discounts = field_get_items('user', $ul, 'field_discounts');
/*
* Here i have to get few info of the current commerce_product/commerce_line_item
* in order to calculate the correct $item_discount
* */
$discount = ((int)$item_discount * $value) / 100;
return $discount;
}
return 0;
So the question is: inside that PHP block, how to get the current line item?
$line_item
? – Clive♦ Sep 16 '13 at 13:10$line_item
and$commerce_line_item
, always get null.. – Strae Sep 16 '13 at 13:13becose the value must be an amount
– Strae Sep 16 '13 at 13:14commerce_line_item_unit_price_subtract
, which does have access to the line item entity – Clive♦ Sep 16 '13 at 13:17