⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 check_options.tpl

📁 NetGou商城购物系统是一款功能强大完善、操作界面友好、可扩展性好、专门针对个人和企业进行网上销售而开发的一套商城购物系统。 它具有完善的商品管理、订单管理、销售统计、新闻管理、结算系统、税率系统、
💻 TPL
字号:
{* $Id: check_options.tpl,v 1.11.2.9 2004/09/10 09:54:24 max Exp $ *}

var variants = new Array();
{if $variants ne ''}
{foreach from=$variants item=v key=k}
variants[{$k}] = new Array();
variants[{$k}][0] = new Array('{$v.taxed_price}', '{$v.avail}', '{if $v.is_thumbnail eq 'Y'}{$v.variantid}{/if}', '{$v.weight}');
variants[{$k}][1] = new Array();
{if $v.options ne ''}
{foreach from=$v.options item=o}
variants[{$k}][1][{$o.classid}] = {$o.optionid};
{/foreach}
{/if}
variants[{$k}][2] = new Array();
{if $v.taxes ne ''}
{foreach from=$v.taxes item=t key=id}
variants[{$k}][2][{$id}] = {$t|default:0};
{/foreach}
{/if}
{/foreach}
{/if}

var modifiers = new Array();
{assign var="cnt" value=0}
{foreach from=$product_options item=v key=k}
{if $v.is_modifier eq 'Y'}
modifiers[{$v.classid}] = new Array(); 
{foreach from=$v.options item=o}
modifiers[{$v.classid}][{$o.optionid}] = new Array({$o.price_modifier|default:"0.00"}, '{$o.modifier_type|default:"$"}');
modifiers[{$v.classid}][{$o.optionid}][2] = new Array();
{foreach from=$o.taxes item=t key=id}
modifiers[{$v.classid}][{$o.optionid}][2][{$id}] = {$t|default:0};
{/foreach}
{/foreach}
{/if}
{/foreach}

var taxes = new Array();
{if $product.taxes}
{foreach from=$product.taxes key=tax_name item=tax}
{if $tax.display_including_tax eq "Y" && ($tax.display_info eq 'A' || $tax.display_info eq 'V')}
taxes[{$tax.taxid}] = {$tax.tax_value|default:0};
{/if}
{/foreach}
{/if}

var exceptions = new Array();
{if $product_options_ex ne ''}
{foreach from=$product_options_ex item=v key=k}
exceptions[{$k}] = new Array();
{foreach from=$v item=o}
exceptions[{$k}][{$o.classid}] = {$o.optionid};
{/foreach} 
{/foreach} 
{/if}

var product_wholesale = new Array();
{if $product_wholesale ne ''}
{foreach from=$product_wholesale item=v key=k}
product_wholesale[{$k}] = new Array({$v.quantity|default:0},{$v.next_quantity|default:0},{$v.taxed_price|default:$product.taxed_price});
{/foreach}
{/if}

var exception_msg = "{$lng.txt_exception_warning|replace:"\n":"<BR>"|replace:"\r":" "|replace:'"':'\"'}!";
var txt_out_of_stock = "{$lng.txt_out_of_stock|replace:"\n":"<BR>"|replace:"\r":" "|replace:'"':'\"'}";
var pconf_price = {$taxed_total_cost|default:0}
var default_price = {$product.taxed_price|default:"0"};
var currency_symbol = "{$config.General.currency_symbol}";
var alter_currency_symbol = "{$config.General.alter_currency_symbol}";
var alter_currency_rate = {$config.General.alter_currency_rate|default:"0"};
var image_dir = "{if $full_url}{$http_location}{else}{$NetGou_web_dir}{/if}/image.php?productid={$productid}&variantid=";
var txt_no = '{$lng.txt_no}';
var list_price = {$product.list_price|default:0};
var price = 0;

{literal}
function check_options() {
var x, cnt, flag, c, t, select_avail;
var local_taxes = new Array();

	for(t in taxes)
		local_taxes[t] = taxes[t];
	price = default_price;

	// Find variant
	for(x = 0; x < variants.length; x++) {
		flag = true;
		for(c in variants[x][1])
			if(document.getElementById('po'+c).value != variants[x][1][c]) {
				flag = false;
				break;
			}
		if(flag) {
			price = parseFloat(variants[x][0][0]);
			avail = parseFloat(variants[x][0][1]);
			for(t in local_taxes)
				if(variants[x][0][2][t])
					local_taxes[t] = parseFloat(variants[x][0][2][t]);
			if(variants[x][0][2] != '' && document.getElementById('product_thumbnail'))
				document.getElementById('product_thumbnail').src = image_dir+variants[x][0][2];
			if(document.getElementById('product_weight'))
				document.getElementById('product_weight').innerHTML = variants[x][0][3];
			break;
		}
	}

	if(pconf_price > 0)
		price = pconf_price;

	// Find modifiers
	for(x in modifiers) {
		if(document.getElementById('po'+x).value) {
			if(modifiers[x][document.getElementById('po'+x).value]) {
				price += parseFloat(modifiers[x][document.getElementById('po'+x).value][1] == '$'?modifiers[x][document.getElementById('po'+x).value][0]:(price*modifiers[x][document.getElementById('po'+x).value][0]/100));
				for(t in local_taxes)
					if(modifiers[x][document.getElementById('po'+x).value][2][t])
						local_taxes[t] = parseFloat(local_taxes[t])+parseFloat(modifiers[x][document.getElementById('po'+x).value][2][t]);
			}
		}
	}

	// Update taxes
	for(t in local_taxes)
		if(document.getElementById('tax_'+t))
			document.getElementById('tax_'+t).innerHTML = currency_symbol+price_format(local_taxes[t], 2);

	// Update form elements (price & quantity & save percent)
	if(document.getElementById('product_price'))
		document.getElementById('product_price').innerHTML = currency_symbol+price_format(price, 2);
	if(alter_currency_rate > 0 && alter_currency_symbol != "" && document.getElementById('product_alt_price'))
		document.getElementById('product_alt_price').innerHTML = "("+alter_currency_symbol+" "+price_format(price*alter_currency_rate, 2)+")";
	if(document.getElementById('save_percent') && list_price > 0) {
		if(price < list_price)
			document.getElementById('save_percent').innerHTML = Math.round(100-(price/list_price)*100);
		else
			document.getElementById('save_percent').innerHTML = '0';
	}

	if(document.getElementById('product_avail_txt'))
		document.getElementById('product_avail_txt').innerHTML = ((avail > 0)?(flag?avail:product_avail):txt_no);
	select_avail = min_avail;
	if(document.getElementById('product_avail')) {
		if(document.getElementById('product_avail').options) {
			if(!isNaN(min_avail) && !isNaN(avail)) {
				if((avail-min_avail+1) != document.getElementById('product_avail').options.length) {
					while(document.getElementById('product_avail').options.length > 0)
						document.getElementById('product_avail').options[0] = null;
					cnt = 0;
					for(x = min_avail; x <= avail; x++)
						document.getElementById('product_avail').options[cnt++] = new Option(x, x);
					if(document.getElementById('product_avail').options.length == 0)
						document.getElementById('product_avail').options[0] = new Option(txt_out_of_stock, 0);
				}
			}
		}
		select_avail = document.getElementById('product_avail').options[document.getElementById('product_avail').selectedIndex].value;
	}

	check_wholesale(select_avail);

	if((alert_msg == 'Y') && (min_avail > avail))
		alert(txt_out_of_stock);
	
	// Check exceptions
	if(!check_exceptions() && (alert_msg == 'Y'))
		alert(exception_msg);
			
	if(document.getElementById('exception_msg'))
		document.getElementById('exception_msg').innerHTML = (check_exceptions()?'':exception_msg+"<BR><BR>");

	return true;
}

function check_exceptions() {
var x, cnt;

	for(x in exceptions) {
        flag = true;
        for(c in exceptions[x])
            if(document.getElementById('po'+c).value != exceptions[x][c]) {
                flag = false;
                break;
            }
		if(flag)
			return false;
	}
	return true;
}

function price_format(price, precision) {
var x, cnt, top, botom;
	precision = Math.pow(10, precision);
	price = Math.round(price*precision)/precision;
	top = Math.floor(price);
	bottom = Math.round((price-top)*precision)+precision;
	top = top+"";
	bottom = bottom+"";
	cnt = 0;
	for(x = top.length; x >= 0; x--) {
		if(cnt%3 == 0 && cnt > 0 && x > 0)
			top = top.substr(0,x)+","+top.substr(x,top.length);
		cnt++;
	}
	price = top+"."+bottom.substr(1,bottom.length);
	return price;
}

function product_option(classid) {
	return document.getElementById(classid);
}

function check_wholesale(qty) {
var x, wl_price;
	if(product_wholesale.length == 0)
		return true;
	
	wl_price = price;
	for(x = 0; x < product_wholesale.length; x++) {
		if(product_wholesale[x][0] <= qty && (product_wholesale[x][1] > qty || product_wholesale[x][1] == 0))
			wl_price = product_wholesale[x][2];
		if(document.getElementById('wp'+x))
			document.getElementById('wp'+x).innerHTML = currency_symbol+price_format(price-default_price+product_wholesale[x][2], 2);
	}
	if(document.getElementById('product_price'))
		document.getElementById('product_price').innerHTML = currency_symbol+price_format(price-default_price+wl_price, 2);

	return true;
}
{/literal}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -