static function getUserCart() { global $db, $user, $router; $sessAr = expSession::get('verify_shopper'); // initialize this users cart if they have ecomm installed. $active = $db->selectValue('modstate', 'active', 'module="storeController"'); if (!expModules::controllerExists('cart') || empty($active)) { // if ecomm is turned off, no cart. return null; } else { if (isset($router->params['controller']) && $router->params['controller'] == 'order' && ($router->params['action'] == 'verifyReturnShopper' || $router->params['action'] == 'verifyAndRestoreCart' || $router->params['action'] == 'clearCart') && (!isset($sessAr['validated']) || $sessAr['validated'] != true)) { return new order(); } else { // if ecomm is turned off, no cart. //$active = ; if (empty($active)) { return null; } $order = new order(); //initialize a new order object to use the find function from. $ticket = expSession::getTicketString(); //get this users session ticket. this is how we track anonymous users. // grab the origional referrer from the session table so that we can transfer it into the cart where it will be used for reporting purposes // sessions are temporary so we can't report on the referrer in the session table itsef because it may not be there // and we can't just get the referrer ar this point becaues the user likely navigated the site a bit and we want the origional referring site $orig_referrer = $db->selectValue('sessionticket', 'referrer', "`ticket`='" . $ticket . "'"); //see if we have a LIVE and ACTIVE session w/ cart and grab it if so $sessioncart = $order->find('first', "invoice_id='' AND sessionticket_ticket='" . $ticket . "'"); //check to see if the user is logged in, and if so grab their existing cart if (!empty($user) && $user->isLoggedIn()) { $usercart = $order->find('first', "invoice_id='' AND user_id=" . $user->id); } //eDebug($sessioncart); //eDebug($usercart); //enter here if we have NO ACTIVE SESSION CART -OR- We're awaiting a potential cart retore if (empty($sessioncart->id) || $sessAr['awaiting_choice'] == true) { if (empty($usercart->id)) { // no SESSION cart was found and user is not logged in... //let's see if they have a cart_id cookie set and we'll snag that if so //they won't have any user data, since they are "logged in" once they get to //checkout, so all we're really doing here is populating a cart for return //shoppers $cookie_cart_id = isset($_COOKIE['cid']) ? $_COOKIE['cid'] : 0; //eDebug($cookie_cart_id,true); if ($cookie_cart_id) { $tmpCart = new order($cookie_cart_id); if ($tmpCart->id != $cookie_cart_id) { //cookie set, but we gots no cart in the DB so act as if we had no cookie $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer, 'return_count' => $cart->setReturnCount($orig_referrer))); order::setCartCookie($cart); } else { $u = new user($tmpCart->user_id); //1) Was Not logged in if (empty($tmpCart->user_id)) { $cart = new order($cookie_cart_id); //update the session ticket and return count $cart->update(array('sessionticket_ticket' => $ticket, 'return_count' => $cart->setReturnCount($orig_referrer))); order::setCartCookie($cart); flash('message', gt('Welcome back')); } else { if (!empty($tmpCart->user_id)) { //check for is admin first if ($u->isActingAdmin() || $u->isAdmin()) { //no need to restore anything. $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer)); order::setCartCookie($cart); } else { if (!empty($tmpCart->user_id) && count($tmpCart->orderitem) == 0) { //silently copy tracking data from old order and continue on $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer, 'return_count' => $tmpCart->setReturnCount($orig_referrer))); order::setCartCookie($cart); flash('message', gt('Welcome back')); } else { if (!empty($tmpCart->user_id) && count($tmpCart->orderitem) > 0) { //3) Was Logged in w/ NON-?real user? account //eDebug(expUtil::right($u->username,10),true); if ($u->isTempUser()) { if (isset($sessAr['validated']) && $sessAr['validated']) { //already went through validation and we're good to go $cart = new order($sessAr['cid']); //update the session ticket and return count $cart->update(array('sessionticket_ticket' => $ticket, 'return_count' => $cart->mergeReturnCount($sessioncart->return_count), 'orig_referrer' => $sessioncart->orig_referrer)); order::setCartCookie($cart); expSession::un_set('verify_shopper'); $user = new user($cart->user_id); expSession::login($user); //Update the last login timestamp for this user. $user->updateLastLogin(); flash('message', gt('Welcome back') . ' ' . $sessAr['firstname'] . '! ' . gt('Your shopping cart has been restored - you may continue shopping or') . ' <a href="' . makelink(array("controller" => "cart", "action" => "checkout")) . '">checkout</a> ' . gt('at your convenience.')); } else { //send to verification? If user has elected to restore their cart //eDebug($_SESSION); if (isset($sessAr['awaiting_choice']) && $sessAr['awaiting_choice'] == true) { /*expSession::set('verify_shopper',array('au'=>1,'orig_path'=>$router->current_url, 'firstname'=>$u->firstname, 'cid'=>$cookie_cart_id)); redirect_to(array("controller"=>"order",'action'=>'verifyReturnShopper')); orderController::verifyReturnShopper();*/ //just give em the sessioncart $cart = $sessioncart; if (count($cart->orderitem) > 0) { //added items to current cart, so we'll assume they do not want to restore the previous at this point expSession::un_set('verify_shopper'); order::setCartCookie($cart); } else { flash('message', gt('Welcome back') . ' ' . $u->firstname . '! ' . gt('We see that you have shopped with us before.') . '<br><br><a id="submit-verify" href="' . makelink(array("controller" => "order", "action" => "verifyReturnShopper")) . '" rel="nofollow">' . gt('Click Here to Restore Your Previous Shopping Cart') . '</a><br><br><a class="exp-ecom-link" href="' . makelink(array("controller" => "order", "action" => "clearCart", "id" => $cookie_cart_id)) . '">' . gt('Click Here To Start a New Shopping Cart') . '</a>'); $sessAr['orig_path'] = $router->current_url; expSession::set('verify_shopper', $sessAr); } } else { //first time...create a default cart, issue message, set session, rinse, repeat $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'return_count' => $cart->setReturnCount($orig_referrer))); expSession::set('verify_shopper', array('au' => 1, 'orig_path' => $router->current_url, 'firstname' => $u->firstname, 'cid' => $cookie_cart_id, 'awaiting_choice' => true)); //order::setCartCookie($cart); flash('message', gt('Welcome back') . ' ' . $u->firstname . '! ' . gt('We see that you have shopped with us before.') . '<br><br><a id="submit-verify" href="' . makelink(array("controller" => "order", "action" => "verifyReturnShopper")) . '" rel="nofollow">' . gt('Click Here to Restore Your Previous Shopping Cart') . '</a><br><br><a class="exp-ecom-link" href="' . makelink(array("controller" => "order", "action" => "clearCart", "id" => $cookie_cart_id)) . '">' . gt('Click Here To Start a New Shopping Cart') . '</a>'); } } } else { //prompt to login and restore, otherwise reset and start fresh //this should be all we need to do here //redirect_to(array("controller"=>"order",'action'=>'verifyReturnShopper','au'=>'0')); $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer)); order::setCartCookie($cart); flash('message', gt('Welcome back') . ' ' . $u->firstname . '! ' . gt('If you would like to pick up where you left off, click here to login and your previous shopping cart will be restored.')); } } } } } } } } else { $cart = new order(); $cart->update(array("sessionticket_ticket" => $ticket, 'user_id' => $user->id, 'orig_referrer' => $orig_referrer)); order::setCartCookie($cart); } } else { //user is logged in, so we grab their usercart and update the session ticket only //$usercart->update(array('sessionticket_ticket'=>$ticket, 'orig_referrer'=>$orig_referrer)); $usercart->update(array('sessionticket_ticket' => $ticket)); $cart = $usercart; } //enter here if we HAVE an ACTIVE session/cart, but the user is not logged in } elseif (!empty($sessioncart->id) && $user->id == 0) { // the user isn't logged in yet...the session cart will do for now. $cart = $sessioncart; // if we hit here we've found a session cart AND a usercart because the user just logged in // and had both...that means we need to merge them } elseif (!empty($sessioncart->id) && !empty($usercart->id)) { // if we hit here we've found a session cart and a usercart...that means we need to merge them // if it's not the same cart. if ($sessioncart->id == $usercart->id) { $cart = $sessioncart; } else { // if the old user cart had gone through any of the checkout process before, than we // will clean that data out now and start fresh. $usercart->cleanOrderitems(); //merge the current session cart with previously saved user cart. foreach ($sessioncart->orderitem as $orderitem) { $orderitem->merge(array('orders_id' => $usercart->id, 'user_id' => $user->id)); } //if session cart HAS coupon codes, delete usercart codes and copy new code to usercart, else leave be if (count($sessioncart->getOrderDiscounts())) { foreach ($usercart->getOrderDiscounts() as $od) { $od->delete(); } foreach ($sessioncart->getOrderDiscounts() as $sod) { $sod->orders_id = $usercart->id; $sod->save(); } } $cart = new order($usercart->id); $sessioncart->delete(); } order::setCartCookie($cart); expSession::un_set('verify_shopper'); // the user doesn't have a cart with his/her user id in it. this probably means they just // logged in so we need to update the cart with the new user id information. } elseif (!empty($sessioncart->id) && (empty($usercart->id) && $user->isLoggedIn())) { //$sessioncart->update(array('user_id'=>$user->id, 'orig_referrer'=>$orig_referrer)); $sessioncart->update(array('user_id' => $user->id)); $cart = $sessioncart; } $cart->item_count = 0; foreach ($cart->orderitem as $items) { if ($items->product->requiresShipping && !$items->product->no_shipping) { $cart->shipping_required = true; } if ($items->product->requiresBilling) { $cart->billing_required = true; } $cart->item_count += $items->quantity; } $cart->lastcat = expSession::get('last_ecomm_category'); $cart->total = $cart->getCartTotal(); //eDebug($cart,true); return $cart; } } }
A03 超商取貨新訂單,使用 輕鬆袋或迷你袋 (不回覆sn_id,不需在ezShip上確認訂單 ,需登錄編號) A04 超商取貨新訂單,使用 輕鬆袋或迷你袋 (不回覆sn_id,需在ezShip上確認訂單, 需登錄編號) A05 宅配新訂單,不需在ezShip上確認訂單,可直接印單 (回覆sn_id,10碼數字) */ $temp_str .= '<input type="hidden" name="order_status" value="A05">'; //1 取貨付款 3 取貨不付款 $temp_str .= '<input type="hidden" name="order_type" value="1">'; //1 取貨付款 3 取貨不付款 $temp_str .= '<input type="hidden" name="su_id" value="' . $this->account . '">'; $temp_str = '<form id="form1" method="get" action="' . $this->sale_url . '">' . $temp_str . '</form><script>document.forms.form1.submit();</script>'; echo iconv("UTF-8", "Big5", $temp_str); } } $sale = new ezship(account); $sale->isshop(); //$sale->istake(); if ($_REQUEST["stCode"]) { //--紀錄商店資訊 $shopping_car = new order($conn, PREFIX . "shopping_car", PREFIX . "shopping_car_list", PREFIX . "products"); $order = $shopping_car->getorder(" where order_no='" . $_REQUEST['processID'] . "'"); $indata['memo'] = '店面資訊:' . $_REQUEST['stCate'] . ' ' . $_REQUEST['stCode'] . ' ' . $_REQUEST['stName'] . ' ' . $_REQUEST['stTel'] . ' ' . $_REQUEST['stAddr'] . ' '; $shopping_car->update($indata, $order['id']); $sale->data_send($_REQUEST); exit; } if ($_POST) { $sale->data_send($_POST); exit; }
//--紅利設定 (多少換1) //$shopping_car->set_point(1); //-結帳資料 if ($_POST && $_REQUEST['submit']) { //--自訂訂單編號 $shopping_car->order_auto_set('JSP'); $pay_bill = $shopping_car->paybill($_POST); if (!$pay_bill) { alert('付款結帳失敗!!' . $shopping_car->erromsg, '?list=1'); exit; } else { $temp = $shopping_car->esun_pay_send($pay_bill, '回傳路徑'); } linkto('index.jsx'); } else { $pay_bill = $shopping_car->update($_POST); } //--新增商品 if ($_GET["addpro"]) { $temp_addpro = explode(',', $_GET["addpro"]); $temp_size = explode(',', $_GET["size"]); $temp_price = explode(',', $_GET["price"]); if (!$_GET["count"]) { $_GET["count"] = 1; } //---會員分類折扣 $member_dp = $conn->GetRow("select * from " . PREFIX . "data_list where type='memberdesh' and new_type='" . $member->getinfo('type') . "' and status=1"); $shopping_car->deshprice($member_dp['detail'], false); foreach ($temp_addpro as $k => $v) { //--取得分類折扣 $pro_data = $conn->GetRow("select * from " . PREFIX . "products where id='" . $v . "'");
if ($w->check() == '0') { $w->msg('还没有登录呢!错误代码:107', '/admin.php'); } $config['name'] = $_SESSION['name']; $config['user'] = $_SESSION['user']; if ($g) { if ($g['ac'] == 'logout') { //登出 $w->logout(); } elseif ($g['ac'] == 'edit') { //编辑 $config['aid'] = $g['aid']; $odate = $o->show($g['aid']); $o->edit($odate); } elseif ($g['ac'] == 'add') { //添加数据 $w->show('add'); exit; } elseif ($g['ac'] == 'del') { $o->del($g['aid']); } } if ($p) { if ($p['ac'] == 'update') { $o->update($p); } elseif ($p['ac'] == 'add') { $o->adds($p); } } $config['oli'] = $o->li('0', '10'); $w->show('list');
function update_shipping() { $order = new order($this->params['id']); $this->params['shipped'] = datetimecontrol::parseData('shipped', $this->params); $order->update($this->params); flash('message', gt('Shipping information updated.')); expHistory::back(); }