/** * 设置商品的SEO信息 * * @param array $product * @return boolean */ public static function set(&$product) { $category = CategoryService::get_instance()->get($product['category_id']); $seo_inf = Seo_manageService::get_instance()->get_product_seo_struct(array('category_id' => $product['category_id'], 'product_name' => $product['title'], 'category_name' => $category['title'], 'goods_price' => $product['goods_price'])); empty($product['meta_title']) and $product['meta_title'] = $seo_inf['meta_title']; empty($product['meta_keywords']) and $product['meta_keywords'] = $seo_inf['meta_keywords']; empty($product['meta_description']) and $product['meta_description'] = $seo_inf['meta_description']; return TRUE; }
/** * 得到分类已经的SEO信息 */ public function get_category_product_seo() { $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array()); // 初始化返回数据 $return_data = array(); //请求结构体 $request_data = array(); try { /* 分类 */ $category_id = $this->input->get('category_id'); // 初始化默认查询条件 $query_struct = array('where' => array('category_id' => $category_id), 'like' => array(), 'orderby' => array('id' => 'DESC'), 'limit' => array('per_page' => 100, 'offset' => 0)); if ($category_id > 0) { //判断分类下面是否有子分类 $childrens = CategoryService::get_instance()->get_childrens_by_category_id($category_id); if (isset($childrens) && !empty($childrens)) { $is_contain_child = 1; } else { $is_contain_child = 0; } } else { $query_struct['where']['category_id'] = Seo_manageService::SEO_CATEGORY_IS_NULL; $is_contain_child = 0; } $seo_manage = Seo_manageService::get_instance()->query_assoc($query_struct); if (is_array($seo_manage) && count($seo_manage) > 0) { $return_struct['status'] = 1; $return_struct['code'] = 200; $return_data['data'] = $seo_manage; $return_struct['content'] = $return_data; $return_struct['is_contain_child'] = $is_contain_child; } //* 请求类型 */ if ($this->is_ajax_request()) { // ajax 请求 // json 输出 $this->template->content = $return_struct; } else { die('No direct access allowed.'); } // end of request type determine } catch (MyRuntimeException $ex) { $return_struct['status'] = 0; $return_struct['code'] = $ex->getCode(); $return_struct['msg'] = $ex->getMessage(); if ($this->is_ajax_request()) { $this->template = new View('layout/empty_html'); $this->template->content = $return_struct['msg']; } else { $this->template->return_struct = $return_struct; $content = new View('info'); $this->template->content = $content; /* 请求结构数据绑定 */ $this->template->content->request_data = $request_data; /* 返回结构体绑定 */ $this->template->content->return_struct = $return_struct; } } }