Пример #1
0
 /**
  * 通过 attributeoption_id 判断该 attributeoption 当前是否正在被关联
  * @param  int || array $attributeoption_id 规格项ID或ID数组
  * @return bool
  */
 public function is_relation_by_attribute_value_id($attributeoption_id)
 {
     // 初始化默认查询条件
     $request_struct = array('where' => array('attributeoption_id' => $attributeoption_id));
     // 判断与  product_attributeoption_relations 表的关联
     if (Product_attributeoption_relationService::get_instance()->count($request_struct)) {
         return TRUE;
     }
     // 判断与  product_attributeoption_productpic_relations 表的关联
     if (Product_attributeoption_productpic_relationService::get_instance()->count($request_struct)) {
         return TRUE;
     }
     return FALSE;
 }
Пример #2
0
 /**
  * 根据商品ID获取该商品的规格值与商品图片关联
  *
  * @param integer $product_id
  * @return array
  */
 public static function get_pdt_attroptpicrs($product_id)
 {
     $attroptpicrs = array();
     $records = Product_attributeoption_productpic_relationService::get_instance()->index(array('where' => array('product_id' => $product_id)));
     if (!empty($records)) {
         foreach ($records as $record) {
             isset($attroptpicrs[$record['attribute_id']]) or $attroptpicrs[$record['attribute_id']] = array();
             isset($attroptpicrs[$record['attribute_id']][$record['attributeoption_id']]) or $attroptpicrs[$record['attribute_id']][$record['attributeoption_id']] = array();
             if (!in_array($record['productpic_id'], $attroptpicrs[$record['attribute_id']][$record['attributeoption_id']])) {
                 $attroptpicrs[$record['attribute_id']][$record['attributeoption_id']][] = $record['productpic_id'];
             }
         }
     }
     return $attroptpicrs;
 }
Пример #3
0
 /**
  * 通过 attributeoption_id 判断该 attributeoption 当前是否正在被关联
  * @param  int || array $attributeoption_ids 规格项ID或ID数组
  * @return bool
  * @throws MyRuntimeException
  */
 public function is_relation_by_attributeoption_id($attributeoption_ids)
 {
     try {
         // 初始化默认查询条件
         $request_struct = array('where' => array('attributeoption_id' => $attributeoption_ids));
         // 判断与 goods_attributeoption_relations 表的关联
         if (Goods_attributeoption_relationService::get_instance()->count($request_struct)) {
             return TRUE;
         }
         // 判断与  product_attributeoption_relations 表的关联
         if (Product_attributeoption_relationService::get_instance()->count($request_struct)) {
             return TRUE;
         }
         // 判断与  product_attributeoption_productpic_relations 表的关联
         if (Product_attributeoption_productpic_relationService::get_instance()->count($request_struct)) {
             return TRUE;
         }
     } catch (MyRuntimeException $ex) {
         throw $ex;
     }
     return FALSE;
 }
Пример #4
0
 public function set_attroptpicrs()
 {
     $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['product_id'])) {
             $product_id = $request_data['product_id'];
             //$product = BLL_Product::get($request_data['product_id']);
             ORM::factory('product_attributeoption_productpic_relation')->where('product_id', $product_id)->delete_all();
             if (!empty($request_data['picrels'])) {
                 if (!is_array($request_data['picrels'])) {
                     throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
                 }
                 $attributes = BLL_Product_Attribute::index(array('id' => array_keys($request_data['picrels'])));
                 if (count($request_data['picrels']) != count($attributes)) {
                     throw new MyRuntimeException(Kohana::lang('o_global.bad_request'), 403);
                 }
                 foreach ($request_data['picrels'] as $aid => $ors) {
                     foreach ($ors as $oid => $pids) {
                         if (isset($attributes[$aid]['options'][$oid])) {
                             if (!empty($pids)) {
                                 foreach (explode(',', $pids) as $pid) {
                                     //if (isset($product['pictures'][$pid])){
                                     Product_attributeoption_productpic_relationService::get_instance()->add(array('product_id' => $product_id, 'attribute_id' => $aid, 'attributeoption_id' => $oid, 'productpic_id' => $pid));
                                     //}
                                 }
                             }
                         }
                     }
                 }
             }
         }
         //* 补充&修改返回结构体 */
         $return_struct['status'] = 1;
         $return_struct['code'] = 200;
         $return_struct['msg'] = '';
         $return_struct['content'] = $return_data;
         //* 请求类型 */
         if ($this->is_ajax_request()) {
             // ajax 请求
             // json 输出
             $this->template->content = $return_struct;
         } else {
             // html 输出
             $this->template = new View('layout/commonblank_html');
             //* 模板输出 */
             $this->template->return_struct = $return_struct;
             $content = new View($this->package_name . '/' . $this->class_name . '/configurable/' . __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->attributes = $attributes;
             $this->template->content->site_id = $request_data['site_id'];
             $this->template->content->aids = $aids;
             //:: 当前应用专用数据
             $this->template->content->title = Kohana::config('site.name');
         }
         // end of request type determine
     } catch (MyRuntimeException $ex) {
         $this->_ex($ex, $return_struct, $request_data);
     }
 }