Closed (duplicate)
Project:
Ubercart Custom Price
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
9 Dec 2009 at 08:53 UTC
Updated:
28 Apr 2011 at 04:47 UTC
Hello.
I wish to take the price from cck field on the product page. $item->price = $node->field_fieldname['value']; Don't work.
Is it possible?
Comments
Comment #1
justclint commentedHey Guys, Im trying to do kind of the same thing. Basically the site sells silver. There are various products of different silver coins. The unique thing is that all the products have the same price(sort of). They all have a market value price.
When selling silver there is something called a premium. Kind of like when you exchange money, you dont actually get the real market value, you get charged for the change making the exchange as well.
So in our case for example, on one product we might say price = market value + $0.89(the premium) per ounce. If you buy 500 ounces (quantity of 1 = 100 pieces) or more its price = market value + $0.79.
So what Ive done is created a content type called "Current Market Value" and it has a field called "field_market_price." Ive created a single node of this content type to store the current market value.
In my template.php file Ive taken that value and turned into a variable called $marketprice to be available site wide.
For my products, the sell price in one example will be $0.89.
Id like my custom price field to do something like:
Comment #2
justclint commentedI just changed the title of this post.
Comment #3
WebNewCastle commentedI realize both of these posts were from a while ago, but in case its useful to either of you or someone else with a similar need ...
Both of these can be done.
Digital_fox, I've tied Custom Price functionality to CCK field values before. It is probably just a syntax issue. I could be wrong, but I think when CCK fields are printed there is usually another part to it. You can do a print_r on $node or $node->field_fieldname to be sure, but I think its usually more in the format of:
$node->field_fieldname[0]['value']
Justclint, you can do what you need, but perhaps skipping the template part. I could be wrong, but I don't know that having that defined and available for your template would necessary make it available for this module, Ubercart, the node, etc. Perhaps it does. But, instead you could just pull particular node's CCK field where it's being stored directly. Not only can Custom Price be tied to a CCK field in the node, it can be tied to a CCK field in any node. You can use node_load to load up the node in question and then have it pull from the specific CCK field. So you might have something similar to above with $reference_node-> and the rest and have $reference_node storing what you get from node_load.
There are some other options as well.
Instead of loading and referencing nodes, you could have store it in a variable (in your installation's variables table). You use variable_save and variable_get and make a custom module, or perhaps use Rules or maybe it would work to use Custom Field with your reference node to save all the values as variables.
Another approach would be to use Custom Field to grab the field(s) in the reference node - your Custom Field for a specific product class could have this code as the default. But, this one strikes me as not being the most efficient option.
Comment #4
AlexanderPop commentedI created CCK text field field_dynamic_price
than I used $item->price = $node->field_dynamic_price[0]['value'];
also tryed
$item->price = check_plain($node->field_dynamic_price[0]['value']);
just added 123 number in field_dynamic_price
and it doesn't work. when I add product to the cart prize becomes 0.00
what do I do wrong? please help
Comment #5
WebNewCastle commentedMaybe try wrapping it in "abs" or "int" instead?
Comment #6
AlexanderPop commented#WebNewCastle
thanks for post, but could you clarify, please? thanks again
Comment #7
chesketh commentedDid you first find the nid in question and call
and then call:
The hard part is pulling out the node id of the node created. I am currently pulling the last node id created by the person placing the order. This seems to work, but the new price is applied to all previous items of the same type in the cart.
Comment #8
AlexanderPop commentedgreat it started to work but only with static value in field_dynamic_price (like 123)
when I use php code in field_dynamic_price
somecodeit shows 0.00 again
Comment #9
chesketh commentedI've solved it, see this comment: http://drupal.org/node/559508#comment-3266432
Comment #10
AlexanderPop commentedsame
when I use php tags
and something between it it shows $00.0 after add to cartif just 333 (without php tag), for example - it shows $333.00 - so works well. but I need to use dynamic data which generates in $node->field_dynamic_price[0]['value']
tryed $item->price = check_plain($node->field_dynamic_price[0]['view']); - no lack...
we use on site custom module which generate data from dynamic datafile. so if I put somewhere in content this code:
calcvalue_getvalue(13, 10, 'XAU', .1)it shows 141.98 when rendering pageso I put
calcvalue_getvalue(13, 10, 'XAU', .1)code in field_dynamic_price field ("php" is input format of course) and I see number "141.98" when page is rendering, but $item->price = check_plain($node->field_dynamic_price[0]['value']); doesn't read this data...Comment #11
tr commentedDuplicate of #559508: Reference cck field. The question is answered over there.