[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
Re: [ic] Using order groups for set price custom orders?
Quoting cfm@maine.com (cfm@maine.com):
> Alternatively you get more <wince>joy</wince> using minivend to build a
> javascript page dynamically according to what is available. I'd bet
> that is more what your client sees. :->
>
Is there anything that gives you more <wince>joy</wince> or less
<wince>joy</wince> doing that type of thing with JavaScript? I would
be happy to use anything anyone has learned about generating JavaScript
from Perl.
There are a couple of javascript examples in Interchange, by the way,
where we set the tables/columns for lists. Below is one for the upcoming
Foundation computer store demo. I guess it was <wince>joy</wince>
writing that one. (WARNING: the below will not be at all directly
useful to anyone. It is only an illustration of the type of thing that
can be done to build JavaScript do-hickies from the database. Also, the
[tree ...] tag doesn't exist until 4.7.x.)
<SCRIPT>
[comment]
Set the base info -- base price, item-code, etc.
[/comment]
var base_price = [price code="[scratch arg]" noformat=1];
var base_quantity = 1;
var price = new Array; var desc = new Array; var ptr = new Array; var k = 0; var j = -1;
[tree
prefix=tree
full=1
tolerate=1
master=o_master
log_error=1
sub=sku
sort=o_group
start="[scratch arg]"
table=options
][tree-sub do_js]
my $level = shift;
my $row = shift;
if( ! $level) {
#$k = 0;
#$j++;
$differential = $row->{differential} || 0;
return <<EOF;
k = 0; j++; desc[j] = new Array; price[j] = new Array; ptr[j] = '$row->{o_group}';
EOF
}
my $desc = $row->{description};
my $price = $row->{price} + $differential;
$desc =~ s/"/"/g;
if($price != 0) {
$desc .= " (";
$desc .= $Tag->currency($price);
$desc .= ")";
}
else {
# Make sure JS doesn't error out
$price = 0;
}
return <<EOF;
price[j][k] = "$price"; desc[j][k] = "$desc"; k++;
EOF
return $out;
[/tree-sub][tree-exec do_js][tree-param mv_level][/tree-exec][/tree]
function currency(amount) {
amount = amount.toString().replace(/\$|\,/g,'');
if (isNaN(amount)) {
amount = '0';
}
cents = Math.floor( (amount * 100 + 0.5 ) % 100);
amount = Math.floor(amount).toString();
if(cents < 10) cents = "0" + cents;
for (var i = 0; i < Math.floor ((amount.length - (1+i)) / 3); i++)
amount = amount.substring(0,amount.length-(4*i+3))+','+amount.substring(amount.length-(4*i+3));
return ('$' + amount + '.' + cents);
}
function update_quantity (form) {
found = 0;
for(i = 0; i < form.length; i++) {
if(form.elements[i].name == 'mv_order_quantity') {
if( found == 0 ) {
found++;
base_quantity = form.elements[i].value;
}
else {
form.elements[i].value = base_quantity;
}
}
}
return true;
}
function update_price (form) {
var total = base_price;
var debug = '';
var name;
for(i = 0; i < ptr.length; i++) {
curr = eval('form.' + ptr[i] + '.selectedIndex');
[comment]
debug = debug
+ "group=" + ptr[i]
+ " i=" + i
+ " curr=" + curr
+ " price=" + price[i][curr]
+ "\n";
[/comment]
total = eval(total + ' + ' + price[i][curr]);
}
total = eval(base_quantity + ' * ' + total );
form.current_price.value = currency(total);
return true;
}
</SCRIPT>
--
Akopia, Inc., 131 Willow Lane, Floor 2, Oxford, OH 45056
phone +1.513.523.7621 fax 7501 <heins@akopia.com>
Research is what I'm doing when I don't know what I'm doing.
-- Wernher Von Braun
_______________________________________________
Interchange-users mailing list
Interchange-users@lists.akopia.com
http://lists.akopia.com/mailman/listinfo/interchange-users