= $config['promo_disc_min']))
{
if ($config['promo_disc_type'] == 'pct') $store['promo_disc'] = ($config['promo_disc_rate'] / 100) * $total;
if ($config['promo_disc_type'] == 'abs') $store['promo_disc'] = $config['promo_disc_rate'];
}
// conflict resolve
if (($config['promo_priority'] == 'voucher') && ($gift['value']) && ($store['promo_disc'])) $store['promo_disc'] = 0;
if (($config['promo_priority'] == 'store') && ($gift['value']) && ($store['promo_disc'])) $gift['value'] = 0;
$disc = array_merge ($gift, $store);
return $disc;
}
require './includes/user_init.php';
require './includes/ship.php';
require './includes/tax.php';
require './includes/pay.php';
// pre-fetch all options
$opt_def = array ();
$res = sql_query ("SELECT * FROM ".$db_prefix."cf_define WHERE as_prod_opt='1' ORDER BY field_order");
while ($row = sql_fetch_array ($res))
{
$opt_def[$row['field_id']]['title'] = $row['field_title'];
$opt_def[$row['field_id']]['help'] = $row['field_help'];
$opt_def[$row['field_id']]['type'] = $row['field_type'];
$opt_def[$row['field_id']]['option'] = $row['field_option'];
}
// close shop?
if ($config['close_site']) msg_die ('site_closed');
$step = get_param ('step');
$shipper = get_param ('shipper');
$payment = get_param ('payment');
$weight = get_param ('weight');
$total = get_param ('total');
$item = get_param ('item');
$order_notes = get_param ('order_notes');
if (($step > 4) || ($step < 1)) $step = 1;
switch ($step)
{
case 1:
$i = $item = $total = $total_weight = 0;
// get discount
$disc = get_coupon ();
if ($disc['gift_code'])
{
$coupon_exists = TRUE;
$txt['coupon_code'] = $disc['gift_code'];
}
else
{
$coupon_exists = FALSE;
$txt['coupon_code'] = '';
}
// -- loading template
$tpl = load_tpl ('checkout1.tpl');
$txt['block_checkout_item'] = '';
$sql = "SELECT p.*, o.qty, o.idx, o.opt_fee , o.opt_text
FROM ".$db_prefix."products AS p JOIN ".$db_prefix."orders AS o
USING (item_id) WHERE user_id = '$current_user_id' ORDER BY cat_id asc, title asc";
$res = sql_query ($sql);
while ($row = sql_fetch_array ($res))
{
$i++;
$item = $item + $row['qty'];
$cat_id = $row['cat_id'];
$item_id = $row['item_id'];
$price = $row['price'] + $row['opt_fee'];
$subtotal = $price * $row['qty'];
$total += ($row['price'] + $row['opt_fee']) * $row['qty'];
$total_weight += $row['weight'] * $row['qty'];
if ($config['enable_adp'] == 3) $row['item_id'] = create_seo_url ($row['item_id'], $row['title']);
$row['digital'] = $row['digital_prod'] ? $lang['l_digital_icon'] : '';
$row['x_option'] = stripslashes ($row['opt_text']);
$row['xe_price'] = get_xe_price ($row['price'], 'list');
$row['price'] = num_format ($price);
$row['price_msrp'] = num_format ($row['price_msrp']);
$row['xe_subtotal'] = get_xe_price ($subtotal, 'list');
$row['subtotal'] = num_format ($subtotal, 0, 1);
$row['subtotal_weight'] = $row['weight'] * $row['qty'];
$row['distro'] = get_distro ($row['distro']);
$row['image'] = make_thumb ($item_id.'_1', 'list');
$row['image_small'] = make_thumb ($item_id.'_1', 'small');
$txt['block_checkout_item'] .= quick_tpl ($tpl_block['checkout_item'], $row);
}
if ($i == 0) $txt['block_checkout_item'] = $lang['l_checkout_empty'];
$txt['xe_total'] = get_xe_price ($total, 'list');
$txt['total'] = num_format ($total, 0, 1);
$txt['item'] = $item;
$txt['total_num'] = $total;
$txt['total_weight'] = $total_weight;
$txt['main_body'] = quick_tpl ($tpl, $txt);
generate_html_header ("$config[site_name] $config[cat_separator] My Cart");
flush_tpl ();
break;
case 2:
// login?
$xpress = FALSE;
if (!$login)
{
// using xpress?
$res = sql_query ("SELECT * FROM ".$db_prefix."user WHERE user_id='$current_user_id' AND user_passwd='**xpress**' LIMIT 1");
$row = sql_fetch_array ($res);
$xpress = TRUE;
// no xpress & no login => redir
if (empty ($row))
{
ip_config_update ('redir', $config['site_url']."/checkout.php?step=2&weight=$weight&total=$total&item=$item");
redir ($config['site_url'].'/profile.php?xpress=1');
}
}
// -- checking cart (if no item, exit!)
$res = sql_query ("SELECT COUNT(*) AS items FROM ".$db_prefix."orders WHERE user_id = '$current_user_id'");
$row = sql_fetch_array ($res);
if (!$row['items']) msg_die ('NO_ITEM_IN_CART');
// billing address
$user = get_user_info ($current_user_id);
$user['bill_address'] = format_address ($user);
// shipping address
$res2 = sql_query ("SELECT * FROM ".$db_prefix."address WHERE user_id='$current_user_id' AND as_default='1' LIMIT 1");
$row2 = sql_fetch_array ($res2);
$user['ship_address'] = format_address ($row2);
// shippers
$tpl = load_tpl ('checkout2.tpl');
$txt['block_courier_item'] = ''; $i = 0;
$t = get_courier_fee ($current_user_id, $item, $total, $weight);
foreach ($t as $val)
{
$val['i'] = $i++;
if (empty ($val['fee']))
{
$val['xe_fee'] = '';
$val['fee'] = '('.$lang['l_courier_free'].')';
}
else
{
$val['xe_fee'] = get_xe_price ($val['fee'], 'list');
$val['fee'] = num_format ($val['fee'], 0, 1);
}
$txt['block_courier_item'] .= quick_tpl ($tpl_block['courier_item'], $val);
}
// payment
$txt['block_pay_item'] = ''; $i = 0;
$t = get_payment_method ();
foreach ($t as $val)
{
$val['i'] = $i++;
$txt['block_pay_item'] .= quick_tpl ($tpl_block['pay_item'], $val);
}
// display
$txt = array_merge ($txt, $user);
$txt['main_body'] = quick_tpl ($tpl, $txt);
generate_html_header ("$config[site_name] $config[cat_separator] Checkout 1/2");
flush_tpl ();
break;
case 3:
// login?
$xpress = FALSE;
$order_notes = safe_send ($order_notes);
if (!$login)
{
// using xpress?
$res = sql_query ("SELECT * FROM ".$db_prefix."user WHERE user_id='$current_user_id' AND user_passwd='**xpress**' LIMIT 1");
$row = sql_fetch_array ($res);
$xpress = TRUE;
// no xpress & no login => redir
if (empty ($row))
{
ip_config_update ('redir', safe_send($config['site_url'].'/checkout.php'));
redir ($config['site_url'].'/profile.php?xpress=1');
}
}
// ship method set?
$ship_test = explode ('_', $shipper);
$res = sql_query ("SELECT * FROM ".$db_prefix."shipping WHERE ship_method = '$ship_test[0]' AND ship_enable = '1' LIMIT 1");
$ship = sql_fetch_array ($res);
if (empty ($ship)) msg_die ('shipper_not_selected', '', -2);
$ship_name = $ship['ship_name'];
// payment method set?
$res = sql_query ("SELECT * FROM ".$db_prefix."payment WHERE pay_method = '$payment' AND pay_enable = '1' LIMIT 1");
$pay = sql_fetch_array ($res);
if (empty ($pay)) msg_die ('payment_not_selected');
$payment_method = $pay['pay_method'];
// get USER ID for checkout4.tpl
$item = $total = $total_weight = 0;
// -- loading template
$tpl = load_tpl ('checkout3.tpl');
$txt['block_checkout_item'] = '';
$sql = "SELECT p.item_id,p.title, p.distro, p.price, p.cat_id, p.weight, p.digital_prod, p.price_msrp, p.short_note, p.x_option, o.qty, o.idx, o.opt_fee , o.opt_text
FROM ".$db_prefix."products AS p JOIN ".$db_prefix."orders AS o
USING (item_id) WHERE user_id = '$current_user_id' ORDER BY cat_id asc, title asc";
$res = sql_query ($sql);
while ($row = sql_fetch_array ($res))
{
$i++;
$item = $item + $row['qty'];
$cat_id = $row['cat_id'];
$item_id = $row['item_id'];
$price = $row['price'] + $row['opt_fee'];
$subtotal = $price * $row['qty'];
$total += ($row['price'] + $row['opt_fee']) * $row['qty'];
$total_weight += $row['weight'] * $row['qty'];
$row['digital'] = $row['digital_prod'] ? $lang['l_digital_icon'] : '';
$row['x_option'] = stripslashes ($row['opt_text']);
$row['xe_price'] = get_xe_price ($row['price'], 'list');
$row['price'] = num_format ($price);
$row['price_msrp'] = num_format ($row['price_msrp']);
$row['xe_subtotal'] = get_xe_price ($subtotal, 'list');
$row['subtotal'] = num_format ($subtotal, 0, 1);
$row['subtotal_weight'] = $row['weight'] * $row['qty'];
$row['distro'] = get_distro ($row['distro']);
$txt['block_checkout_item'] .= quick_tpl ($tpl_block['checkout_item'], $row);
}
// any item?
if ($item == 0) msg_die ('NO_ITEM_IN_CART');
// billing address
$user = get_user_info ($current_user_id);
$user['bill_address'] = format_address ($user);
if ($xpress) $user['bill_address'] .= $lang['l_xpress_tag'];
// shipping address
$res_ship = sql_query ("SELECT * FROM ".$db_prefix."address WHERE user_id='$current_user_id' AND as_default='1' LIMIT 1");
$row_ship = sql_fetch_array ($res_ship);
$user['ship_address'] = format_address ($row_ship);
if ($xpress) $user['ship_address'] .= $lang['l_xpress_tag'];
// get all cost
$t = get_courier_fee ($current_user_id, $item, $total, $total_weight, $shipper);
if (empty ($t)) msg_die ('shipper_not_selected', '', -2);
$sh_cost = $t[$shipper]['fee'];
// get grand total
$disc = get_discount ($total);
$dst = $total - $disc['value'] - $disc['promo_disc']; // dst = discounted sub total
// get tax
if ($config['tax_base'] == 'billing')
$tax = get_tax ($total, $dst, $sh_cost, $user['country'], $user['state'], $user['city']);
else
$tax = get_tax ($total, $dst, $sh_cost, $row_ship['country'], $row_ship['state'], $row_ship['city']);
$gtotal = $dst + $tax + $sh_cost;
// cart config for payment
$cart_cfg['amount'] = $gtotal;
$cart_cfg['shipper'] = $shipper;
$cart_cfg['order_notes'] = $order_notes;
$form = get_form_var ($payment, $user, $row_ship, $cart_cfg);
// flush
$txt = array_merge ($txt, $user);
$txt['order_notes'] = $order_notes;
$txt['shipping_cost'] = num_format ($sh_cost, 0, 1);
$txt['gift_code'] = $disc['gift_code'];
$txt['coupon_disc'] = num_format ($disc['value'] * -1, 0, 1);
$txt['shop_disc'] = num_format ($disc['promo_disc'] * -1, 0, 1);
$txt['total_weight'] = num_format ($total_weight, 2);
$txt['total_weight_ceil'] = ceil ($total_weight);
$txt['total'] = num_format ($total, 0, 1);
$txt['tax'] = num_format ($tax, 0, 1);
$txt['xe_grand_total'] = get_xe_price ($gtotal, 'list');
$txt['grand_total'] = num_format ($gtotal, 0, 1);
$txt['amount'] = $gtotal;
$txt['shipping'] = $sh_cost;
$txt['payment_method'] = $pay['pay_name'];
$txt['shipping_method'] = $ship_name;
$txt['payment'] = $payment;
$txt['shipper'] = $shipper;
$txt['form_action'] = $form['action'];
$txt['form_method'] = $form['method'];
$txt['form_hidden'] = $form['hidden'];
$txt['num_curr_name'] = $config['num_curr_name'];
// output
$txt['main_body'] = quick_tpl ($tpl, $txt);
generate_html_header ("$config[site_name] $config[cat_separator] Checkout 2/2");
flush_tpl ();
break;
}
?>
e of the musical
talent and the entertaining show these guys put on. I may not listen to The Smiths
like I used to, but I’d see These Charming Men again.
