php购物车处理逻辑
1 <?php 2 /** 3 * 我的购物车 4 */ 5 6 include 'init.php'; 7 8 $TEMPLATE['type'] = 'cart'; 9 $TEMPLATE['pageTitle'] = '我的购物车'; 10 11 $carts_list = $goods_list = array(); 12 foreach ($_COOKIE as $k => $v) { 13 if (strpos($k, 'mycarts_') === 0) { 14 $aid = intval($v); 15 $goods_id = intval(str_replace('mycarts_', '', $k)); 16 $goods_list[$goods_id] = $aid; 17 } 18 } 19 20 $active_model = new \model\Active(); 21 $goods_model = new \model\Goods(); 22 23 foreach ($goods_list as $goods_id => $aid) { 24 $goods_info = $goods_model->get($goods_id); 25 $active_info = $active_model->get($aid); 26 if ($goods_info && $active_info 27 && $goods_info['active_id'] == $aid 28 && $goods_info['sys_status'] === '1' 29 && $active_info['sys_status'] === '1' 30 && $active_info['time_begin'] < $now 31 && $active_info['time_end'] > $now 32 ) { 33 // 验证数据的正确性 34 $carts_list[$aid]['active'] = $active_info; 35 $carts_list[$aid]['goods'][] = $goods_info; 36 } 37 } 38 39 $TEMPLATE['carts_list'] = $carts_list; 40 41 include TEMPLATE_PATH . '/cart.php';
转载于tongpan.com