public function getPageContent() { $ship_rules = GiveItShipping::getShippingRules(); $page_url = GiveIt::CURRENT_INDEX . Tools::getValue('token') . '&configure=' . Tools::getValue('configure') . '&menu=' . Tools::getValue('menu'); if ($id_shipping = Tools::getValue('edit_rule')) { $page_url .= '&edit_rule=' . $id_shipping; } $default_language = new Language((int) Configuration::get('PS_LANG_DEFAULT')); $this->context->smarty->assign(array('shipping_rules' => $ship_rules, 'page_url' => $page_url, 'default_language_notice' => $default_language->iso_code)); if (version_compare(_PS_VERSION_, '1.6', '>=')) { return $this->context->smarty->fetch(_GIVEIT_TPL_DIR_ . 'admin/shipping_prices_ps16.tpl'); } else { return $this->context->smarty->fetch(_GIVEIT_TPL_DIR_ . 'admin/shipping_prices.tpl'); } }
private function getShippingRules() { if (!self::$shipping_rules) { foreach (GiveItShipping::getShippingRules() as $rule) { self::$shipping_rules[] = array('id' => $rule['id_giveit_shipping'] . '_', 'name' => $rule['title'], 'iso_code' => $rule['iso_code'], 'price' => (int) (Tools::convertPrice($rule['price']) * 100), 'free_above' => (int) (Tools::convertPrice($rule['free_above']) * 100), 'tax_percent' => $rule['tax_percent']); } } }
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(); }