Example #1
0
 /**
  * 根据特性ID获取商品特性
  *
  * @param integer $feature_id
  * @return array
  */
 public static function get($feature_id)
 {
     $feature = FeatureService::get_instance()->get($feature_id);
     $feature = coding::decode_feature($feature);
     $options = FeatureoptionService::get_instance()->index(array('where' => array('feature_id' => $feature['id']), 'orderby' => 'order'));
     $feature['options'] = array();
     foreach ($options as $option) {
         unset($option['feature_id']);
         unset($option['order']);
         $feature['options'][$option['id']] = $option;
     }
     return $feature;
 }
Example #2
0
 /** 
  * 通过feature_id,特性数组,更新该 feature的选项 
  * @param  int $feature_id  特性ID 
  * @param  array $options  更新的特性数组 
  * @return bool 
  * @throws MyRuntimeException 
  */
 public function update_options($feature_id, $site_id, $options = array())
 {
     $oldoptions = $this->get_featureoptions_by_feature_id($feature_id);
     if (!empty($oldoptions)) {
         $del_ids = array();
         foreach ($oldoptions as $val) {
             if (!array_key_exists($val['id'], $options)) {
                 $del_ids[] = $val['id'];
             } else {
                 $set_data = $options[$val['id']];
                 FeatureoptionService::get_instance()->set($val['id'], $set_data);
             }
         }
         if (!empty($del_ids)) {
             FeatureoptionService::get_instance()->delete_by_featureoption_id($del_ids);
         }
     }
     if (!empty($options)) {
         foreach ($options as $key => $val) {
             if (!array_key_exists($key, $oldoptions)) {
                 $set_data = $options[$key];
                 $set_data['site_id'] = $site_id;
                 $set_data['feature_id'] = $feature_id;
                 FeatureoptionService::get_instance()->add($set_data);
             }
         }
     }
     $this->clear($feature_id);
 }