Hi,
I'm not sure if I should post this here or with Entity or Commerce, since the issue involves all of them.
So I'm working on a rule to update the product display node when the referenced product is updated.
Basically it looks like this:
-When product is updated
-"Fetch entity by property" the product display node which references the updated product
-Do some data operations...
The property by which I fetch is a product reference field, which is a list, not a single value, while "updated product" is a single value. As a result I get the error
Warning: array_values() [function.array-values]: The argument should be an array in rules_action_entity_query() (line 56 of ...rules/modules/entity.eval.inc)
So somehow I need to pass the argument as a list/array or I'd need a "list contains" condition.
Is there a solution or workaround for this?
Comments
Comment #1
darksnowFirstly, sorry about the cross post. I originally put this in Commerce Coupon issue queue, but I now think that it's a more general Rules issue (or lack of understanding on my part ;))
You can see the original issue I posted here: http://drupal.org/node/1292748
I made a copy of the rule "Calculate coupon with fixed amount" from commerce coupon and messed around with it. My rule now checks that "Order contains a particular product" to make sure the discounted product is there.
Later I use "Fetch entity by property" to get the line item that has the Product referenced in the coupon. The coupon itself has a Product Reference field in it. The Action is set up as follows:
Entity type - Commerce Line Item
Property - Product
Value - coupon:field-prod
Variable name - discount_line_item
If you're nor familiar with commerce_coupon then in essence I have an entity which has a reference field in it. The rule gets a complete "Order" which contains line items. These line item entities contain an reference to the same Product type as my Coupon. What I'm trying to do is get the "Line Item" entity that has the same "Product" as the "Coupon". Put simply, I'm trying to "Fetch entity by property" using a reference field.
I've tried using properties of the Product (e.g. field-prod:product-id instead of field-prod directly) but they didn't work, which is what I expected since the comparison is between the Product field and a product.
Later I'm using the retrieved line item to get it's quantity in order to multiply the discount. So if you order four Products the coupon will discount them all, effectively multiplying the discount amount by four.
I think this problem might be related to this issue.
I'm not so sure since I'm not getting an error. What I do get in my rules evaluation debug is:
* 10.148 ms Added the provided variable discount_line_item of type list [edit]
* 39.418 ms Unable to apply data selector discount-line-item:0:quantity: Missing data values.
The "Missing data values" error is from the step which uses the retrieved line item. I'm guessing that I've either misunderstood how Rules works or me "Fetch entity by property" is fetching nothing so index 0 in the returned list doesn't exist.
I hope all that makes sense and somebody can help.
Cheers.
Comment #2
lukusI have the same problem .. I think it might be because the referenced product ID isn't actually stored in a variable in the product display (node) - it's stored as an array, and the actual value is continued further down within its structure.
So, I'm stuck at the moment. Any advice appreciated.
Comment #3
valante commentedI'm having the same problem when trying to fetch a Line Item via the Product property. This is a bug, not a support request. It's either in Rules or in how the Line Item entity is exposed to them. I'm going to poke around--if I find something, I'll post it here.
Edited: Seems like the problem is in the Product Reference module, since it's the one responsible for adding the Product property to Line Item.
Comment #4
valante commentedBased on these issues:
- #1306106: Can't load nodes via a product reference in a rule
- #1093918: Improve entity property query support
- #1084426: Fetch Entity by property won't work for all properties
I've made the following changes to commerce/modules/product_reference/commerce_product_reference.module :
1. In line 990, fixed type "propery" to "property"
2. In line 994, changed from this:
unset($property['query callback']);To this:
$property['query callback'] = array();I admit I don't understand the full implications of the second change, but it solved the issue for me. Now looping over Line Items without problems. (Other than the ones I get when I try to Issue licenses for them, of course, but that's another issue . . .)
Comment #5
valante commentedAnother alternative that now works for me: completely deleting the "$property['query callback']" line. Whatever its default value is, apparently it's good enough.
Comment #6
klausiLooks like a commerce issue, nothing to review here.
Comment #7
mitchell commentedUpdated component.
Comment #8
tr commentedI'm not sure why this is still open - the conclusion was it was a bug in a Commerce-related module.