Beispiel #1
0
 /**
  * 使用商品模板创建一个新的商品
  * 
  * @return array
  */
 public static function get($site_id, $type = 0)
 {
     if (Product_templateService::get_instance()->is_template_exist($site_id)) {
         $template = Product_templateService::get_instance()->get_template_by_site($site_id);
         unset($template['id']);
         unset($template['create_timestamp']);
         unset($template['update_timestamp']);
         unset($template['descriptions']);
         $product = $template;
         $product['type'] = $type;
         $product['sku'] = strtoupper(uniqid());
     } else {
         $product = array('site_id' => $site_id, 'status' => 0, 'sku' => strtoupper(uniqid()), 'category_id' => 0, 'on_sale' => 1, 'type' => $type);
     }
     $product_id = ProductService::get_instance()->add($product);
     return BLL_Product::get($product_id);
 }
Beispiel #2
0
 public function set_product_template(&$request_data, &$product)
 {
     $p_t = isset($request_data['product']) ? $request_data['product'] : array();
     if (empty($p_t)) {
         throw new MyRuntimeException('服务器没有接收到模板设置的信息!', 400);
     }
     $template = array();
     //print_r($product);die();
     foreach ($p_t as $key => $value) {
         if ($value == 'on') {
             if ($key == 'product_featureoption_relation_struct') {
                 if (!empty($product['fetuoptrs'])) {
                     $template['product_featureoption_relation_struct'] = '{"items":' . json_encode($product['fetuoptrs']) . '}';
                     $str = ':';
                     foreach ($product['fetuoptrs'] as $key => $value) {
                         $str .= "{$key}:";
                     }
                     $template['product_feature_relation_struct'] = '{"items":"' . $str . '"}';
                 } else {
                     $template['product_featureoption_relation_struct'] = '';
                     $template['product_feature_relation_struct'] = '';
                 }
             }
             if (isset($product[$key])) {
                 $template[$key] = $product[$key];
             }
         }
     }
     if (isset($template['descsections'])) {
         $template['descsections'] = isset($product['descsections'][0]['content']) ? $product['descsections'][0]['content'] : '';
     }
     if (!isset($template['on_sale'])) {
         $template['on_sale'] = 1;
     }
     if (empty($template)) {
         throw new MyRuntimeException('没有勾选任何模板信息,模板更新失败!', 400);
     }
     $template_id = Product_templateService::get_instance()->is_template_exist($product['site_id']);
     if ($template_id > 0) {
         Product_templateService::get_instance()->set($template_id, $template);
         return 1;
     } else {
         $template['site_id'] = $product['site_id'];
         return Product_templateService::get_instance()->add($template);
     }
 }
Beispiel #3
0
 public function delete()
 {
     $return_struct = array('status' => 0, 'code' => 501, 'msg' => 'Not Implemented', 'content' => array());
     try {
         //* 初始化返回数据 */
         $return_data = array('assoc' => NULL, 'count' => 0);
         //* 收集请求数据 ==根据业务逻辑定制== */
         $request_data = $this->input->get();
         $site_ids = role::get_site_ids();
         if (empty($site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         $in_site_id = site::id();
         if (isset($request_data['site_id']) and $request_data['site_id'] === '0') {
             unset($request_data['site_id']);
         }
         if (isset($request_data['site_id']) and !in_array($request_data['site_id'], $site_ids)) {
             throw new MyRuntimeException(Kohana::lang('o_global.access_denied'), 403);
         }
         if ($in_site_id > 0) {
             $query_site_id = $in_site_id;
         } else {
             throw new MyRuntimeException(Kohana::lang('o_global.select_site'), 400);
         }
         $template_id = intval($request_data['template_id']);
         $template = Product_templateService::get_instance()->index(array('where' => array('id' => $template_id)));
         if (!empty($template)) {
             if ($template[0]['site_id'] == $query_site_id) {
                 ORM::factory('product_template')->where('id', $template_id)->delete_all();
             } else {
                 throw new MyRuntimeException('没有权限删除该商品模板!', 403);
             }
         } else {
             throw new MyRuntimeException('该模板不存在,或者已被删除!', 403);
         }
         //* 补充&修改返回结构体 */
         //* 补充&修改返回结构体 ==根据业务逻辑定制== */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '商品模板已经成功删除!';
         $return_struct['content'] = $return_data;
         $return_struct['action'] = array('type' => 'location', 'url' => !empty($request_data['listurl']) ? url::base() . $request_data['listurl'] : url::base() . $this->package_name . '/' . $this->class_name . '/' . 'index');
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View('info');
             //* 变量绑定 */
             $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->title = Kohana::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $return_struct['status'] = 0;
         $return_struct['code'] = $ex->getCode();
         $return_struct['msg'] = $ex->getMessage();
         //TODO 异常处理
         //throw $ex;
         if ($this->is_ajax_request()) {
             $this->template->content = $return_struct;
         } 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;
         }
     }
 }