Example #1
0
 function add()
 {
     if ($_POST['count'] == 0) {
         $this->error("You did not select any product!");
     }
     //强制登录
     if ($this->memberID <= 0 && GetValue('quickbuy') == 0) {
         if ($this->isAjax()) {
             $data = array('status' => 0, 'info' => 'Please Log on!', 'url' => U('MemberPublic/Login'));
             echo json_encode($data);
             exit;
         } else {
             echo "<script>alert('Please Log on!');location.href='" . U('MemberPublic/Login') . "';</script>";
             exit;
         }
     }
     $dao = D("Cart");
     self::$Model = D("Products");
     $prolist = self::$Model->where("id=" . $_POST['id'])->find();
     $attrlist = self::$Model->get_attrs($prolist['cateid'], $_POST['id']);
     $model = array();
     $i = 0;
     //属性列表
     $attributes = array_keys($_POST['attr']);
     $no_select = array();
     //强制值不为空
     foreach ($attrlist as $key => $value) {
         if (($value['input_type'] == 0 || $value['input_type'] == 1) && in_array($value['name'], $attributes) && $_POST['attr'][$value['name']]) {
             $model[$i]['name'] = $value['name'];
             $attr_value = explode('__', $_POST['attr'][$value['name']]);
             $model[$i]['value'] = $attr_value[0];
             $model[$i]['attr_price'] = $attr_value[1];
             $i++;
         } else {
             $no_select[] = $value['name'];
         }
     }
     if (count($no_select) > 0) {
         $this->error("Please select " . implode(',', $no_select) . '!');
     }
     $dao->add_item($this->sessionID, $_POST['id'], $_POST['count'], serialize($model));
     if ($this->isAjax()) {
         $item_count = itemCount();
         $total_count = TotalCount();
         $price_total = getprice_str(cart_total());
         $data = array('status' => 1, 'info' => "<em class='add_ok'></em><span id='shopping_data'>Add <strong>{$_POST['count']}</strong> items Goods To Cart Successful</span>", 'number_total' => $item_count, 'items_total' => $total_count, 'price_total' => $price_total, 'list' => $dao->cart_list($this->sessionID));
         //$this->success('Shopping Cart <a>'.itemCount().'</a> items quantity <a>'.TotalCount().'</a>.<br/>Total '.getprice_str(cart_total()).'.');
         echo json_encode($data);
         exit;
     } else {
         $this->redirect('Cart/disp');
     }
 }
 function _initialize()
 {
     header("Content-Type:text/html; charset=utf-8");
     //获取国家列表
     self::$Model = D("Region");
     $this->Countries = self::$Model->where("type=0")->order('name asc')->select();
     //主题
     if ($this->theme = GetValue('theme')) {
     } else {
         $this->theme = 'default';
     }
     //货币
     L('_OPERATION_SUCCESS_', "Operation Success");
     L('_OPERATION_FAIL_', 'Operation Fail');
     //$this->currencies=get_currencies_arr();
     //生产一个唯一的session id
     $this->sessionID = Cookie::get('sessionID');
     if (!$this->sessionID) {
         $this->sessionID = create_session_id();
         Cookie::set('sessionID', $this->sessionID);
     }
     //读取用户id
     $auth_cookie = Cookie::get('auth');
     if (empty($auth_cookie)) {
         $this->memberID = 0;
         Session::set('back', $_SERVER['REQUEST_URI']);
     } else {
         $auth = daddslashes(explode("\t", authcode($auth_cookie, 'DECODE', C('AUTHKEY'))));
         list($member_id, $member_email) = empty($auth) || count($auth) < 2 ? array('', '') : $auth;
         if (!empty($member_id)) {
             $this->memberID = $member_id;
         }
     }
     Cookie::set('memberID', $this->memberID);
     if ($this->memberID) {
         //读取用户信息
         $this->mid = $this->memberID;
         self::$Model = D("Members");
         $this->member_Info = $this->memberInfo = self::$Model->where("id=" . $this->memberID)->find();
         self::$Model = D("Shippingaddress");
         $this->memberShippingAddress = self::$Model->where("id=" . $this->memberID)->find();
     }
     //购物车商品
     self::$Model = D("Cart");
     $this->cart_list = self::$Model->cart_list($this->sessionID);
     $this->item_count = itemCount();
     $this->total_count = TotalCount();
     if (F('Common_Cache')) {
         $this->assign(F('Common_Cache'));
     }
 }
 function add()
 {
     if ($_POST['count'] == 0) {
         $this->error("You did not select any product!");
     }
     //强制登录
     /*if ($this->memberID <= 0 && GetSettValue('quickbuy')==0) {
     		echo "<script>alert('Please Log on!');location.href='".U('Member-Public/Login')."';</script>";
     		die;
     		}*/
     $dao = D("Cart");
     self::$Model = D("Products");
     $prolist = self::$Model->where("id=" . $_POST['id'])->find();
     $attrlist = self::$Model->get_attrs($prolist['cateid'], $_POST['id']);
     $model = array();
     $i = 0;
     //属性列表
     $attributes = array_keys($_POST['attr']);
     $no_select = array();
     //强制值不为空
     foreach ($attrlist as $key => $value) {
         if ($value['input_type'] == 1 && in_array($value['name'], $attributes) && $_POST['attr'][$value['name']]) {
             $model[$i]['name'] = $value['name'];
             $attr_value = explode('__', $_POST['attr'][$value['name']]);
             $model[$i]['value'] = $attr_value[0];
             $model[$i]['attr_price'] = $attr_value[1];
             $i++;
         } else {
             $no_select[] = $value['name'];
         }
     }
     if (count($no_select) > 0) {
         $this->error("Please select " . implode(',', $no_select) . '!');
     }
     $dao->add_item($this->sessionID, $_POST['id'], $_POST['count'], serialize($model));
     if ($this->isAjax()) {
         $this->success('Shopping Cart <a>' . itemCount() . '</a> items quantity <a>' . TotalCount() . '</a>.<br/>Total ' . getprice_str(cart_total()) . '.');
     } else {
         $this->redirect('Cart/disp');
     }
 }
Example #4
0
 function _initialize()
 {
     header("Content-Type:text/html; charset=utf-8");
     L('_OPERATION_SUCCESS_', "Operation Success");
     L('_OPERATION_FAIL_', 'Operation Fail');
     //是否关闭网站
     if (GetValue('close_site') == 1) {
         header("HTTP/1.1 500 Internal Server Error");
         header("Status: 500 Internal Server Error");
         die('<div style="margin: 10px; text-align: center; font-size: 14px"><p>The temporary closure of this site, you can not access!</p><p>' . GetValue('close_site_content') . '</p></div>');
     }
     //IP封锁
     if (isset($_COOKIE['ipblock']) && $_COOKIE['ipblock'] == 0) {
     } elseif (isset($_COOKIE['ipblock']) && $_COOKIE["ipblock"] == 1 || GetValue('ipblock') == 1 && GetValue('ipblock_pwd') != '') {
         import('@.Action.Home.IpblockAction');
         $ipblock = new IpblockAction();
         $ipblock->index();
     }
     $this->ProModel = D('Products');
     //多主题
     if ($this->theme = GetValue('theme')) {
         setcookie('think_template', $this->theme, time() + 3600, '/');
     } else {
         setcookie('think_template', 'default', time() + 3600, '/');
     }
     //多语言
     /*$lang=GetValue('lang');
     		if('auto'!=$lang){
     		setcookie('think_language',$lang?$lang:'en-us',time()+3600,'/');
     		}*/
     //浏览历史
     $this->product_history = product_history();
     //货币初始化
     $this->currencies = $currencies = get_currencies_arr();
     if (!isset($_SESSION['currency'])) {
         for ($row = 0; $row < count($currencies); $row++) {
             if ($currencies[$row]['symbol'] == C('DEFAULT_CURRENCIES_SYMBOL')) {
                 $_SESSION['currency'] = $currencies[$row];
             }
         }
     }
     //生产一个唯一的session id
     $this->sessionID = Cookie::get('sessionID');
     if (!$this->sessionID) {
         $this->sessionID = create_session_id();
         Cookie::set('sessionID', $this->sessionID);
     }
     //读取用户id
     $auth_cookie = Cookie::get('auth');
     if (empty($auth_cookie)) {
         $this->memberID = 0;
     } else {
         $auth = daddslashes(explode("\t", authcode($auth_cookie, 'DECODE', C('AUTHKEY'))));
         list($member_id, $member_email) = empty($auth) || count($auth) < 2 ? array('', '') : $auth;
         if (!empty($member_id)) {
             $this->memberID = $member_id;
         }
     }
     Cookie::set('memberID', $this->memberID);
     if ($this->memberID) {
         //读取用户信息
         $this->mid = $this->memberID;
         self::$Model = D("Members");
         $this->memberInfo = self::$Model->where("id=" . $this->memberID)->find();
         $this->member_Info = $this->memberInfo;
         self::$Model = D("Shippingaddress");
         $this->memberShippingAddress = self::$Model->where("id=" . $this->memberID)->find();
         Cookie::set('memberShippingAddress', $this->memberShippingAddress);
         $this->member_ShippingAddress = $this->memberShippingAddress;
         /*$this->_365call="
         		<script type=\"text/javascript\">
         		//<![CDATA[
         		var _365call_memberID  = \"{$this->memberInfo['email']}\"; //  char(20)  账号(会员号)
         		var _365call_clientName= \"{$this->memberInfo['firstname']}{$this->memberInfo['lastname']}\"; //  char(50)  用户名(姓名)
         		var _365call_email     = \"{$this->memberInfo['email']}\"; //  char(50)  邮件地址
         		var _365call_phone     = \"{$this->memberShippingAddress['telphone']}\"; //  char(20)  联系电话
         		var _365call_msn       = \"\"; //  char(50)  MSN
         		var _365call_qq        = \"\"; //  char(20)  QQ
         		var _365call_note      = \"{$this->memberShippingAddress['address']}\"; //  char(100) 其他
         		//]]>
         		</script>";*/
     }
     //当前月份
     $today = getdate();
     $this->month = $today['month'];
     //总重量
     self::$Model = D("Cart");
     $this->Total_weight = self::$Model->cart_total_weight($this->sessionID);
     //购物车商品
     $this->cart_list = self::$Model->cart_list($this->sessionID);
     $this->item_count = itemCount();
     $this->total_count = TotalCount();
     //会员等级
     $this->memberGropuInfo = get_members_group($this->memberID);
     if (get_members_group($this->memberID)) {
         $this->isVip = 1;
     } else {
         $this->isVip = 0;
     }
     /**
      * bof缓存模板变量
      */
     //全局模板变量
     if (F('Common_Cache') == '') {
         F('Common_Cache', $this->_Common_Cache());
     }
     $this->assign(F('Common_Cache'));
     //产品缓存
     if (F('Products_Cache') == '') {
         F('Products_Cache', $this->_Products_Cache());
     }
     //打乱随机显示
     $Products_Cache = F('Products_Cache');
     //$Products_Cache['FeaturedProducts']=$this->ProModel->rand($Products_Cache['FeaturedProducts']);
     //$Products_Cache['HotProducts']=$this->ProModel->rand($Products_Cache['HotProducts']);
     //$Products_Cache['NewProducts']=$this->ProModel->rand($Products_Cache['NewProducts']);
     //$Products_Cache['SpeProducts']=$this->ProModel->rand($Products_Cache['SpeProducts']);
     $this->assign($Products_Cache);
     /**
      * eof缓存模板变量
      */
 }
 public function add_cart()
 {
     $count = I('post.count', 0, 'intval');
     $pid = I('post.id', 0, 'intval');
     $post = $_POST;
     if ($count <= 0) {
         $this->error("You did not select any product.");
     }
     if (empty($pid)) {
         $this->error("Please add goods to cart again.");
     }
     //强制登录
     if ($this->memberID <= 0 && GetValue('quickbuy') == 0) {
         $this->error('Please Log on.', U('MemberPublic/Login'));
     }
     $cartModel = D('Cart');
     $productModel = D('Products');
     $prolist = $productModel->where("id='{$pid}'")->find();
     $attrlist = $productModel->get_attrs($prolist['cateid'], $pid);
     //属性列表
     $i = 0;
     $attributes = array_keys($post['attr']);
     $attr_data = $no_select = array();
     //print_r($attrlist);
     //强制值不为空
     foreach ($attrlist as $k => $v) {
         if (($v['input_type'] == 0 || $v['input_type'] == 1) && in_array($v['name'], $attributes) && $post['attr'][$v['name']]) {
             $attr_data[$i]['name'] = $v['name'];
             $attr_value = explode('__', $post['attr'][$v['name']]);
             $attr_data[$i]['value'] = $attr_value[0];
             $attr_data[$i]['attr_price'] = $attr_value[1];
             $i++;
         } else {
             $no_select[] = $v['name'];
         }
     }
     if (count($no_select) > 0) {
         $this->error("Please select " . implode(',', $no_select) . '.');
     }
     $cartModel->add_item($this->sessionID, $pid, $count, serialize($attr_data));
     if (IS_AJAX) {
         $item_count = itemCount();
         $total_count = TotalCount();
         $price_total = getprice_str(cart_total());
         $data = array('status' => 1, 'info' => "Add {$_POST['count']} items Goods To Cart Successful</span>", 'item_count' => $item_count, 'total_count' => $total_count, 'price_total' => $price_total);
         $this->ajaxReturn($data);
     } else {
         $this->redirect('Cart/index');
     }
 }