I try to create an order through the rules module (create entity > order). On execution this leads me always to this error:
Notice: Undefined index: uid in _commerce_order_create() (line 299 of .../modules/commerce/modules/order/commerce_order.module).
Here is the equivalent source code:
<?php
function _commerce_order_create($values = array()) {
// Create a new order owned by the specified user.
$order = commerce_order_new($values['uid']); // <- line 299
unset($values['uid']);
[...]
?>
The problem is that the $values['uid'] is not set and can not be set in the rules configuration form. The entity will not be created. The other thing, I think is strange here, is that the Order Id is required. For my opinion this should be optional (is set when the order is created). Or is this way to create an order with rules completely wrong?
Comments
Comment #1
rszrama commentedInteresting... I hadn't tried this yet. Several things do appear to need changing:
I'm sure we'll have similar problems with other entities...
Comment #2
rszrama commentedJust committed a patch solving #2 and #4 (it was the type property lacking a setter callback), and I've implemented a check on $values['uid'] to stop #3 from giving the PHP notice. The problem, though, was that I'm actually not being passed any of the action's settings, so I don't get any order status or owner information passed to the creation function. However, it still seems to be setting the uid properly since I'm using a separate setter callback - I tested this by setting it explicitly to user 2 and also using the data selector for site:current-user (I was logged in as user 1) and it worked fine.
I guess that really leaves figuring out how to hide the Order Number field and also how to get the Order E-mail field to show up as editable / selectable.
Comment #3
hunziker commentedrszrama thank you for your work on this. I think this module becomes one of the greatest Drupal 7 modules.
I have apply your changes from the last commit. The creation of new orders works now. But as you mentioned above the problem exists also on other entities (line-items).
I build a good test case. I try to implement a cloning mechanism for orders in Rules. Here is my test case:
If this works we covered all features that should be available. Because all fields need to be read and written in the test case. Perhaps we can build up on this a new test case. The following list covers the errors which blocks the cloning of the order:
Additionally there exists another error in the above use case. It is not possible to provide the new order to other rules. But this is a rules error. So I will post it in there issue queue.
Comment #4
derekw commentedSubscribing, I just got to this point.
Comment #5
derekw commentedAre orders appearing in the commerce_orders table with your action?
This is not resulting in any order for me:
Create a new entity
Parameter: Entity type: Order, Order number:0, Status: Shopping cart, Type: Order, Owner:0
Provides variables: Created order (commerce_order)
Save entity
Parameter: Entity: [order-created], Force saving immediately: true
Comment #6
hunziker commentedThe order appears in my test in the list, but there are other problems. So actually it does not work.
Comment #7
derekw commentedYes if I skip adding line items the order does get entered into the database.
Comment #8
rszrama commentedJust updating to confirm that yes, orders will be created and show up in your Orders View (assuming you set the status to a non-shopping cart status like Pending). Additionally, the remaining issues I point to in comment #2 above still remain.
I've imported hunziker's component, and it actually doesn't error out for me if I execute it - it just seems to ignore the line item cloning altogether. It clones the base order object fine, but that's it.
I'll mark this for review at the Commerce Camp sprint if I don't get back to it before then. In the meantime, I'd just recommend doing this in code instead of trying to construct it with Rules if it's mission critical for your site. You can always back the cloning functionality into a custom Rules action.
Comment #9
rszrama commentedWhoops, meant to update the title, since the original issue pertaining to Orders explicitly have mostly been resolved.
Comment #10
rszrama commentedCan anyone confirm the problems on the latest versions of Entity API and Rules?
Comment #11
videographics commentedI've come across a number of problems related to setting a data value on reference fields that refer to Commerce Order entities that seem like the might be related to this issue.
I've tried setting the value of fields that are supposed to take an entity as a value but when I try to use a Commerce Order as a value, I get:
This happens with the Relation module (http://drupal.org/project/relation) and also with Entity Reference module.
The Relation module IS able to create the relation using the "Entity Collector" (but that's really awkward and only really practical for testing) and I AM able to reference the orders using Entity Reference field on the edit page of the node as well.
This is with commerce 7.x-1.0, rules 7.x-2.0, entity 7.x-1.0-beta11. I'm going to undertake testing all this with dev versions in the next day or so. Can someone tell me if they think the dev versions might address this?
Comment #12
videographics commentedSO sorry. My issues seem to be related to trying to insert a single entity into a variable where rules is expecting a list. You can pretty much ignore everything I've been saying. (gulp)
Comment #13
rszrama commentedNo worries, it's good to get that confirmation.
Comment #14
videographics commentedActually, the array/single value issue only resolved problems with the node reference and entity reference modules. (This actually gets me what I need for my current application.) But, I'm still having trouble with Rules creating Relations between nodes and Order entities.
Comment #15
rszrama commented