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']); } }
public function execute() { if (!$this->getUser()->getRights('shop', 'settings')) { throw new waRightsException(_w('Access denied')); } $model = new shopTypeModel(); $data = array(); $data['id'] = waRequest::post('id', 0, waRequest::TYPE_INT); switch (waRequest::post('source', 'custom')) { case 'custom': $data['name'] = waRequest::post('name'); $data['icon'] = waRequest::post('icon_url', false, waRequest::TYPE_STRING_TRIM); if (empty($data['icon'])) { $data['icon'] = waRequest::post('icon', 'icon.box', waRequest::TYPE_STRING_TRIM); } if (!empty($data['id'])) { $model->updateById($data['id'], $data); } else { $data['sort'] = $model->select('MAX(sort)+1 as max_sort')->fetchField('max_sort'); $data['id'] = $model->insert($data); } break; case 'template': $data = $model->insertTemplate(waRequest::post('template'), true); break; } if ($data) { $data['icon_html'] = shopHelper::getIcon($data['icon'], 'icon.box'); $data['name_html'] = '<span class="js-type-icon">' . $data['icon_html'] . '</span> <span class="js-type-name">' . htmlspecialchars($data['name'], ENT_QUOTES, 'utf-8') . '</span>'; } $this->response = $data; }