Ejemplo n.º 1
0
    private static function createCountries()
    {
        if (!Country::getByIso('ES') || !Country::getByIso('PT')) {
            if (!self::disableCountries()) {
                return false;
            }
            $modulos = SeurLib::getModulosPago();
            $values = array();
            $currency = Currency::getDefaultCurrency();
            /* ESPAÑA */
            if (!Country::getByIso('ES')) {
                self::$spain = new Country();
                self::$spain->name = array(1 => 'Spain', 2 => 'Espagne', 3 => 'España');
                self::$spain->id_zone = self::$peninsula->id;
                self::$spain->id_currency = $currency->id;
                self::$spain->iso_code = 'ES';
                self::$spain->contains_states = true;
                self::$spain->need_identification_number = true;
                if (!self::$spain->save()) {
                    return false;
                }
                foreach ($modulos as $modulo) {
                    $values[] = '(' . (int) $modulo->id . ', ' . (int) self::$spain->id . ')';
                }
                if (!empty($values)) {
                    Db::getInstance()->Execute('
						INSERT INTO ' . _DB_PREFIX_ . 'module_country (`id_module`, `id_country`) 
						VALUES ' . implode(',', $values));
                }
            }
            /* PORTUGAL */
            if (!Country::getByIso('PT')) {
                self::$portugal_country = new Country();
                self::$portugal_country->name = array(1 => 'Portugal', 2 => 'Portugal', 3 => 'Portugal');
                self::$portugal_country->id_zone = self::$portugal->id;
                self::$portugal_country->id_currency = $currency->id;
                self::$portugal_country->iso_code = 'PT';
                self::$portugal_country->contains_states = false;
                self::$portugal_country->need_identification_number = false;
                if (!self::$portugal_country->save()) {
                    return false;
                }
                foreach ($modulos as $modulo) {
                    $values[] = '(' . (int) $modulo->id . ', ' . (int) self::$portugal_country->id . ')';
                }
                if (!empty($values)) {
                    Db::getInstance()->Execute('
						INSERT INTO ' . _DB_PREFIX_ . 'module_country (`id_module`, `id_country`) 
						VALUES ' . implode(',', $values));
                }
            }
        } else {
            self::$spain = new Country((int) Country::getByIso('ES'));
            self::$spain->active = true;
            self::$spain->contains_states = true;
            if (!self::$spain->save()) {
                return false;
            }
            self::$portugal_country = new Country((int) Country::getByIso('PT'));
            self::$portugal_country->active = true;
            self::$portugal_country->id_zone = self::$portugal->id;
            if (!self::$portugal_country->save()) {
                return false;
            }
        }
        return true;
    }