コード例 #1
0
ファイル: popup.php プロジェクト: duonghoaikhanh/hondabac
 function _cart()
 {
     global $ttH;
     $arr_cart = Session::get('cart_pro', array());
     $arr_cart_list_pro = Session::get('cart_list_pro');
     if (isset($ttH->post['data'])) {
         foreach ($ttH->post['data'] as $key) {
             eval('$' . $key['name'] . ' = ' . $key['value'] . ';');
         }
     }
     $arr_color = $ttH->load_data->data_table('product_color', 'color_id', 'color_id,color,title', "\tlang='" . $ttH->conf['lang_cur'] . "' order by show_order desc, date_create desc");
     $arr_size = $ttH->load_data->data_table('product_size', 'size_id', 'size_id,title', "\tlang='" . $ttH->conf['lang_cur'] . "' order by show_order desc, date_create desc");
     $err = '';
     /*print_arr($ttH->input); 
     		print_arr($arr_cart); */
     //die();
     if (isset($item_id)) {
         $item_id = $item_id > 0 ? $item_id : 0;
         $color = isset($color) ? $color : 0;
         $size = isset($size) ? $size : 0;
         //$code_pic = (isset($ttH->input['code_pic'])) ? $ttH->input['code_pic'] : 0;
         $quantity = isset($quantity) && $quantity > 0 ? $quantity : 1;
         if ($item_id > 0) {
             $cart_id = md5($item_id . '_c' . $color . '_s' . $size);
             //$cart_id = md5($item_id.'_c'.$color.'_cp'.$code_pic);
             $arr_tmp = array('item_id' => $item_id, 'color' => $color, 'size' => $size, 'quantity' => $quantity);
             $check_quantity = isset($arr_cart[$cart_id]['quantity']) ? $arr_cart[$cart_id]['quantity'] + $quantity : $quantity;
             $num_max = $ttH->site_func->check_in_stock(array('type_id' => $item_id), array('size_id' => $size));
             if ($num_max < $check_quantity) {
                 if ($size > 0) {
                     $err = $ttH->html->html_alert(str_replace(array('{item}', '{num_has}', '{size}'), array('{product_' . $item_id . '}', $num_max, $arr_size[$size]['title']), $ttH->lang['global']['err_in_stock_size']), 'warning');
                 } else {
                     $err = $ttH->html->html_alert(str_replace(array('{item}', '{num_has}'), array('{product_' . $item_id . '}', $num_max), $ttH->lang['global']['err_in_stock']), 'warning');
                 }
                 $quantity = 0;
                 if (isset($arr_cart[$cart_id])) {
                     $arr_cart[$cart_id]['quantity'] = $arr_tmp['quantity'];
                 } else {
                     $arr_tmp['quantity'] = $num_max;
                 }
             }
             $arr_cart_list_pro[$item_id] = $item_id;
             if (isset($arr_cart[$cart_id])) {
                 $arr_cart[$cart_id]['quantity'] += $quantity;
             } else {
                 $arr_cart[$cart_id] = $arr_tmp;
             }
             $arr_cart = Session::set('cart_pro', $arr_cart);
             $arr_cart_list_pro = Session::set('cart_list_pro', $arr_cart_list_pro);
             $link_go = $ttH->site_func->get_link_popup('product', 'cart');
             $ttH->html->redirect_rel($link_go);
         }
     }
     if (count($arr_cart) <= 0) {
         $link_go = $ttH->site_func->get_link_popup('product', 'cart_empty');
         $ttH->html->redirect_rel($link_go);
     }
     /*print_arr($arr_cart);
     		print_arr($arr_cart_list_pro);
     		print_arr($gift_voucher);
     		print_arr($ttH->input);*/
     //die('aaa');
     $arr_pro = array();
     $sql = "select *\r\r\n\t\t\t\t\t\tfrom product \r\r\n\t\t\t\t\t\twhere is_show=1 \r\r\n\t\t\t\t\t\tand find_in_set(item_id,'" . @implode(',', $arr_cart_list_pro) . "')>0 \r\r\n\t\t\t\t\t\torder by show_order desc, date_create asc";
     //echo $sql;
     $result = $ttH->db->query($sql);
     $html_row = "";
     while ($row = $ttH->db->fetch_row($result)) {
         $arr_pro[$row['item_id']] = $row;
         if (isset($ttH->input['item_id']) && $ttH->input['item_id'] == $row['item_id'] && !empty($err)) {
             $err = str_replace('{product_' . $ttH->input['item_id'] . '}', $row['title'], $err);
         }
     }
     $data = array();
     $data['cart_total'] = 0;
     if (is_array($arr_cart) && count($arr_cart > 0)) {
         foreach ($arr_cart as $cart_id => $row) {
             $row_pro = isset($row['item_id']) ? $arr_pro[$row['item_id']] : array();
             $row['cart_id'] = $cart_id;
             $row['pic_w'] = 50;
             $row['pic_h'] = 50;
             $row['picture'] = isset($row_pro['picture']) ? $row_pro['picture'] : '';
             $row["picture"] = $ttH->func->get_src_mod($row["picture"], $row['pic_w'], $row['pic_h'], 1, 0, array('fix_max' => 1));
             if (isset($row_pro['price_s'])) {
                 $row['price_buy'] = $row_pro['price_s'];
             } elseif (isset($row_pro['price_l'])) {
                 $row['price_buy'] = $row_pro['price_l'];
             } else {
                 $row['price_buy'] = 0;
             }
             $row['title'] = isset($row_pro['title']) ? $row_pro['title'] : '';
             $row['quantity'] = isset($row['quantity']) ? $row['quantity'] : 0;
             $row['total'] = $row['quantity'] * $row['price_buy'];
             $data['cart_total'] += $row['total'];
             $row['color'] = isset($row['color']) && array_key_exists($row['color'], $arr_color) ? $row['color'] : 0;
             $color = isset($arr_color[$row['color']]['color']) ? '<div><span class="color" style="background:' . $arr_color[$row['color']]['color'] . ';">&nbsp;</span></div>' : '';
             $row['color'] = isset($arr_color[$row['color']]['title']) ? $color . $arr_color[$row['color']]['title'] : '';
             $row['size'] = isset($row['size']) && array_key_exists($row['size'], $arr_size) ? $row['size'] : 0;
             $row['size'] = isset($arr_size[$row['size']]['title']) ? $arr_size[$row['size']]['title'] : '';
             $row['price_buy_text'] = $ttH->func->get_price_format($row['price_buy']);
             $row['quantity_text'] = list_quantity('quantity[]', $row['quantity'], ' for="' . $cart_id . '" class="quantity" onchange="ttHOrdering.cart_update(\'form_cart\');"');
             $row['total'] = $ttH->func->get_price_format($row['total']);
             $ttH->temp_act->assign('row', $row);
             $ttH->temp_act->parse("table_cart.row_item");
         }
     } else {
         $ttH->temp_act->assign('row', array('mess' => $ttH->lang['product']['no_have_item']));
         $ttH->temp_act->parse("table_cart.row_empty");
     }
     //promotion
     $err_promotion = '';
     $promotion_percent = 0;
     $promotion_code = isset($ttH->input['promotional_code']) ? $ttH->input['promotional_code'] : Session::get('promotion_code');
     /*if($data['cart_total'] >=isset( $ttH->setting)? $ttH->setting['voucher']['min_cart_promotion'] :1) {
     			if(!empty($promotion_code)) {
     				$sql = "select * 
     								from promotion 
     								where is_show=1 
     								and percent>0 
     								and percent<100 
     								and promotion_id='".$promotion_code."'";
     				//echo $sql;
     				$result = $ttH->db->query($sql);
     				if ($row_promotion = $ttH->db->fetch_row($result)) {
     					if(!empty($row_promotion['order_id'])) {
     						$err_promotion = $ttH->lang['product']['err_promotion_order'];
     					} elseif(time() > $row_promotion['date_end']) {
     						$err_promotion = $ttH->lang['product']['err_promotion_date_end'];
     					} else {
     						$promotion_percent = $row_promotion['percent'];
     						$gift_promotion = Session::set ('promotion_code', $row_promotion['promotion_id']);
     					}
     				} else {
     					Session::set ('promotion_code', '');
     				}
     			}
     			$promotion_code = Session::get('promotion_code');
     		} elseif(!empty($promotion_code)) {
     			$err_promotion = str_replace('{min_cart}',$ttH->func->get_price_format($ttH->setting['voucher']['min_cart_promotion'], 0),$ttH->lang['global']['err_promotion_min_cart']);
     			Session::set ('promotion_code', '');
     		}*/
     //End promotion
     //voucher
     $err_voucher = '';
     $voucher_amount_has = 0;
     $gift_voucher = isset($ttH->input['gift_voucher']) ? $ttH->input['gift_voucher'] : Session::get('gift_voucher');
     if (!empty($gift_voucher)) {
         $sql = "select * \r\r\n\t\t\t\t\t\t\tfrom voucher \r\r\n\t\t\t\t\t\t\twhere is_show=1 \r\r\n\t\t\t\t\t\t\tand voucher_id='" . $gift_voucher . "'";
         //echo $sql;
         $result = $ttH->db->query($sql);
         if ($row_voucher = $ttH->db->fetch_row($result)) {
             if ($row_voucher['amount'] <= $row_voucher['amount_use']) {
                 $err_voucher = $ttH->lang['product']['err_gift_voucher_no_amount'];
             } elseif (time() > $row_voucher['date_end']) {
                 $err_voucher = $ttH->lang['product']['err_gift_voucher_date_end'];
             } else {
                 $voucher_amount_has = $row_voucher['amount'] - $row_voucher['amount_use'];
                 $gift_voucher = Session::set('gift_voucher', $row_voucher['voucher_id']);
             }
         } else {
             Session::set('gift_voucher', '');
         }
     }
     $gift_voucher = Session::get('gift_voucher');
     //End voucher
     $data['cart_payment'] = $data['cart_total'];
     if ($promotion_percent > 0 && $promotion_percent < 100) {
         $data['cart_payment'] = (100 - $promotion_percent) / 100 * $data['cart_payment'];
     }
     $voucher_amount_has_out = $voucher_amount_has;
     if ($voucher_amount_has > $data['cart_payment']) {
         $voucher_amount_has_out = $data['cart_payment'];
         $data['cart_payment'] = 0;
     } else {
         $data['cart_payment'] -= $voucher_amount_has;
     }
     $data['cart_total'] = $ttH->func->get_price_format($data['cart_total'], 0);
     //$data['min_cart_promotion'] = $ttH->setting['voucher']['min_cart_promotion'];
     $data['promotion_percent'] = $promotion_percent;
     $data['voucher_amount'] = $voucher_amount_has;
     $data['voucher_amount_out'] = $ttH->func->get_price_format($voucher_amount_has_out, 0);
     $data['cart_payment'] = $ttH->func->get_price_format($data['cart_payment'], 0);
     if (isset($ttH->is_popup)) {
         $data['link_action'] = $ttH->site_func->get_link_popup($this->modules, $this->action);
         $data['link_ordering_address'] = $ttH->site_func->get_link_popup($this->modules, 'ordering_address');
         $data['link_buy_more'] = '#';
     } else {
         $data['link_action'] = $ttH->site->get_link($this->modules, $ttH->setting[$this->modules]['ordering_friendly_link'], $ttH->setting[$this->modules]['ordering_cart_link']);
         $data['link_ordering_address'] = $ttH->site->get_link($this->modules, $ttH->setting[$this->modules]['ordering_friendly_link'], $ttH->setting[$this->modules]['ordering_address_link']);
         $data['link_buy_more'] = $ttH->site->get_link($this->modules);
     }
     $data['err'] = $err;
     $data['err_promotion'] = !empty($err_promotion) ? '<div class="error">' . $err_promotion . '</div>' : '';
     $data['err_voucher'] = !empty($err_voucher) ? '<div class="error">' . $err_voucher . '</div>' : '';
     $ttH->temp_act->assign('data', $data);
     $ttH->temp_act->parse("table_cart");
     return $ttH->temp_act->text("table_cart");
 }
コード例 #2
0
ファイル: detail.php プロジェクト: duonghoaikhanh/hondabac
 function do_detail($info = array(), $info_lang = array())
 {
     global $ttH;
     $ttH->func->include_css($ttH->dir_skin . 'js/jcarousel-master/connected-carousels/product.css');
     $ttH->func->include_js($ttH->dir_skin . 'js/jcarousel-master/dist/jquery.jcarousel.min.js');
     $ttH->func->include_js($ttH->dir_skin . 'js/jcarousel-master/connected-carousels/jcarousel.connected-carousels.js');
     $data = array_merge($info, $info_lang);
     $data["link_action"] = $ttH->site->get_link('product', '', $info_lang['friendly_link']);
     //$data["link_cart"] = $ttH->site->get_link ('product',$ttH->setting['product']['ordering_friendly_link'],$ttH->setting['product']['ordering_cart_link']).'/?item_id='.$data['item_id'];
     $data["link_cart"] = $ttH->site_func->get_link_popup('product', 'cart', array('item_id' => $data['item_id']));
     $data["img_detail"] = $this->pic_slide($data);
     $data["brand_name"] = get_brand_name($info["brand_id"], 'link');
     $data["group_name"] = get_group_name($info["group_id"], 'link');
     $data["price"] = $ttH->func->get_price_format($info["price_s"]);
     $data["price_buy"] = $ttH->func->get_price_format($info["price_l"]);
     $data["price_s"] = $ttH->func->get_price_format($info["price_s"]);
     if ($info["price"] > $info["price_buy"] && $info["price_buy"] > 0) {
         $ttH->temp_act->assign('price', $data['price']);
         $ttH->temp_act->parse("detail.info_row_price");
     }
     if ($info["made_country"] != "") {
         $ttH->temp_act->assign('made_country', $info['made_country']);
         $ttH->temp_act->parse("detail.made_country");
     }
     if ($info["price_s"] > 0) {
         $ttH->temp_act->assign('price_s', $info['price_s']);
         $ttH->temp_act->parse("detail.price_s");
     }
     if ($info["price_l"] > 0) {
         $ttH->temp_act->assign('price_l', $info['price_l']);
         $ttH->temp_act->parse("detail.price_l");
     }
     if ($info["quantity"] != "") {
         $ttH->temp_act->assign('quantity', $info['quantity']);
         $ttH->temp_act->parse("detail.quantity");
     }
     $sql = "select option_id,title  \n\n\t\t\t\t\t\tfrom product_option \n\n\t\t\t\t\t\twhere is_show=1 \n\n\t\t\t\t\t\tand lang= '" . $ttH->conf['lang_cur'] . "'\n\n\t\t\t\t\t\torder by show_order desc, date_create asc";
     //echo $sql;
     $result = $ttH->db->query($sql);
     $html_row = "";
     while ($row = $ttH->db->fetch_row($result)) {
         if (isset($data['arr_option'][$row['option_id']])) {
             $row['content'] = $data['arr_option'][$row['option_id']];
             $ttH->temp_act->assign('row', $row);
             $ttH->temp_act->parse("detail.info_row");
         }
     }
     $data["list_color"] = list_color($info["item_id"], $info["list_color"]);
     if (!empty($data["list_color"])) {
         $row = array();
         $row['info_row_class'] = 'list_color';
         $row['title'] = $ttH->lang['product']['color'];
         $row['content'] = $data["list_color"];
         $ttH->temp_act->assign('row', $row);
         $ttH->temp_act->parse("detail.info_row");
     }
     $data["list_size"] = list_size($info["item_id"], $info["list_size"]);
     if (!empty($data["list_size"])) {
         $row = array();
         $row['info_row_class'] = 'list_size';
         $row['title'] = $ttH->lang['product']['size'];
         $row['content'] = $data["list_size"];
         $ttH->temp_act->assign('row', $row);
         $ttH->temp_act->parse("detail.info_row");
     }
     //$data["list_combine"] = list_combine ($info["item_id"]);
     /*$data["list_code_pic"] = list_code_pic ($info["item_id"], $info["list_code_pic"]);
     
     		if(!empty($data["list_code_pic"])) {
     
     			$row = array();
     
     			$row['title'] = $ttH->lang['product']['code_pic'];
     
     			$row['content'] = $data["list_code_pic"];
     
     			$ttH->temp_act->assign('row', $row);
     
     			$ttH->temp_act->parse("detail.info_row");
     
     		}*/
     $data["link_cart"] = $ttH->site_func->get_link_popup('product', 'cart');
     $data["list_quantity"] = list_quantity('quantity', 1, ' class="quantity"');
     $ttH->temp_act->assign('data', $data);
     $ttH->temp_act->parse("detail.btn_add_cart");
     /*$arr_order_method = $ttH->load_data->data_table ('order_method', 'method_id', 'method_id,name_action,title', "is_show=1 and lang='".$ttH->conf['lang_cur']."' order by show_order desc, date_create desc");
     
     		$data['order_method'] = '';
     
     		foreach($arr_order_method as $k => $v) {
     
     			$data['order_method'] .= '<li>'.$v['title'].'</li>';
     
     		}
     
     		if($data['order_method']) {
     
     			$data['order_method'] = '<ul class="list_none order_method-list">'.$data['order_method'].'</ul>';
     
     			$ttH->temp_act->assign('order_method', $data['order_method']);
     
     			$ttH->temp_act->parse("detail.order_method");
     
     		}*/
     $arr_content = array('content', 'content1', 'content2', 'content3', 'content4', 'content5');
     $has_content = 0;
     $index = 10;
     foreach ($arr_content as $k) {
         if ($data[$k]) {
             $index--;
             $has_content = 1;
             $ttH->temp_act->assign('tab', array('key' => $k, 'index' => $index, 'title' => $ttH->lang['product'][$k]));
             $ttH->temp_act->parse("detail.tab.title");
             $ttH->temp_act->assign('tab', array('key' => $k, 'content' => $data[$k]));
             $ttH->temp_act->parse("detail.tab.content");
         }
     }
     if ($has_content == 1) {
         $ttH->temp_act->parse("detail.tab");
     }
     $data['navigation'] = $ttH->navigation;
     $data['date_update'] = date('d-m-Y', $data['date_update']);
     //$data['other'] = list_other (" and a.item_id!='".$data['item_id']."'");
     //$data['other'] = $this->do_other ($data);
     $ttH->temp_act->assign('data', $data);
     $ttH->temp_act->parse("detail");
     return $ttH->temp_act->text("detail");
     $nd = array('title' => $data['title'], 'content' => $ttH->temp_act->text("detail"));
     return $ttH->html->temp_box("box_main", $nd);
 }