Hello!

there's something wrong with the way the uc_order_node_save function creates the 'empty' node. If the assigned content type contains a cck datetime field with default value set to NULL (empty), there are many warnings for this field when the node is created. The datetime field value in database is '0000-00-00 00:00:00', but it has to be NULL. When creating the order node manually via node/add the database value is NULL.

Why don't you use the node_save function?

Regards,
root66

Comments

m.stenta’s picture

Hmm. I'll have to look into this.

In the latest release I changed from using node_save() to using drupal_execute() so that all node defaults would be respected (see issue #1198556: default field value not being set). This is because drupal_execute() is basically the same thing as clicking "Save" in the node form itself. Using node_save(), on the other hand, doesn't automatically load default values into the $node object... they need to be provided by the module before passing it to node_save().

I did some quick research and found this: http://redfinsolutions.com/blog/using-drupalexecute-vs-nodesave

I haven't parsed through it completely, but it seems to give an overview of the difference between drupal_execute() and node_save(), and also mentions that the Date module has some issues with drupal_execute(), which is probably what's causing this problem. There are some links there to specific issues, including:

#258572: drupal_execute date field populated from array
#258432: drupal_execute

And a similar issue posted by someone else:

http://drupal.org/node/554686

I'll dig in deeper when I have some time... until then feel free to look through it. Any suggestions are welcome!

Thanks for the bug report.

scotwith1t’s picture

Shoot...kinda counting on this module for a project...and a date field is critical to the functionality. Basically, a user sings up for an event, pays for it, once the event has passed, I need to associate a date that a certificate was sent to the user and this seemed to be the best approach and a good module...except the date bug! Any suggestions for working around or do I need to scrape together some $$ to sponsor this fix? It's huge for this project...unless you can think of another way to do this without your module, but I was loving the idea of it...

m.stenta’s picture

Assigned: Unassigned » m.stenta
Priority: Normal » Major

I actually just upped the priority of this issue for one of my own projects. I don't need it immediately, though, so no gaurantees it will be fixed right away. I'm heading to DrupalCon all next week, too. What's your project timeline looking like? "ASAP" I assume? :-)

I've been doing more research, and it's a very tough issue. To put it simply: if we want to be able to use default values and validation on order node fields, we need to use drupal_execute(). If we want to be able to use Date fields, we need to use node_save().

I'm wondering if maybe uc_order_node should just implement both options, and provide settings to choose which method you want to use... depending on what kind of fields you have. Not sure if this would be possible... I'd have to check how easy it is to provide a node_save() option again with the new code structure.

But even so, that wouldn't help the people who need default values AND Date fields (like me).

KarenS, the maintainer of the Date module, has made it pretty clear that she does not recommend using drupal_execute() with Date fields, because the Date module does some funky stuff with the way it structures it's fields. Unfortunately, I haven't come across any recommended ways of performing node validation or filling in default field values when using node_save(). Sigh.

Here are some of the other issues I've been reading through (see my first comment for more). Let me know if you notice anything I may have missed:

#799744: Validation error with drupal_execute()
#1243558: Use node_save() instead of drupal_form_submit() or drupal_execute()

And some other discussions:

node_save($node) vs drupal_execute('mycontenttype_node_form', $form_state, $node)
Problem with dates in drupal_execute

m.stenta’s picture

Here's another issue I found, and specifically a comment that suggests how to use node_save() and maintain default values:

http://drupal.org/node/293663#comment-1152690

Unfortunately, it also doesn't deal with Date fields. AND it doesn't perform validation.

septianw’s picture

Version: 6.x-1.x-dev » 6.x-1.0-beta4

warning: Parameter 2 to drupal_retrieve_form() expected to be a reference, value given in /...../sites/default/modules/uc_order_node/uc_order_node.module on line 152.

i got this error when reviewing order.
is it normal? any workaround of this?

scotwith1t’s picture

Version: 6.x-1.0-beta4 » 6.x-1.x-dev

Please don't hijack existing issues. Your report has nothing to do with datefields as the OP and further replies did/do. Please create a separate issue for your problem. If this is indeed related, you haven't made that link apparent with your comment. Thx.

m.stenta’s picture

Thanks for keeping an eye out @scot.self, but I actually think that @septianw's post is relevant to this issue. That is a common warning reported by others who are trying to use date cck fields with drupal_execute(). I think there are two problems that result from the same issue: one deals with generating the date field automatically in the background (when an order node is created during checkout), and one when you are trying to save the form manually (in the order admin interface). @septianw's issue is with saving the form manually.

This is a really tricky issue, and I'm not sure if anyone in the community has come up with a good solution for it. The best I've heard is something to the effect of "you need to do a bunch of tricky stuff to format the values so that the date module can use them properly." The worst I've heard is, "good luck."

I'd really love to find a solution for this, but I'm stretched between numerous projects right now, and it's not the highest priority. If you (or anyone else) can do some research and see if anyone has come up with a solution, perhaps we can speed this along.

Good luck! ;-)

scotwith1t’s picture

My fault, it just didn't seem relevant and no info in the message linked it to this issue for me. Shows what I know about these API functions! :) Anyway, I wish I could help, and if it comes to it I will enlist a friend to look at it with me that's php-savvy, but I can't really help here. Thanks for keeping an eye on it and please update us if you come up with a fix! Thx.

m.stenta’s picture

Note to self: look at the term_fields module. Maybe that will give us some insight about how to approach this issue.

jvieille’s picture

Issue summary: View changes

drupal_execute works erratically for me, using only text fields.
https://www.drupal.org/project/uc_order_node/issues/2419931

replaced by node_save, which does not seem to have any issue with default values.