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;
 }
 private function setup()
 {
     if ($country = waRequest::post('country')) {
         if (!empty($this->countries[$country])) {
             $path = $this->getConfig()->getConfigPath('data/welcome/', false);
             $country_data = (include $path . "country_{$country}.php");
             # Main country setting
             $model = new waAppSettingsModel();
             $model->set('shop', 'country', $country);
             #currency
             if (!empty($country_data['currency'])) {
                 $currency_model = new shopCurrencyModel();
                 $sort = 0;
                 foreach ($country_data['currency'] as $code => $rate) {
                     // delete old currency info is exists
                     $currency_model->deleteById($code);
                     $currency_model->insert(array('code' => $code, 'rate' => $rate, 'sort' => $sort++), 2);
                     if ($sort == 1) {
                         $model->set('shop', 'currency', $code);
                     }
                 }
             }
             #taxes
             if (!empty($country_data['taxes'])) {
                 foreach ($country_data['taxes'] as $tax_data) {
                     shopTaxes::save($tax_data);
                 }
             }
             #custom code
             $function = 'shopWelcome' . ucfirst($country);
             if (function_exists($function)) {
                 try {
                     call_user_func_array($function, array());
                 } catch (Exception $ex) {
                     //TODO
                 }
             }
         }
     }
     if (!empty($this->types)) {
         $type_model = new shopTypeModel();
         $type_features_model = new shopTypeFeaturesModel();
         $types = waRequest::post('types');
         if (empty($types)) {
             if (!$type_features_model->countAll()) {
                 $types[] = 'default';
             }
         }
         if ($types) {
             foreach ($types as $type) {
                 $type_model->insertTemplate($type);
             }
         }
     }
     $set_model = new shopSetModel();
     $set_model->add(array('id' => 'promo', 'name' => _w('Featured on homepage'), 'type' => shopSetModel::TYPE_STATIC));
     $set_model->add(array('id' => 'bestsellers', 'name' => _w('Bestsellers'), 'type' => shopSetModel::TYPE_DYNAMIC, 'count' => 8, 'rule' => 'rating DESC'));
     // notifications
     $notifications_model = new shopNotificationModel();
     if ($notifications_model->countAll() == 0) {
         $notifications_action = new shopSettingsNotificationsAddAction();
         $notifications = $notifications_action->getTemplates();
         $params_model = new shopNotificationParamsModel();
         $events = $notifications_action->getEvents();
         foreach ($notifications as $event => $n) {
             if ($event == 'order') {
                 continue;
             }
             $data = array('name' => $events[$event]['name'] . ' (' . _w('Customer') . ')', 'event' => $event, 'transport' => 'email', 'status' => 1);
             $id = $notifications_model->insert($data);
             $params = $n;
             $params['to'] = 'customer';
             $params_model->save($id, $params);
             if ($event == 'order.create') {
                 $data['name'] = $events[$event]['name'] . ' (' . _w('Store admin') . ')';
                 $id = $notifications_model->insert($data);
                 $params['to'] = 'admin';
                 $params_model->save($id, $params);
             }
         }
     }
     /* !!! import commented out on welcome screen
        switch (waRequest::post('import')) {
        case 'demo':
        //TODO create demoproducts
        $this->redirect('?action=products');
        break;
        case 'migrate':
        $plugins = $this->getConfig()->getPlugins();
        if (empty($plugins['migrate'])) {
        $url = $this->getConfig()->getBackendUrl(true).'installer/?module=update&action=manager&install=1&app_id[shop/plugins/migrate]=webasyst';
        } else {
        $url = '?action=importexport#/migrate/';
        }
        $this->redirect($url);
        break;
        case 'scratch':
        default: */
     $this->redirect('?action=products#/welcome/');
     //        break;
     //}
 }