pathRoot = str_replace("Lib", "", dirname(__FILE__));
}
// load
function Load() {
if (!$_SESSION[DOMAIN]["account"]["url"])
$_SESSION[DOMAIN]["account"]["url"] = $_SERVER["HTTP_HOST"];
if ($_POST["remove"]) {
header("Content-type: text/html; charset=UTF-8");
$this->RemoveOrder();
$this->LoadCartPage();
exit();
}
if ($_POST["reset"]) {
header("Content-type: text/html; charset=UTF-8");
$this->ResetOrder();
$this->LoadCartPage();
exit();
}
if ($_POST["cartpage"]) {
header("Content-type: text/html; charset=UTF-8");
$this->LoadCartPage();
exit();
}
if ($_POST["incart"]) {
header("Content-type: text/html; charset=UTF-8");
$this->LoadCart();
exit();
}
if ($_POST["stock"]) {
header("Content-type: text/html; charset=UTF-8");
if (!$_SESSION[DOMAIN]["shop"]["config"]) $this->LoadConfig();
$this->LoadStock();
exit();
}
if ($_POST["pickup"]) {
header("Content-type: text/html; charset=UTF-8");
if (!$_SESSION[DOMAIN]["shop"]["config"]) $this->LoadConfig();
$this->PickupItem();
exit();
}
if ($_POST["item"]) {
header("Content-type: text/html; charset=UTF-8");
if (!$_SESSION[DOMAIN]["shop"]["config"]) $this->LoadConfig();
$this->AddItem();
exit();
}
}
// load config.
function LoadConfig() {
$cmd = new C_Command();
try{
$cmd->Open("{$this->pathRoot}_Data/s_config.db");
$cmd->AddColumn("layout, n_row, _use_incart_");
$cmd->AddColumn("_use_sh_group_, _use_sh_attr_, _use_sh_price_");
$rows = $cmd->Select("t_design");
$_SESSION[DOMAIN]["shop"]["config"]["layout"] = $rows[0]["layout"];
$_SESSION[DOMAIN]["shop"]["config"]["n_row"] = $rows[0]["n_row"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_incart_"] = $rows[0]["_use_incart_"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_sh_group_"] = $rows[0]["_use_sh_group_"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_sh_attr_"] = $rows[0]["_use_sh_attr_"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_sh_price_"] = $rows[0]["_use_sh_price_"];
$cmd->Clear();
$cmd->AddColumn("shop_type, v_wish, _use_stock_, _use_quote_, _use_member_, soldout, sort_type");
// Added: 1401
$cmd->AddColumn("_tax_");
$rows = $cmd->Select("t_base");
$_SESSION[DOMAIN]["shop"]["config"]["shop_type"] = $rows[0]["shop_type"];
$_SESSION[DOMAIN]["shop"]["config"]["v_wish"] = $rows[0]["v_wish"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_stock_"] = $rows[0]["_use_stock_"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_quote_"] = $rows[0]["_use_quote_"];
$_SESSION[DOMAIN]["shop"]["config"]["_use_member_"] = $rows[0]["_use_member_"];
$_SESSION[DOMAIN]["shop"]["config"]["soldout"] = $rows[0]["soldout"];
// Added: 1401
$_SESSION[DOMAIN]["shop"]["config"]["_tax_"] = $rows[0]["_tax_"];
//
if ($rows[0]["sort_type"] == 2) $_SESSION[DOMAIN]["shop"]["sort"] = "Random()";
else if ($rows[0]["sort_type"] == 1) $_SESSION[DOMAIN]["shop"]["sort"] = "n_index DESC, item DESC";
else $_SESSION[DOMAIN]["shop"]["sort"] = "n_index, item";
$cmd->Close();
} catch (Exception $ex) {
echo "FAILURE:" . $ex->getMessage();
$cmd->Close();
}
}
// load carriage & point.
function LoadCarriageAndPoint() {
if ($_SESSION[DOMAIN]["account"]["carriage"] && $_SESSION[DOMAIN]["account"]["point"]) return true;
$cmd = new C_Command();
try {
$cmd->Open("{$this->pathRoot}_Data/s_config.db");
$cmd->AddColumn("*");
$rows = $cmd->Select("t_carriage");
$_SESSION[DOMAIN]["account"]["carriage"] = $rows[0];
$rows = $cmd->Select("t_point");
$_SESSION[DOMAIN]["account"]["point"] = $rows[0];
$cmd->Close();
return true;
} catch (Exception $ex) {
echo "FAILURE:" . $ex->getMessage();
$cmd->Close();
return false;
}
}
// remove order.
function RemoveOrder() {
$xcode = Filter::Get($_POST["id"], 200, "[^0-9a-zA-Z\-_]");
unset($_SESSION[DOMAIN]["cart"][$xcode]);
}
// reset order.
function ResetOrder() {
$xcode = Filter::Get($_POST["id"], 200, "[^0-9a-zA-Z\-_]");
$value = Filter::Get($_POST["v"], 9, "[^0-9]", "a", "1");
if (!$value) $value = 1;
$cmd = new C_Command();
try {
$cmd->Open("{$this->pathRoot}_Data/s_master.db");
$cmd->AddColumn("n_stock");
$cmd->SetOption("xcode = '{$xcode}'");
$rows = $cmd->Select("m_sku");
$cmd->Close();
} catch (Exception $ex) {
$this->exception = $ex->getMessage();
$cmd->Close();
}
if (count($rows) > 0 && $_SESSION[DOMAIN]["cart"][$xcode]) {
if ($_SESSION[DOMAIN]["shop"]["config"]["_use_stock_"] && (int) $value > (int) $rows[0]["n_stock"]) {
$n = ($rows[0]["n_stock"]) ? $rows[0]["n_stock"] : 0;
if ($n) $this->exception = "この商品は{$n}点以上購入できません。";
else $this->exception = "この商品は売り切れました。";
$_SESSION[DOMAIN]["cart"][$xcode]["order"] = $n;
} else {
$_SESSION[DOMAIN]["cart"][$xcode]["order"] = $value;
}
}
}
// load cart-page.
function LoadCartPage() {
// Added: 1401
$_tax_ = $_SESSION[DOMAIN]["shop"]["config"]["_tax_"];
if ($_SESSION[DOMAIN]["cart"]) {
if (!$this->LoadCarriageAndPoint()) exit();
if ($this->exception) print("");
print("
");
print("");
print("");
print("");
print("");
// Modified: 1401
if ($_tax_) print("");
else print("");
print("");
print("");
foreach ($_SESSION[DOMAIN]["cart"] as $v) {
$price = $v["item"]["sale_price"];
$option = "";
if ($v["option"]) {
$option = "
";
foreach ($v["option"] as $name => $value) {
$vs = explode(":", $value);
if ($vs[1]) {
$price += $vs[1];
$option .= "
[{$name}] {$vs[0]} +¥" . number_format($vs[1]);
} else {
$option .= "
[{$name}] {$vs[0]}";
}
}
}
$v_price = number_format($price);
$link = ($v["item"]["link_url"]) ? "../{$v["item"]["link_url"]}" : "item.php?i={$v["item"]["item"]}";
print("");
print("");
print("");
print("");
print("");
print("");
$cnt += (int) $v["order"];
$sum += (int) $v["order"] * (int) $price;
$add += (int) $v["item"]["n_addition"] * (int) $v["order"]; // 追加送料
}
print("
");
print("");
// total
$f_cnt = number_format($cnt);
$f_sum = number_format($sum);
print("");
// discount
$point = $_SESSION[DOMAIN]["account"]["point"];
if ($point["_use_discount_"]) {
$csv = explode(",", $point["discount"]);
foreach ($csv as $s) {
list($p, $r) = explode(":", $s);
if ((int) $sum >= (int) $p) {
$rate = $r / 100;
$tag = "";
} else $tag = "
あと" . number_format((int) $p - (int) $sum) . "円で{$r}%OFF
";
}
if ($rate) {
$dis = (int) ((float) $sum * (float) $rate);
$v_dis = number_format($dis);
print("");
} else {
print("");
}
}
// carriage
$carriage = $_SESSION[DOMAIN]["account"]["carriage"];
if ($carriage["add_type"] == 3) {
$tag = "
無料";
} else if ($carriage["_limit_"] && (int) $sum >= (int) $carriage["n_limit"]) {
$tag = "
\\0";
} else if ($carriage["set_type"] > 1) {
$tag = "
送料一覧をご覧ください";
} else {
$car = ($carriage["add_type"] == 1) ? (int) $carriage["n_carriage"] * (int) $cnt : (int) $carriage["n_carriage"];
$car = (int) $car + (int) $add;
$tag = "¥" . number_format($car);
}
// Modified: 1401
if ($_tax_) print("");
else print("");
// Modified: 1401 amount
$amt = $sum - $dis + $car;
$tax = ($_tax_) ? Filter::Tax($amt) : 0;
$v_tax = number_format($tax);
$v_amt = number_format($amt + $tax);
if ($_tax_) print("");
print("");
print("
計{$f_cnt}点 | ¥{$f_sum} |
---|
割引 | -¥{$v_dis}{$tag} |
---|
割引 | {$tag} |
---|
送料 | {$tag} |
---|
送料(税込) | {$tag} |
---|
消費税 | ¥{$v_tax} |
---|
合計(税込) | ¥{$v_amt} |
---|
");
// point
if ($point["_use_point_"]) {
$rate = (int) $point["point_add_rate"] / 100;
$v_pt = number_format($sum * $rate);
print("");
print("");
print("
");
}
$url = SSL_URL;
$id = session_id();
print("
");
print("");
} else {
print("
カートに商品はありません。
");
print("
");
}
}
// load cart.
function LoadCart() {
if ($_SESSION[DOMAIN]["cart"]) {
$path = "http://" . DOMAIN;
print("");
foreach ($_SESSION[DOMAIN]["cart"] as $v) {
$price = $v["item"]["sale_price"];
if ($v["option"]) {
foreach ($v["option"] as $name => $value) {
$vs = explode(":", $value);
if ($vs[1]) {
$price += $vs[1];
}
}
}
$v_price = number_format($price);
$link = ($v["item"]["link_url"]) ? $v["item"]["link_url"] : "shop/item.php?i={$v["item"]["item"]}";
print("");
print("");
print("");
print("");
$cnt += (int) $v["order"];
$sum += (int) $v["order"] * (int) $price;
}
$cnt = number_format($cnt);
$sum = number_format($sum);
print("");
print("");
print("");
print("
");
}
}
// load stock.
function LoadStock() {
$item = Filter::Get($_POST["item"], 200, "[^0-9a-zA-Z\-_]");
$sub = Filter::Get($_POST["sub"], 1, "[^01]");
if (!$item) return;
$soldout = $_SESSION[DOMAIN]["shop"]["config"]["soldout"];
if (!soldout) "在庫切れ!";
$cmd = new C_Command();
try{
$cmd->Open("{$this->pathRoot}_Data/s_master.db");
$cmd->AddColumn("sku.xcode, sku.unit1, sku.unit2, sku.n_stock, sku.n_min, m._sku_, m._visible_");
$cmd->SetOption("sku.item = '{$item}'");
$rows = $cmd->Select("m_sku As sku Left Outer Join m_item as m On (sku.item = m.item)");
if ($rows[0]["_sku_"]) {
$u1 = array();
$u2 = array();
foreach ($rows as $row) {
if (!$u1[$row["unit1"]]) $u1[] = $row["unit1"];
if (!$u2[$row["unit2"]] && $row["unit2"]) $u2[] = $row["unit2"];
$sku[$row["xcode"]] = $row;
}
$cmd->Clear();
$cmd->AddColumn("unit1, unit1_name");
$csv = implode("','", $u1);
$cmd->SetOption("unit1 in ('{$csv}')");
$cmd->SetOrder("n_index");
$rows2 = $cmd->Select("m_unit1");
foreach ($rows2 as $row) {
$unit1[$row["unit1"]] = $row["unit1_name"];
}
if (count($u2) > 0) {
$cmd->Clear();
$cmd->AddColumn("unit2, unit2_name");
$csv = implode("','", $u2);
$cmd->SetOption("unit2 in ('{$csv}')");
$cmd->SetOrder("n_index");
$rows2 = $cmd->Select("m_unit2");
foreach ($rows2 as $row) {
$unit2[$row["unit2"]] = $row["unit2_name"];
}
}
}
$cmd->Close();
if ($rows[0]["_visible_"] !== "0") {
if ($rows[0]["_sku_"]) {
// SKU
$u1 = array_keys($unit1);
$u2 = array_keys($unit2);
echo "";
if (count($u2) > 0) {
echo "";
echo "";
for ($c = 0; $c < count($u2); $c++) {
echo "";
}
echo "";
}
for ($r = 0; $r < count($u1); $r++) {
echo "";
if (count($u2) > 0) {
echo "";
for ($c = 0; $c < count($u2); $c++) {
$xcode = "{$item}{$u1[$r]}{$u2[$c]}";
if ($sku[$xcode]) {
if ($sku[$xcode]["n_stock"] > 0) {
$mark = ($sku[$xcode]["n_stock"] > $sku[$xcode]["n_min"]) ? "○" : "△";
if ($_checked_) $flg = "";
else { $flg = "checked"; $_checked_ = true; }
echo "";
$_stock_ = true;
} else echo "";
} else echo "";
}
} else {
echo "";
$xcode = "{$item}{$u1[$r]}";
if ($sku[$xcode]["n_stock"] > 0) {
$mark = ($sku[$xcode]["n_stock"] > $sku[$xcode]["n_min"]) ? "○" : "△";
if ($_checked_) $flg = "";
else { $flg = "checked"; $_checked_ = true; }
echo "";
$_stock_ = true;
} else echo "";
}
echo "";
}
echo "
";
echo "
○…在庫あり △…残りわずか ×…売り切れ
";
if (!$_stock_) {
echo "
";
} else {
$path = ($sub) ? "../" : "";
echo "
";
echo "
";
}
} else {
if ($rows[0]["n_stock"] < 1) {
echo "
";
} else {
$path = ($sub) ? "../" : "";
echo "
";
echo "
";
}
}
}
} catch (Exception $ex) {
echo "FAILURE:" . $ex->getMessage();
$cmd->Close();
}
}
// pickup.
function PickupItem() {
$xcode = Filter::Get($_POST["item"], 200, "[^0-9a-zA-Z\-_]");
$cmd = new C_Command();
//$cmd->_debug_ = true;
$view = "m_sku As sku";
$view .= " Left Join m_item As i On (sku.item = i.item)";
$view .= " Left Join m_unit1 As u1 On (sku.unit1 = u1.unit1)";
$view .= " Left Join m_unit2 As u2 On (sku.unit2 = u2.unit2)";
try {
$cmd->Open("{$this->pathRoot}_Data/s_master.db");
$cmd->AddColumn("sku.xcode, sku.n_stock, i.link_url, i.image1, i.item, i.item_name, u1.unit1_name, u2.unit2_name");
$cmd->AddColumn("i.sale_price, i.n_point, i.n_addition");
$cmd->SetOption("(sku.xcode = '{$xcode}') Or (sku.xcode = '{$xcode}000000')");
$rows = $cmd->Select($view);
$cmd->Close();
} catch (Exception $ex) {
echo "FAILURE:" . $ex->getMessage();
$cmd->Close();
}
if (count($rows) < 1) echo "FAILURE:該当商品がみつかりません。";
else {
$xcode = $rows[0]["xcode"];
if ($_SESSION[DOMAIN]["cart"][$xcode]) {
if ($_SESSION[DOMAIN]["shop"]["config"]["_use_stock_"] && (int) $_SESSION[DOMAIN]["cart"][$xcode]["order"] >= (int) $rows[0]["n_stock"]) {
$n = ($rows[0]["n_stock"]) ? $rows[0]["n_stock"] : 0;
if ($n) echo "FAILURE:この商品は{$n}点以上購入できません。";
else echo "FAILURE:この商品は売り切れました。";
} else {
$_SESSION[DOMAIN]["cart"][$xcode]["order"] = (int) $_SESSION[DOMAIN]["cart"][$xcode]["order"] + 1;
echo "SUCCEED:";
}
} else {
$_SESSION[DOMAIN]["cart"][$xcode]["item"] = $rows[0];
$_SESSION[DOMAIN]["cart"][$xcode]["order"] = 1;
echo "SUCCEED:";
}
//var_dump($_SESSION[DOMAIN]["cart"]);
}
}
// add item.
function AddItem() {
$order = Filter::Get($_POST["order"], 9, "[^0-9]", "a");
$item = Filter::Get($_POST["item"], 200, "[^0-9a-zA-Z\-_]");
$sku = Filter::Get($_POST["sku"], 200, "[^0-9a-zA-Z\-_]");
if (isset($_POST["option_name"]) && isset($_POST["option_value"])) {
Filter::SetArray($_POST["option_name"], 200);
Filter::SetArray($_POST["option_value"], 200);
}
$xcode = ($sku) ? $sku : $item;
$cmd = new C_Command();
//$cmd->_debug_ = true;
$view = "m_sku As sku";
$view .= " Left Join m_item As i On (sku.item = i.item)";
$view .= " Left Join m_unit1 As u1 On (sku.unit1 = u1.unit1)";
$view .= " Left Join m_unit2 As u2 On (sku.unit2 = u2.unit2)";
try {
$cmd->Open("{$this->pathRoot}_Data/s_master.db");
$cmd->AddColumn("sku.xcode, n_stock, i.link_url, i.image1, i.item, i.item_name, u1.unit1_name, u2.unit2_name");
$cmd->AddColumn("i.sale_price, i.n_point, i.n_addition");
$cmd->SetOption("(sku.xcode = '{$xcode}') Or (sku.xcode = '{$xcode}000000')");
$rows = $cmd->Select($view);
$cmd->Close();
} catch (Exception $ex) {
echo "FAILURE:" . $ex->getMessage();
$cmd->Close();
}
if (count($rows) < 1) echo "FAILURE:該当商品がみつかりません。";
else {
$xcode = $rows[0]["xcode"];
$cnt = ($order) ? $order : 1;
if ($_SESSION[DOMAIN]["cart"][$xcode]) {
if ($_SESSION[DOMAIN]["shop"]["config"]["_use_stock_"] && (int) $_SESSION[DOMAIN]["cart"][$xcode]["order"] + (int) $cnt > (int) $rows[0]["n_stock"]) {
$n = ($rows[0]["n_stock"]) ? $rows[0]["n_stock"] : 0;
if ($n) echo "FAILURE:この商品は{$n}点以上購入できません。";
else echo "FAILURE:この商品は売り切れました。";
$_add_ = false;
} else {
$_SESSION[DOMAIN]["cart"][$xcode]["order"] = (int) $_SESSION[DOMAIN]["cart"][$xcode]["order"] + (int) $cnt;
echo "SUCCEED:";
$_add_ = true;
}
} else {
if ($_SESSION[DOMAIN]["shop"]["config"]["_use_stock_"] && (int) $cnt > (int) $rows[0]["n_stock"]) {
$n = ($rows[0]["n_stock"]) ? $rows[0]["n_stock"] : 0;
if ($n) echo "FAILURE:この商品は{$n}点以上購入できません。";
else echo "FAILURE:この商品は売り切れました。";
$_add_ = false;
} else {
$_SESSION[DOMAIN]["cart"][$xcode]["item"] = $rows[0];
$_SESSION[DOMAIN]["cart"][$xcode]["order"] = $cnt;
echo "SUCCEED:";
$_add_ = true;
}
}
if ($_add_ && isset($_POST["option_name"]) && isset($_POST["option_value"])) {
$n = $_POST["option_name"];
$v = $_POST["option_value"];
$option = array();
for ($i = 0; $i < count($v); $i++) {
$value = explode(":", $v[$i]);
if (!$value[0]) continue;
$option[$n[$i]] = $v[$i];
}
$_SESSION[DOMAIN]["cart"][$xcode]["option"] = $option;
}
}
}
}
$page = new ShopCart();
$page->Load();