I have some very advanced pricing and I'd love to just add a few cck fields on to my Product content types and then use this module to reference those cck fields. I can't seem to be able to reference node fields within this module's Custom Price Calculation area with

global $node
$node->contentfield

Any tips?

Comments

illepic’s picture

Hrm. Well, the following loads my node, as it should:

$node = node_load($item->nid);

And now I have a node object to play with. Is there a more efficient way to do this?

tamasco’s picture

Hello Chris,

I want to have item price take the value of a cck field attached to the product content type. Is this the same thing the code you provided does? Also, I don't quite understand how to use the your code. Do I substitute "$node" with the machine readable name of the node and "nid" with the node id? Forgive my ignorance.

Kind regards,
Tamasco.

AlexanderPop’s picture

I 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

chesketh’s picture

I've solved this problem. The issue is that I did not know how to extract the node ID associated with each cart item. Luckily print_r($item) in the custom price field provided the information. Here is my code to calculate the price of an item based on the number of days in the from and to dates of a CCK date field.

$nid=$item->data[node_checkout_nid];
$node=node_load($nid);
$numseconds=strtotime($node->field_when[0][value2])-strtotime($node->field_when[0][value]);
$numdays=ceil($numseconds/86400);
$item->price = 3*$numdays;

The $item object contains each item in the shopping cart as an object.

frankspin’s picture

I can't get this working guys. I need some help.

I have a cck field named: field_korting5
The field type is integer

$item->data['node_checkout_nid'];
$node = node_load($item->data['node_checkout_nid']);     
$item->price = $item->price * $node->field_korting5[0]['value'];

I'm always getting the value of 0,00 in my product price

skyesong’s picture

This thread is finally what put me on the right track. I had to change one line of my custom price calculation to:

$numseconds=strtotime($item->data['attributes_cck']['field_dates'][0]['value2'])-strtotime($item->data['attributes_cck']['field_dates'][0]['value']);

I'm a self-taught newb and I've just spent the last two days figuring this out, so I hope this helps somebody else.

For the record, I'm using uc_attribute_cck in order for the dates to be selectable as product attributes.

TR’s picture

Status: Active » Fixed

Yes, you can use a CCK field value in the custom price calculation. The first thing you have to do is load the entire node. CCK field data is attached to the node, but the $item variable stored in the cart does NOT have all the node data - it only has the data normally needed by Ubercart. That's the purpose of the first line below. The second line is just for debugging purposes - this will let you see all the variables that are attached to the node and identify the exact place your CCK data is stored. Remove the second line after you have your custom price calculation working. The third line is the line that calculates the price. You can do whatever you want here. For my example, I just created a numeric CCK field with a machine name of 'field_markup', and my product price is simply the product sell_price (set on the product edit page, /node/%/edit) plus the value of the 'field_markup' (also set on the product edit page, in the CCK field that you created for 'field_markup').

Custom Price Code:

$node = node_load($item->nid);
drupal_set_message('<pre>' . var_export($node, TRUE) . '</pre>');
$item->price = $item->price + $node->field_markup[0]['value'];

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.