--- uc_aac.orig 2008-01-13 01:26:44.000000000 -0600 +++ uc_aac.module 2008-01-13 02:58:29.000000000 -0600 @@ -49,7 +49,7 @@ function uc_aac_form_alter($form_id, &$f function _uc_aac_alter_form($field_id, $nid) { $correct_token = drupal_get_token($field_id); - $result = db_query('select sell_price from {uc_products} where nid=%d', $nid); + $result = db_query('SELECT sell_price FROM {uc_products} WHERE nid=%d AND vid=(SELECT vid FROM {node_revisions} WHERE nid=%d ORDER BY timestamp DESC LIMIT 1)', $nid, $nid); $price = 0; if ($product = db_fetch_object($result)) { $price = $product->sell_price; @@ -111,6 +111,44 @@ function _uc_aac_alter_form($field_id, $ $content .= ' $(fakeForm).ajaxSubmit( { success: function(html_result) { + while (html_result.indexOf("[")>-1) { + var spos = html_result.indexOf("["); + var epos = html_result.indexOf("]"); + var attr = html_result.substring(spos+1, epos-spos); + html_result = html_result.substring(epos+1); + var opts = attr.split("|"); + var el = false; + for (i=0; isell_price; } $attributes = $field_values['attributes']; if ($attributes) { foreach ($attributes as $attr) { - $result = db_query('select price from {uc_product_options} WHERE nid = %d AND oid = %d', $field_values['uccp']['nid'], $attr); - if ($adjustment = db_fetch_object($result)) { - $price += $adjustment->price; + $res = db_query('SELECT aid FROM {uc_attribute_options} WHERE oid = %d', $attr); + if ($aid = db_result($res)) { + $res = db_query('SELECT DISTINCT upo.oid, uao.name, upo.cost, upo.price FROM {uc_attribute_options} AS uao JOIN {uc_product_options} AS upo ON uao.oid = upo.oid WHERE uao.aid = %d AND upo.nid = %d', $aid, $nid); + $names = array(); + $prices = array(); + while ($obj = db_fetch_object($res)) { + $names[$obj->oid] = $obj->name; + $prices[$obj->oid] = $obj->price; + if ($obj->oid==$attr) { + $price += $obj->price; + } + } + $baseprice = $prices[$attr]; + print "[attr:$aid|"; + foreach ($prices as $oid=>$aprice) { + $adjprice = $aprice - $baseprice; + $text = $names[$oid]; + if ($adjprice!=0) { + $text .= ", "; + if ($adjprice>0) { + $text .= "+"; + } + $text .= uc_currency_format($adjprice); + } + print "{$oid}:{$text}|"; + } + print "]"; } } } $ret = uc_currency_format($price); - print( $ret ); + print $ret; } }