protected function _installStates($xml) { if (isset($xml->states->state)) { foreach ($xml->states->state as $data) { $attributes = $data->attributes(); if (!($id_state = State::getIdByName($attributes['name']))) { $state = new State(); $state->name = strval($attributes['name']); $state->iso_code = strval($attributes['iso_code']); $state->id_country = Country::getByIso(strval($attributes['country'])); $id_zone = (int) Zone::getIdByName(strval($attributes['zone'])); if (!$id_zone) { $zone = new Zone(); $zone->name = (string) $attributes['zone']; $zone->active = true; if (!$zone->add()) { $this->_errors[] = Tools::displayError('Invalid Zone name.'); return false; } $id_zone = $zone->id; } $state->id_zone = $id_zone; if (!$state->validateFields()) { $this->_errors[] = Tools::displayError('Invalid state properties.'); return false; } $country = new Country($state->id_country); if (!$country->contains_states) { $country->contains_states = 1; if (!$country->update()) { $this->_errors[] = Tools::displayError('Cannot update the associated country: ') . $country->name; } } if (!$state->add()) { $this->_errors[] = Tools::displayError('An error occurred while adding the state.'); return false; } } else { $state = new State($id_state); if (!Validate::isLoadedObject($state)) { $this->_errors[] = Tools::displayError('An error occurred while fetching the state.'); return false; } } } } return true; }
protected function _installStates($xml) { if (isset($xml->states->state)) { foreach ($xml->states->state as $data) { $attributes = $data->attributes(); if (!($id_state = State::getIdByName($attributes['name']))) { $state = new State(); $state->name = strval($attributes['name']); $state->iso_code = strval($attributes['iso_code']); $state->id_country = Country::getByIso(strval($attributes['country'])); $state->id_zone = (int) Zone::getIdByName(strval($attributes['zone'])); if (!$state->validateFields()) { $this->_errors[] = Tools::displayError('Invalid state properties.'); return false; } $country = new Country($state->id_country); if (!$country->contains_states) { $country->contains_states = 1; if (!$country->update()) { $this->_errors[] = Tools::displayError('Cannot update the associated country: ') . $country->name; } } if (!$state->add()) { $this->_errors[] = Tools::displayError('An error occurred while adding the state.'); return false; } } else { $state = new State($id_state); if (!Validate::isLoadedObject($state)) { $this->_errors[] = Tools::displayError('An error occurred while fetching the state.'); return false; } } // Add counties foreach ($data->county as $xml_county) { $county_attributes = $xml_county->attributes(); if (!($id_county = County::getIdCountyByNameAndIdState($county_attributes['name'], $state->id))) { $county = new County(); $county->name = $county_attributes['name']; $county->id_state = (int) $state->id; $county->active = 1; if (!$county->validateFields()) { $this->_errors[] = Tools::displayError('Invalid County properties'); return false; } if (!$county->save()) { $this->_errors[] = Tools::displayError('An error has occurred while adding the county'); return false; } } else { $county = new County((int) $id_county); if (!Validate::isLoadedObject($county)) { $this->_errors[] = Tools::displayError('An error occurred while fetching the county.'); return false; } } // add zip codes foreach ($xml_county->zipcode as $xml_zipcode) { $zipcode_attributes = $xml_zipcode->attributes(); $zipcodes = $zipcode_attributes['from']; if (isset($zipcode_attributes['to'])) { $zipcodes .= '-' . $zipcode_attributes['to']; } if ($county->isZipCodeRangePresent($zipcodes)) { continue; } if (!$county->addZipCodes($zipcodes)) { $this->_errors[] = Tools::displayError('An error has occurred while adding zipcodes'); return false; } } } } } return true; }
public static function installExternalCarrier($config) { $carrier = new Carrier(); $carrier->name = $config['name']; $carrier->id_tax = $config['id_tax']; $carrier->active = $config['active']; $carrier->deleted = $config['deleted']; $carrier->delay = $config['delay']; $carrier->shipping_handling = $config['shipping_handling']; $carrier->range_behavior = $config['range_behavior']; $carrier->is_module = $config['is_module']; $carrier->shipping_external = $config['shipping_external']; $carrier->external_module_name = $config['external_module_name']; $carrier->need_range = $config['need_range']; $languages = Language::getLanguages(true); foreach ($languages as $language) { if ($language['iso_code'] == 'fr') { $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']]; } if ($language['iso_code'] == 'en') { $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']]; } if ($language['iso_code'] == 'es') { $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']]; } } if ($carrier->add()) { $groups = Group::getGroups(true); foreach ($groups as $group) { Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_group` VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $group['id_group'] . '\')'); } $rangePrice = new RangePrice(); $rangePrice->id_carrier = $carrier->id; $rangePrice->delimiter1 = '0'; $rangePrice->delimiter2 = '10000'; $rangePrice->add(); $rangeWeight = new RangeWeight(); $rangeWeight->id_carrier = $carrier->id; $rangeWeight->delimiter1 = '0'; $rangeWeight->delimiter2 = '15'; $rangeWeight->add(); $id_zone = Zone::getIdByName('Europe'); Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'carrier_zone` VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $id_zone . '\')'); Db::getInstance()->Execute('INSERT INTO `' . _DB_PREFIX_ . 'delivery` (`id_carrier`, `id_range_price`, `id_range_weight`, `id_zone`, `price`) VALUES (\'' . (int) $carrier->id . '\',\'' . (int) $rangePrice->id . '\',NULL,\'' . (int) $id_zone . '\',\'' . (double) $config['price'] . '\'), (\'' . (int) $carrier->id . '\',NULL,\'' . (int) $rangeWeight->id . '\',\'' . (int) $id_zone . '\',\'' . (double) $config['price'] . '\')'); Configuration::updateValue('KIALASMALL_CARRIER_ID', (int) $carrier->id); //copy logo if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg')) { return false; } return true; } else { return false; } }
public static function installExternalCarrier($config) { $carrier = new Carrier(); $carrier->hydrate($config); $carrier->name = $config['name']; $carrier->id_zone = $config['id_zone']; $carrier->active = $config['active']; $carrier->deleted = $config['deleted']; $carrier->delay = $config['delay']; $carrier->shipping_handling = $config['shipping_handling']; $carrier->range_behavior = $config['range_behavior']; $carrier->is_module = $config['is_module']; $carrier->shipping_external = $config['shipping_external']; $carrier->external_module_name = $config['external_module_name']; $carrier->need_range = $config['need_range']; $carrier->setTaxRulesGroup($config['id_tax_rules_group'], true); $languages = Language::getLanguages(true); foreach ($languages as $language) { if ($language['iso_code'] == 'lv') { $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']]; } if ($language['iso_code'] == 'lt') { $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']]; } if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT'))) { $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']]; } } if ($carrier->add()) { $groups = Group::getGroups(true); foreach ($groups as $group) { Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) $carrier->id, 'id_group' => (int) $group['id_group']), 'INSERT'); } // $range_price = new RangePrice(); // $range_price->id_carrier = $carrier->id; // $range_price->delimiter1 = '0'; // $range_price->delimiter2 = '10000'; // $range_price->add(); // $range_weight = new RangeWeight(); // $range_weight->id_carrier = $carrier->id; // $range_weight->delimiter1 = '0'; // $range_weight->delimiter2 = '10000'; // $range_weight->add(); // Add weight ranges to carrier $rangePrices = array(); foreach ($config['ranges'] as $range) { $rangeWeight = new RangeWeight(); $rangeWeight->hydrate(array('id_carrier' => $carrier->id, 'delimiter1' => (double) $range['delimiter1'], 'delimiter2' => (double) $range['delimiter2'])); $rangeWeight->add(); // Save range ID and price and set it after the Zones have been added $rangePrices[] = array('id_range_weight' => $rangeWeight->id, 'price' => $range['price']); } // Update prices in delivery table for each range (need IDs) foreach ($rangePrices as $rangePrice) { $data = array('price' => $rangePrice['price']); $where = 'id_range_weight = ' . $rangePrice['id_range_weight']; Db::getInstance()->update('delivery', $data, $where); } // Add Europe for EVERY carrier range // Automatically creates rows in delivery table, price is 0 $id_zone_europe = Zone::getIdByName('Europe'); $carrier->addZone($id_zone_europe ? $id_zone_europe : 1); // Copy Logo if (!Tools::copy(dirname(__FILE__) . '/logo.png', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.png')) { return false; } DpdCarrierOptions::setCarrierOptions((int) $carrier->id, (int) $carrier->id, $config['type']); // Return ID Carrier return (int) $carrier->id; } return false; }
public function getContent() { if (!extension_loaded('soap') || !class_exists('SoapClient')) { return $this->displayError($this->l('SOAP extension should be enabled on your server to use this module.')); } $output = ''; $this->configured = Configuration::get('SEUR_Configured'); if (Tools::isSubmit('submitToDefault')) { $this->setDefaultWS(); } elseif (Tools::isSubmit('submitWebservices')) { $this->storeWS(); } elseif (Tools::isSubmit('submitConfiguration')) { $update_seur_carriers = array(); $delivery = Tools::getValue('seur_cod'); if (Module::isInstalled('seurcashondelivery') == false && $delivery) { $output .= $this->displayError($this->l('To enable Cash on delivery you must install the module "SEUR Cash on delivery".')); $delivery = '0'; } $sql_update_configuration_table = ' UPDATE `' . _DB_PREFIX_ . 'seur_configuration` SET `pos` =' . (int) Tools::getValue('pos', 1) . ', `international_orders` =' . (int) Tools::getValue('international_orders') . ', `seur_cod` =' . (int) $delivery . ', `notification_advice_radio` =' . (int) Tools::getValue('notification_advice_radio') . ', `notification_distribution_radio` =' . (int) Tools::getValue('notification_distribution_radio') . ', `print_type` =' . (int) Tools::getValue('print_type') . ', `pickup` =' . (int) Tools::getValue('pickup') . ', `advice_checkbox` =' . (int) (Tools::getValue('advice_checkbox') == 'on' ? 1 : 0) . ', `distribution_checkbox` =' . (int) (Tools::getValue('distribution_checkbox') == 'on' ? 1 : 0); if (Context::getContext()->shop->isFeatureActive()) { $sql_update_configuration_table .= ', `id_shop` =' . (int) $this->context->shop->id; } if (Tools::getValue('id_seur_carrier')) { $update_seur_carriers[] = array('id' => (int) Tools::getValue('id_seur_carrier'), 'type' => 'SEN'); } if (Tools::getValue('id_seur_carrier_canarias_m')) { $update_seur_carriers[] = array('id' => (int) Tools::getValue('id_seur_carrier_canarias_m'), 'type' => 'SCN'); } if (Tools::getValue('id_seur_carrier_canarias_48')) { $update_seur_carriers[] = array('id' => (int) Tools::getValue('id_seur_carrier_canarias_48'), 'type' => 'SCE'); } if (Tools::getValue('id_seur_carrier_pos')) { $update_seur_carriers[] = array('id' => (int) Tools::getValue('id_seur_carrier_pos'), 'type' => 'SEP'); } if (!empty($update_seur_carriers)) { SeurLib::updateSeurCarriers($update_seur_carriers); } $sql_update_configuration_table .= ' WHERE `id_seur_configuration` = 1'; $this->configured = 1; Configuration::updateValue('SEUR_Configured', 1); Configuration::updateValue('SEUR_REMCAR_CARGO', (double) Tools::getValue('contra_porcentaje')); Configuration::updateValue('SEUR_REMCAR_CARGO_MIN', (double) Tools::getValue('contra_minimo')); Configuration::updateValue('SEUR_PRINTER_NAME', Tools::getValue('printer_name') ? pSQL(Tools::getValue('printer_name')) : 'Generic / Text Only'); Configuration::updateValue('SEUR_FREE_WEIGTH', (double) Tools::getValue('peso_gratis')); Configuration::updateValue('SEUR_FREE_PRICE', (double) Tools::getValue('precio_gratis')); $seur_carriers = array(); foreach ($update_seur_carriers as $value) { $seur_carriers[$value['type']] = $value['id']; } $carrier_seur = new Carrier((int) $seur_carriers['SEN']); $carrier_pos = new Carrier((int) $seur_carriers['SEP']); if (Tools::getValue('international_orders') && SeurLib::getConfigurationField('international_orders') != Tools::getValue('international_orders') && SeurLib::getConfigurationField('tarifa') && Validate::isLoadedObject($carrier_seur)) { if (Tools::getValue('international_orders') && Tools::getValue('international_orders') == 1) { $carrier_seur->addZone((int) Zone::getIdByName('Europe')); $carrier_seur->save(); } elseif (Tools::getValue('international_orders') == 0) { $carrier_seur->deleteZone((int) Zone::getIdByName('Europe')); $carrier_seur->save(); } } if (in_array(Tools::getValue('pos'), array(0, 1)) == true && Validate::isLoadedObject($carrier_pos)) { $carrier_pos->active = (int) Tools::getValue('pos'); $carrier_pos->save(); } if (!Db::getInstance()->Execute($sql_update_configuration_table)) { $output .= $this->displayError($this->l('Cannot update.')); } else { $output .= $this->displayConfirmation($this->l('Configuration updated.')); } } elseif (Tools::isSubmit('submitLogin')) { $sqlUpdateDataTable = 'UPDATE `' . _DB_PREFIX_ . 'seur_merchant` SET `nif_dni` ="' . pSQL(Tools::strtoupper(Tools::getValue('nif_dni'))) . '", `name` ="' . pSQL(Tools::strtoupper(Tools::getValue('name'))) . '", `first_name` ="' . pSQL(Tools::strtoupper(Tools::getValue('first_name'))) . '", `franchise` ="' . (Tools::getValue('franchise') ? pSQL(Tools::getValue('franchise')) : pSQL(Tools::getValue('franchise_cfg'))) . '", `company_name` ="' . pSQL(Tools::strtoupper(Tools::getValue('company_name'))) . '", `street_type` ="' . pSQL(Tools::getValue('street_type')) . '", `street_name` ="' . pSQL(Tools::strtoupper(Tools::getValue('street_name'))) . '", `street_number` ="' . pSQL(Tools::getValue('street_number')) . '", ' . (Tools::getValue('staircase') ? '`staircase` ="' . pSQL(Tools::strtoupper(Tools::getValue('staircase'))) . '",' : ' ') . ' `floor` ="' . pSQL(Tools::getValue('floor')) . '", `door` ="' . pSQL(Tools::getValue('door')) . '", `post_code` ="' . (Tools::getValue('post_code') ? pSQL(Tools::getValue('post_code')) : pSQL(Tools::getValue('post_code_cfg'))) . '", `town` ="' . (Tools::getValue('town') ? pSQL(Tools::strtoupper(Tools::getValue('town'))) : pSQL(Tools::strtoupper(Tools::getValue('town_cfg')))) . '", `state` ="' . (Tools::getValue('state') ? pSQL(Tools::strtoupper(Tools::getValue('state'))) : pSQL(Tools::strtoupper(Tools::getValue('state_cfg')))) . '", `country` ="' . (Tools::getValue('country') ? pSQL(Tools::strtoupper(Tools::getValue('country'))) : pSQL(Tools::strtoupper(Tools::getValue('country_cfg')))) . '", `phone` ="' . (int) Tools::getValue('phone') . '", `ccc` ="' . (int) Tools::getValue('ccc_cfg') . '", `cit` ="' . (int) Tools::getValue('ci') . '", ' . (Tools::getValue('fax') ? '`fax` =' . (int) Tools::getValue('fax') . ',' : ' ') . ' `email` ="' . pSQL(Tools::strtolower(Tools::getValue('email'))) . '"'; if (Tools::getValue('user_cfg') && Tools::getValue('pass_cfg')) { $sqlUpdateDataTable .= ', `USER`="' . pSQL(Tools::strtolower(Tools::getValue('user_cfg'))) . '", `PASS`="' . pSQL(Tools::strtolower(Tools::getValue('pass_cfg'))) . '" '; } $sqlUpdateDataTable .= "WHERE `id_seur_datos` = 1;"; if (Tools::getValue('user_seurcom') && Tools::getValue('pass_seurcom')) { Configuration::updateValue('SEUR_WS_USERNAME', Tools::getValue('user_seurcom')); Configuration::updateValue('SEUR_WS_PASSWORD', Tools::getValue('pass_seurcom')); } if (!Db::getInstance()->Execute($sqlUpdateDataTable)) { $output .= $this->displayError($this->l('Database fail.')); } else { $output .= $this->displayConfirmation($this->l('Configuration updated.')); } $this->stateConfigured = 1; } elseif (Tools::isSubmit('submitWithRanges')) { if (Range::setRanges()) { $output .= $this->displayConfirmation($this->l('Prices configured correctly. ')); SeurLib::setConfigurationField('tarifa', 1); } $this->configured = 1; Configuration::updateValue('SEUR_Configured', 1); die(Tools::redirectAdmin($this->getModuleLink('AdminModules'))); } elseif (Tools::isSubmit('submitWithoutRanges')) { $this->configured = 1; Configuration::updateValue('SEUR_Configured', 1); } return $this->displayForm(); }
private static function createZones() { $id_provincia = Zone::getIdByName(SeurLib::$seur_zones[0]); if ($id_provincia) { self::$provincia = new Zone($id_provincia); self::$provincia->active = 1; } else { self::$provincia = new Zone(); self::$provincia->name = html_entity_decode(SeurLib::$seur_zones[0]); } $id_peninsula = Zone::getIdByName(SeurLib::$seur_zones[1]); if ($id_peninsula) { self::$peninsula = new Zone($id_peninsula); self::$peninsula->active = 1; } else { self::$peninsula = new Zone(); self::$peninsula->name = html_entity_decode(SeurLib::$seur_zones[1]); } $id_portugal = Zone::getIdByName(SeurLib::$seur_zones[2]); if ($id_portugal) { self::$portugal = new Zone($id_portugal); self::$portugal->active = 1; } else { self::$portugal = new Zone(); self::$portugal->name = html_entity_decode(SeurLib::$seur_zones[2]); } $id_baleares = Zone::getIdByName(SeurLib::$seur_zones[3]); if ($id_baleares) { self::$baleares = new Zone($id_baleares); self::$baleares->active = 1; } else { self::$baleares = new Zone(); self::$baleares->name = html_entity_decode(SeurLib::$seur_zones[3]); } $id_canarias = Zone::getIdByName(SeurLib::$seur_zones[4]); if ($id_canarias) { self::$canarias = new Zone($id_canarias); self::$canarias->active = 1; } else { self::$canarias = new Zone(); self::$canarias->name = html_entity_decode(SeurLib::$seur_zones[4]); } $id_ceuta_melilla = Zone::getIdByName(SeurLib::$seur_zones[5]); if ($id_ceuta_melilla) { self::$ceuta_melilla = new Zone($id_ceuta_melilla); self::$ceuta_melilla->active = 1; } else { self::$ceuta_melilla = new Zone(); self::$ceuta_melilla->name = html_entity_decode(SeurLib::$seur_zones[5]); } if (!self::$provincia->save() || !self::$peninsula->save() || !self::$portugal->save() || !self::$baleares->save() || !self::$canarias->save() || !self::$ceuta_melilla->save()) { return false; } return true; }