When an order is submitted and processed I need to be able to write values back to the related node to flag it as complete so I can create meaningful views of ordered products..
I followed this guide and it worked perfectly for passing the Order ID and Payment Status back to the node. I am having problems passing the value of the selected product attributes back to the node however. I have a textfield setup called Passed Attributes in my content type, but I think my call to the attributes is wrong.
Using conditional attributes, as documented above I am using this code to update the node on checkout:
if (isset($order)) {
foreach ($order->products as $product) {
if (isset($product->data['node_checkout_nid'])) {
$node = node_load($product->data['node_checkout_nid']);
$node->field_status['0']['value'] = 1;
$node->field_orderid['0']['value'] = $order->order_id;
node_save($node);
}
}
}
I i need to pass the attributes back too so am I looking for something like:
$node->field_orderid['0']['value'] = $order->attributes ?
Thanks,
Gary
Comments
Comment #1
garyh CreditAttribution: garyh commentedSorry I forgot to say what guide I followed for the above, it was this: http://drupaleasy.com/blogs/ultimike/2009/03/event-registration-ubercart
Comment #2
anni CreditAttribution: anni commentedI need this too!
Anyone an idea?
Comment #3
Train CreditAttribution: Train commentedIf you were still wondering how to access the attributes (as I was), I figured it out...
Using the code above, you would access the attributes as such:
In this case I have an attribute I called "Level."
'attributes' is an array of arrays within the 'product' object that holds the data for your assigned attributes. You can write yourself a Conditional Action to print_r the 'orders' object after checkout (using the link in comment #1) to see how to access the attributes.
Hopefully somebody with the same issue will find this helpful.
Comment #4
epop CreditAttribution: epop commentedSo how do I pass the ordered attribute to a node field? For example the status field becomes 1. Id like a field in my node to contain the the ordered attribute.
Comment #5
Train CreditAttribution: Train commentedThis bit of code does it for me:
Load the node via node_load(), set the value of your field to what you want, save the node via node_save().
Comment #6
paulwedge CreditAttribution: paulwedge commentedFor some strange reason the instructions provided in http://drupaleasy.com/blogs/ultimike/2009/03/event-registration-ubercart are not working for me.
I have followed the exact instructions - however when I include a dsm($node) or dsm($product) in the PHP code, they return blank.
Also when I go back to my product and click the 'Devel' tab, the 'data' string contains the following characters: a:1:{s:13:"form_build_id";s:37:"form-3ccc03345f4832c69666a89c560de940";}
Does anybody have a suggestion on what might be going wrong?
Thanks!
Comment #7
dallasw1983 CreditAttribution: dallasw1983 commentedFor anyone still looking on how to pass the ordered attributes to the node, I was able to do it.
I'm new at PHP so there might be a better way of doing this, but it works. :D
Here are the steps I took in order to get the results.
1. Go to Home » Administer » Store administration » Conditional Actions
In your Actions tab for the 'Action: Execute custom PHP code' first use this code:
2. Make a node of the product that you want to get the attributes for and select all the attributes, you will get an output of $order with all the data related to $order, find the part that has the attributes. It will look something like this:
If some of the attributes are not selected, then the away will look something like this:
3. Copy the PHP data from the array and put it into the code you need using the snippet from below. Next, go back to Home » Administer » Store administration » Conditional Actions > Actions tab
Put in the code after you've made changes to it.
4. Order another node product and your attributes will be in the CCK fields on the node!
A note, in the array for the attributes in $order, the attributes won't always be in order from [0] to [3] if all the attributes are not selected.
Alright, hope this helps out any one that needed it! If you have any questions, I'll try to answer with my overwhelming PHP experience! lol
Dallas
Comment #8
aidanlis CreditAttribution: aidanlis commentedSome sort of basic functionality should come with uc_node_checkout to achieve this, and also some documentation about extending this for other fields needs to be written.
Comment #9
aidanlis CreditAttribution: aidanlis commentedThis is done, available in the latest -dev release.
Comment #10
bombjack CreditAttribution: bombjack commentedApologies for reopening this so soon after the beta8 release, but this fix appears to have changed the behaviour causing me an issue.
I too have been following the guide mentioned in post 1 & 6, with some minor additions to the php code called in the 'conditional actions' section, intending to save some additional fields, only I found the data wasn't being stored. I checked and confirmed that the node was being updated with drupal_set_message debug dumps showing the nodes' content after the call to the node_save function
After much searching, trial and lots of errors, I finally reverted to the beta7 version to find that the functionality worked as expected.
Having looked through the change log it made more sense to me why the Product ID, Order ID and Status where the only items to be saved, being as this was new functionality recently added. I think this might be the source of the problem blocking the saving of the node in my case.
I am still reasonably new to Drupal and have yet to get my head around tracing back through function calls sufficiently to understand exactly what is going on, but it appears to me that at the point at which the php code assigned to the conditional action is executed, node checkout may have a copy of the node, which it duly intends to update with the Product ID, Order ID and Status as per the recent update, only when it saves these details it overwrites the node, thereby deleting the additional data that I am attempting to store.
Whilst I appreciate the desire to make it easy to map data to fields through the GUI it would be nice to be able to maintain the ability and flexibility of storing other details too. I hope it might be possible to have the best of both worlds unless the behaviour I am reporting was intentional for reasons I am unaware of.
Being as this is my first ever bug report post, I hope reopening this issue is the most appropriate way to have gone about it. It does seem closely associated!
Craig.
Comment #11
stellrex CreditAttribution: stellrex commentedIt seems as though I'm unable to update the status field, even after following the suggestions above and from the drupal easy article. I have a cck field called "field_status", and I've chosen it as the Status field in the node checkout settings. When an order completes, the status does not change from 0 .
I've also tried adding the conditional actions per the drupal easy article, and the status never changes from 0 to 1. Does anyone have any insight here? I've spent a couple hours trying to figure this out with no success. Below is the code I added per the article:
if (isset($order)) {
foreach ($order->products as $product) {
if (isset($product->data['node_checkout_nid'])) {
$node = node_load($product->data['node_checkout_nid']);
$node->field_status['0']['value'] = 1;
$node->field_orderid['0']['value'] = $order->order_id;
node_save($node);
}
}
}
Comment #12
aidanlis CreditAttribution: aidanlis commented@stellrex stop trying to use an integer field to store a string?
@bombjack bummer, I will open a new bug for you.
Comment #13
aidanlis CreditAttribution: aidanlis commentedNew issue here: #1165128: update_content_fields overwrites changes from conditional actions
Comment #15
guntherdevisch CreditAttribution: guntherdevisch commented@stellrex & @aidanlis: Do have a solution to store the status?
If have the code below for my CA, but the status isn't saved for $node->status AND $node->field_status['0']['value']. Before this was no problem, but recently this doesn't work anymore. I think by updating the module 'uc_node_checkout' to 6.x-2.0-beta8.
Thanks in advance,
Gunther
Comment #16
lyy9981 CreditAttribution: lyy9981 commentedI had the same problem as @bombjack and @guntherdevisch pointed out. @bombjack explained very well what caused the problem, I solved it by reverting to the beta7 version.