I'm having trouble applying a complex set of discounts to my products through rules.
The discounts are basically a user-category/product-category matrix with a different discount percentage for each cell. User categories and product categories are taxonomy lists. I have added a Field Collection field (with and infinite number of values) to the user category. In this field collection I combine a product category and a discount percentage (as a decimal), and then repeat for all product categories.
So when calculating the product sale price I need to:
- Look up the product category (works fine)
- Look up the user category and load the discounts list (works fine)
- Look up the right discount in the discounts list by product category (having trouble with this)
I've been able to look up the right discount in a custom PHP action like this:
$product_category = $product->field_product_category['und'][0]['tid'];
for($discount_index=0;$discount_index<count($user_discounts);$discount_index++){
$discount = $user_discounts[$discount_index];
if($discount->field_discount_product_category['und'][0]['tid'] == $product_category){
return $discount->field_discount_percentage['und'][0]['value'];
}
}
return 0;
But apparently returning values out of a custom PHP block is not supported.
Next I thought to install the Conditional Rules module. I could loop through the discounts and check the current loop variable against the product category and apply the discount if it matched. Within the If I can't access my loop variable though. Can anyone suggest a method that might work? I prefer not to have to write my own module if it can be avoided.