Hey Guys, been searching high and low on how to do this but cant seem to find what I need. What I need to do is get the value from 1 field in a specific node, say node 20. Then need to make that value a variable that can be accessed by all nodes of a specific node type.
To elaborate on what Im trying to do:
The site Im doing sells silver. There are many silver products but all pricing is based off market value. Im using Ubercart as well as a module called custom pricing. Since all prices are based on market value we do not want to have to update the price of every individual product. So I created a node called "Current Market Price" and in there is a custom field for the market value called "field_market_price".
This is the only node that will exist for this node type. Its only there for people to update this single fields value which is the market price of silver.
Now I need to take that value and send it to my all my product nodes so all the products can use this value as a price.
In theory I guess what Im trying to do is something like:
(this is just a pseudo code example)
IN TEMPLATE.PHP
<?php function mytheme_preprocess_page(&$vars) {
// GET FIELD VALUE FROM NODE ID 20
$vars['marketprice'] = $nid->20->field_market_price[0]['value'];
return $vars;
} ?>
IN NODE-PRODUCT.TPL.PHP
<?php print $marketprice; ?>
I hope this makes sense but if more info is needed please just let me know.
Thanks!
Comments
Cant you...
...Just use a $SESSION variable ?
You could probably use the
You could probably use the Computed Field module, that would compute the price of each node as a CCK field on the fly. Not sure how well this would integrate with UC, but I think it would.
Thanks guys, As for sessions,
Thanks guys, As for sessions, I guess I could that but I still need to figure out how to get the data from a field in a specific node.
I took a look at the Computed fields module. Looks like a great module. Im definitely going to play around with this but in this scenario since Im using Ubercart the added module "custom pricing" is whats going to be doing these price calculations for me.
But what I need figure out is how to get the value from the specific field in a specific node to pass over to my "custom pricing" module so it can do the calculation.
I guess really what Im trying to figure out is how I can pull the value from field_xyz in node 20 and make it into a variable to be accessible in my other nodes or even anywhere in my site.
I know how to create a variable, just cant seem to pull that value from the specific field in the specific node.
Thanks!
Maybe
http://api.drupal.org/api/function/variable_set/6
Well I think I might be
Well I think I might be headed in the right direction. I found this node_load() thing and it might be what Im looking for. My actual node id Im trying to get is 28.
I got this, still not working but would like to know if you can see what Im trying to accomplish and how maybe I can rewrite so it works:
As I said its still not working but any ideas on how to make this work would be great!
Thanks!
Finally got it, I forgot to
Finally got it, I forgot to apply the fist variable. The code above should be:
function mytheme_preprocess(&$vars) {
// Get my specific node
$get_marketprice_node = node_load(28);
// Get my value from a specific field
$get_marketprice_value = $get_marketprice_node->field_market_price['0']['value'];
// Make available to the rest of my site
$vars['marketprice'] = $get_marketprice_value;
}
And it works!
Well, I guess this is how you can take a value from a specific node and make it available site wide. Maybe this may help someone else.
That fine if you just want to
That is fine if you just want to use the variable for display. But if your going to actually do anything with it (like using the value in ubercart), this may not be sufficient. (I'm no ubercart expert, so tell me if I'm wrong)
Hey mtsansford, Im no
Hey mtsansford, Im no ubercart expert either. Im not even a drupal expert. And yes, at the moment I can not get that variable to tie into ubercart but nothing is impossible so I figure I got to keep on keeping on since theres no current module to do what I want.
But Ill definitely keep this post updated with results. Im posting in the ubercart forum now. They may even have an alternative solution to what Im trying to do. Either way Ill keep ya posted.
Cheers!