protected function processPostData($old_tax)
 {
     if (!waRequest::post()) {
         return $old_tax;
     }
     $tm = $this->tm;
     if (waRequest::post('delete')) {
         if ($old_tax['id']) {
             $tm->deleteById($old_tax['id']);
             $this->trm->deleteByField('tax_id', $old_tax['id']);
             $this->tzcm->deleteByField('tax_id', $old_tax['id']);
         }
         echo json_encode(array('status' => 'ok', 'data' => 'ok'));
         exit;
     }
     //
     // Prepare data for shopTaxes::save()
     //
     $tax_data = waRequest::post('tax');
     if (!is_array($tax_data)) {
         return $old_tax;
     }
     if (!empty($old_tax['id'])) {
         $tax_data['id'] = $old_tax['id'];
     }
     // countries
     $tax_data['countries'] = array();
     $tax_countries = waRequest::post('countries');
     // country global rate: iso3 => float
     if ($tax_countries && is_array($tax_countries)) {
         $tax_country_regions = waRequest::post('country_regions');
         // rates by region: iso3 => region_code => float
         if (!is_array($tax_country_regions)) {
             $tax_country_regions = array();
         }
         foreach ($tax_countries as $country_iso3 => $country_global_rate) {
             $tax_data['countries'][$country_iso3] = array('global_rate' => $country_global_rate);
             if (!empty($tax_country_regions[$country_iso3]) && is_array($tax_country_regions[$country_iso3])) {
                 $tax_data['countries'][$country_iso3]['regions'] = $tax_country_regions[$country_iso3];
             }
         }
     }
     // zip codes
     $tax_data['zip_codes'] = array();
     $zip_codes = waRequest::post('tax_zip_codes');
     $zip_rates = waRequest::post('tax_zip_rates');
     if (is_array($zip_codes) && is_array($zip_rates)) {
         foreach ($zip_codes as $i => $code) {
             if ($code) {
                 $tax_data['zip_codes'][$code] = ifset($zip_rates[$i], 0);
             }
         }
     }
     return shopTaxes::save($tax_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;
     //}
 }