Exemplo n.º 1
0
 private function displayShippingPricesPage()
 {
     $languages = Language::getLanguages(false);
     $countries = Country::getCountries($this->context->language->id);
     $zones = Zone::getZones(false);
     // add zones to the list and use zone_id as iso_code
     foreach (array_reverse($zones) as $zone) {
         array_unshift($countries, array('id_country' => $zone['id_zone'], 'iso_code' => $zone['id_zone'], 'name' => $zone['name']));
     }
     if (Tools::isSubmit('saveShippingData')) {
         Tools::safePostVars();
         $shipping = new GiveItShipping(Tools::getValue('edit_rule', null));
         $id_default_language = (int) Configuration::get('PS_LANG_DEFAULT');
         if (Tools::getValue('title_' . (int) $id_default_language) === '') {
             $this->html .= $this->displayError($this->l('Error. Please always provide a shippng method title for you default language.'));
         } else {
             foreach ($languages as $language) {
                 $shipping->title[$language['id_lang']] = pSQL(Tools::getValue('title_' . $language['id_lang']));
             }
             $shipping->price = pSQL(Tools::getValue('shipping_price'));
             $shipping->free_above = pSQL(Tools::getValue('free_above'));
             $shipping->tax_percent = pSQL(Tools::getValue('tax_percent'));
             $shipping->id_currency = $this->context->currency->id;
             $shipping->iso_code = pSQL(Tools::getValue('iso_code'));
             if (($error = $shipping->validateFields(false, true)) === true && ($error = $shipping->validateFieldsLang(false, true)) === true) {
                 if ($shipping->save()) {
                     $this->addFlashMessage($this->l('Shipping rule was successfully saved'));
                     Tools::redirectAdmin(self::CURRENT_INDEX . Tools::getValue('token') . '&menu=' . Tools::getValue('menu'));
                 } else {
                     $this->html .= $this->displayError($this->l('Error. Shipping rule could not be saved'));
                 }
             } else {
                 $this->html .= $this->displayError($error);
             }
         }
     }
     if ($id_shipping_rule = Tools::getValue('edit_rule')) {
         $shipping = new GiveItShipping((int) $id_shipping_rule);
         $this->context->smarty->assign('shipping', $shipping);
     }
     if ($id_shipping_rule = Tools::getValue('delete_rule')) {
         $shipping = new GiveItShipping((int) $id_shipping_rule);
         if ($shipping->delete()) {
             $this->addFlashMessage($this->l('Shipping rule was successfully deleted'));
             Tools::redirectAdmin(self::CURRENT_INDEX . Tools::getValue('token') . '&menu=' . Tools::getValue('menu'));
         } else {
             $this->html .= $this->displayError($this->l('Error. Shipping rule could not be deleted'));
         }
     }
     $this->context->smarty->assign(array('currency' => $this->context->currency, 'module' => $this, 'id_lang_default' => Configuration::get('PS_LANG_DEFAULT'), 'countries' => $countries, 'languages' => $languages));
     $view = new GiveItShippingPricesView($this);
     $this->html .= $view->getPageContent();
 }