<?php
$order = $mysql->get_array($mysql->query("country", "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' AND temp = 'y' LIMIT 1"));
$shipping = $site->shop_settings('home_country,shipping_flatrate_dom,shipping_flatrate_int');
if($order['country'] == '')
{
$order['country'] = $shipping['home_country'];
}
$postage = ($order['country'] == $shipping['home_country']) ? number_format($shipping['shipping_flatrate_dom'], 2, '.', '') : number_format($shipping['shipping_flatrate_int'], 2, '.', '');
//add handling fee into the shipping fee
$h = $site->shop_settings('shipping_handling_fee');
$postage += $h['shipping_handling_fee'];
//update postage
$mysql->update("shipping", $postage, "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' AND temp = 'y' LIMIT 1");
//free shipping when X amount is spent
$totalvar = 0;
$query = $mysql->query("(price*qty) as price,pid", "fs_shop_cart", "owner = '{$_SESSION['owner']}' AND temp = 'y'");
while($data = $mysql->get_array($query))
{
$exclude = $mysql->num_rows($mysql->query("ID", "fs_shop_products", "ID = '{$data['pid']}' AND exclude_from_free_shipping = 'y' LIMIT 1"));
$totalvar += ($exclude == 1) ? 0 : $data['price'];
}
$order = $mysql->get_array($mysql->query("sales_tax,country,discount_value", "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' AND temp = 'y' LIMIT 1"));
$totalvar -= ($order['sales_tax']+$order['discount_value']);
if($totalvar > 0)
{
$freeAmount = $site->shop_settings('free_shipping,home_country');
if($totalvar > $freeAmount['free_shipping'] && $order['country'] == $freeAmount['home_country'])
{
$mysql->update("shipping", 0, "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' AND temp = 'y' LIMIT 1");
}
}
//don't charge shipping if order only has virutal products
$query = $mysql->query("virtual", "fs_shop_cart", "owner = '{$_SESSION['owner']}' AND temp = 'y'");
$allitems = $mysql->num_rows($query);
$virtualItems = 0;
while($data = $mysql->get_array($query))
{
if($data['virtual'] == 'y')
{
$virtualItems++;
}
}
if($virtualItems == $allitems)
{
$mysql->update("shipping", 0, "fs_shop_orderdata", "owner = '{$_SESSION['owner']}' AND temp = 'y' LIMIT 1");
}
?>