Пример #1
0
 /**
  * 显示编辑商品表单
  */
 public function edit()
 {
     // 初始化返回结构体
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         // 初始化返回数据
         $return_data = array();
         // 收集请求数据
         $request_data = $this->input->get();
         if (empty($request_data['id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400);
         }
         $product = BLL_Product::get($request_data['id']);
         if (empty($product['id'])) {
             throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 400);
         }
         // 分类列表默认关联第一个
         $categorys_tree = CategoryService::get_instance()->get_tree("<option value=\\\"\$id\\\" \$selected>\$spacer\$title</option>", $product['category_id']);
         $categories = CategoryService::get_instance()->query_assoc(array());
         $categories = tree::get_tree_array($categories);
         $classifies = ClassifyService::get_instance()->index(array('orderby' => array('id' => 'ASC')));
         $classify_content['features'] = $this->load_features($product['classify_id'], $product['fetuoptrs']);
         $classify_content['brands'] = $this->load_brands($product['classify_id'], $product['brand_id']);
         // 处理商品类型特定的模板区块
         $ptype_layout = NULL;
         switch ($product['type']) {
             case ProductService::PRODUCT_TYPE_ASSEMBLY:
                 throw new MyRuntimeException('Coming soon ...', 400);
                 //暂时不支持组合商品
                 $ptype_layout = new View($this->package_name . '/' . $this->class_name . '/assembly/layout');
                 break;
             case ProductService::PRODUCT_TYPE_CONFIGURABLE:
                 $ptype_layout = new View($this->package_name . '/' . $this->class_name . '/configurable/layout');
                 break;
             case ProductService::PRODUCT_TYPE_GOODS:
             default:
                 $ptype_layout = new View($this->package_name . '/' . $this->class_name . '/simple/layout');
                 break;
         }
         $ptype_layout->product = $product;
         $return_struct['content'] = array('product' => $product);
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View($this->package_name . '/' . $this->class_name . '/' . __FUNCTION__);
             //* 变量绑定 */
             $this->template->title = Kohana::config('site.name');
             $this->template->content = $content;
             //* 请求结构数据绑定 */
             $this->template->content->request_data = $request_data;
             //* 返回结构体绑定 */
             $this->template->content->return_struct = $return_struct;
             $this->template->content->categorys_tree = $categorys_tree;
             $this->template->content->categories = $categories;
             $this->template->content->classifies = $classifies;
             $this->template->content->classify_content = $classify_content;
             $this->template->content->ptype_layout = $ptype_layout;
             $this->template->content->listurl = isset($request_data['listurl']) ? $request_data['listurl'] : '';
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }