Example #1
0
 public function deleteByField($field, $value = null)
 {
     if (is_array($field)) {
         $items = $this->getByField($field, $this->id);
     } else {
         $items = $this->getByField($field, $value, $this->id);
     }
     $res = false;
     if ($ids = array_keys($items)) {
         $res = parent::deleteByField($this->id, $ids);
         if ($res) {
             $type_upselling_model = new shopTypeUpsellingModel();
             $type_upselling_model->deleteByField('feature_id', $ids);
             $params_model = new shopProductFeaturesModel();
             $params_model->deleteByField('feature_id', $ids);
             $types = $this->groupByValueType($items);
             foreach ($types as $type => $type_ids) {
                 if ($model = self::getValuesModel($type)) {
                     $model->deleteByField('feature_id', $type_ids);
                 }
             }
             $this->deleteByField('parent_id', $ids);
         }
     }
     return $res;
 }
 protected function saveUpSelling()
 {
     $value = waRequest::post('value');
     $this->type_model->updateById($this->type_id, array('upselling' => $value));
     $type_upselling_model = new shopTypeUpsellingModel();
     $type_upselling_model->deleteByField('type_id', $this->type_id);
     if ($value) {
         $rows = array();
         $data = waRequest::post('data', array());
         foreach ($data as $feature => $row) {
             if (!isset($row['feature'])) {
                 continue;
             }
             $rows[] = array('type_id' => $this->type_id, 'feature' => $feature, 'feature_id' => isset($row['feature_id']) ? $row['feature_id'] : null, 'cond' => $row['cond'], 'value' => isset($row['value']) ? is_array($row['value']) ? implode(',', $row['value']) : $row['value'] : '');
         }
         if ($rows) {
             $type_upselling_model->multipleInsert($rows);
         }
         $this->response['type_id'] = $this->type_id;
         $this->response['data'] = array('price' => array('feature' => 'price'), 'tag' => array('feature' => 'tag'), 'type_id' => array('feature' => 'type_id'));
         $type_features_model = new shopTypeFeaturesModel();
         $rows = $type_features_model->getByType($this->type_id);
         foreach ($rows as $row) {
             $this->response['data'][$row['code']] = array('feature' => $row['code'], 'feature_id' => $row['feature_id']);
         }
         $data = $type_upselling_model->getByType($this->type_id);
         foreach ($data as $row) {
             $this->response['data'][$row['feature']] = array('feature_id' => $row['feature_id'], 'feature' => $row['feature'], 'cond' => $row['cond'], 'value' => $row['value']);
         }
         $this->response['html'] = shopSettingsRecommendationsAction::getConditionHTML($data);
         $this->response['data'] = array_values($this->response['data']);
     }
 }