/**
  * 通过 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;
 }
 /**
  * 通过 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;
 }
示例#3
0
 /**
  * 通过商品ID获取商品与规格项的关联
  *
  * @param integer $product_id
  * @return array
  */
 protected static function get_pdt_attroptrs($product_id)
 {
     $attroptrs = array();
     $records = Product_attributeoption_relationService::get_instance()->index(array('where' => array('product_id' => $product_id)));
     if (!empty($records)) {
         foreach ($records as $record) {
             $attr_id = $record['attribute_id'];
             $opti_id = $record['attributeoption_id'];
             if (!isset($attroptrs[$attr_id])) {
                 $attroptrs[$attr_id] = array();
             }
             if (!in_array($opti_id, $attroptrs[$attr_id])) {
                 $attroptrs[$attr_id][] = $opti_id;
             }
         }
     }
     return $attroptrs;
 }
示例#4
0
 /**
  * 设置商品特性关联
  *
  * @param array $product
  * @return boolean
  */
 public static function set_fetuoptrs(&$product)
 {
     $fetuoptrs = isset($product['pdt_fetuoptrs']) ? $product['pdt_fetuoptrs'] : array();
     if ($product['classify_id'] > 0 && $fetuoptrs) {
         $product['product_featureoption_relation_struct'] = array();
         $features = self::get_clsfeturs($product['classify_id']);
         if ($features) {
             $rs = array();
             foreach ($fetuoptrs as $fetu_id => $opti_name) {
                 if (isset($features[$fetu_id])) {
                     $opti_name = trim($opti_name);
                     if (!empty($opti_name)) {
                         //输入项目
                         if ($features[$fetu_id]['type'] == 1) {
                             //组合商品属性保存
                             Product_attributeoption_relationService::get_instance()->add(array('apply' => AttributeService::ATTRIBUTE_FEATURE, 'product_id' => $product['id'], 'attribute_id' => $fetu_id, 'attributeoption_id' => '0', 'attribute_value' => $opti_name));
                             $rs[$fetu_id] = '0';
                         } else {
                             //选择项目
                             foreach ($features[$fetu_id]['options'] as $option) {
                                 if (strtolower(trim($option['name'])) === strtolower($opti_name)) {
                                     Product_attributeoption_relationService::get_instance()->add(array('apply' => AttributeService::ATTRIBUTE_FEATURE, 'product_id' => $product['id'], 'attribute_id' => $fetu_id, 'attributeoption_id' => $option['id'], 'attribute_value' => $opti_name));
                                     $rs[$fetu_id] = (string) $option['id'];
                                     break;
                                 }
                             }
                         }
                     }
                 }
             }
             if (!empty($rs)) {
                 $product_feature_relation_struct = json_encode(array('items' => array_keys($rs)));
                 $product_featureoption_relation_struct = json_encode(array('items' => $rs));
                 //更新商品数据
                 $data = array('id' => $product['id'], 'product_feature_relation_struct' => $product_feature_relation_struct, 'product_featureoption_relation_struct' => $product_featureoption_relation_struct, 'update_time' => time());
                 ProductService::get_instance()->update($data);
                 //更新货品数据
                 if (!empty($product['pdt_goods'])) {
                     foreach ($product['pdt_goods'] as $index => $good) {
                         $data = array('id' => $good['id'], 'product_feature_relation_struct' => $product_feature_relation_struct, 'product_featureoption_relation_struct' => $product_featureoption_relation_struct, 'update_time' => time());
                         ProductService::get_instance()->update($data);
                     }
                 }
             }
         }
     }
     return TRUE;
 }
示例#5
0
 /**
  * 通过商品ID获取商品与规格项的关联
  *
  * @param integer $product_id
  * @return array
  */
 protected static function get_pdt_attroptrs($product_id)
 {
     $attroptrs = array();
     $records = Product_attributeoption_relationService::get_instance()->index(array('where' => array('product_id' => $product_id, 'apply' => AttributeService::ATTRIBUTE_SPEC)));
     if (!empty($records)) {
         foreach ($records as $record) {
             $attroptrs[$record['attribute_id']] = $record['attributeoption_id'];
         }
     }
     return $attroptrs;
 }
示例#6
0
 /**
  * 通过 attribute.id 判断该 attribute当前是否正在被关联
  * @param  int $attribute_id  规格ID
  * @return bool
  * @throws MyRuntimeException
  */
 public function is_relation_by_attribute_id($attribute_id)
 {
     // 获取 attribute 下所有的 attributeoption
     $attributeoptions = $this->get_attributeoptions_by_attribute_id($attribute_id);
     if (!empty($attributeoptions)) {
         // 获取所有 attributeoption 的 ID
         $attributeoption_ids = array_keys($attributeoptions);
         if (!empty($attributeoption_ids)) {
             // 初始化默认查询条件
             $request_struct = array('where' => array('attributeoption_id' => $attributeoption_ids));
             // 判断与  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;
             //}
         }
     }
     //判断与classify_attribute_relation 表的关联
     $request_struct = array('where' => array('attribute_id' => $attribute_id));
     if (Classify_attribute_relationService::get_instance()->count($request_struct)) {
         return TRUE;
     }
     return FALSE;
 }
示例#7
0
 public static function get_pdtattrrs($product_id, $type = '')
 {
     $pdtattrs = array();
     $qs = array('where' => array('product_id' => $product_id));
     if ($type) {
         $qs['where']['apply'] = $type;
     }
     $records = Product_attributeoption_relationService::get_instance()->index($qs);
     if (!empty($records)) {
         foreach ($records as $record) {
             if (!isset($pdtattrs[$record['attribute_id']])) {
                 $pdtattrs[$record['attribute_id']] = array();
             }
             $pdtattrs[$record['attribute_id']][] = $record['attributeoption_id'];
         }
         return $pdtattrs;
     }
 }