$country->Currency = "ZMK"; $country->Locale = Translatable::get_current_locale(); $country->write(); } // write country ZW if (!SilvercartCountry::get()->filter("ISO2", "ZW")->exists()) { $country = new SilvercartCountry(); $country->ISO2 = "ZW"; $country->ISO3 = "ZWE"; $country->FIPS = "ZI"; $country->ISON = "716"; $country->Title = _t("SilvercartCountry.TITLE_ZW"); $country->Continent = "AF"; $country->Currency = "ZWL"; $country->Locale = Translatable::get_current_locale(); $country->write(); } $translatorsByPrio = i18n::get_translators(); foreach ($translatorsByPrio as $priority => $translators) { foreach ($translators as $name => $translator) { $adapter = $translator->getAdapter(); $languages = $adapter->getList(); foreach ($languages as $language) { $locale = i18n::get_locale_from_lang($language); if ($country->hasLanguage($locale)) { continue; } $data = $adapter->getMessages($language); foreach (SilvercartCountry::get() as $country) { $key = 'TITLE_' . strtoupper($country->ISO2); if (array_key_exists('SilvercartCountry.' . $key, $data)) {
/** * creates test configuration data on /dev/build or by adding test * configuration in ModelAdmin. * * @return bool * * @author Sebastian Diel <*****@*****.**> * @since 02.07.2011 */ public static function createTestConfiguration() { if (self::$enableTestData === true) { //create a carrier and an associated zone and shipping method $carrier = SilvercartCarrier::get()->first(); if (!$carrier) { self::createTestTaxRates(); $carrier = new SilvercartCarrier(); $carrier->Title = 'DHL'; $carrier->FullTitle = 'DHL International GmbH'; $carrier->write(); $carrierLanguages = array('en_GB' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'), 'en_US' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH'), 'de_DE' => array('Title' => 'DHL', 'FullTitle' => 'DHL International GmbH')); $locales = array('de_DE', 'en_GB', 'en_US'); $fallbackLocale = false; if (!in_array(Translatable::get_current_locale(), $locales)) { $locales[] = Translatable::get_current_locale(); $fallbackLocale = Translatable::get_current_locale(); } if ($fallbackLocale !== false) { $carrierLanguages[$fallbackLocale] = $carrierLanguages['en_US']; } foreach ($carrierLanguages as $locale => $attributes) { $languageObj = SilvercartCarrierLanguage::get()->filter(array('SilvercartCarrierID' => $carrier->ID, 'Locale' => $locale))->first(); if (!$languageObj) { $languageObj = new SilvercartCarrierLanguage(); $languageObj->Locale = $locale; $languageObj->SilvercartCarrierID = $carrier->ID; } foreach ($attributes as $attribute => $value) { $languageObj->{$attribute} = $value; } $languageObj->write(); } //relate carrier to zones $zoneDomestic = SilvercartZone::get()->first(); if (!$zoneDomestic) { $zones = array(array('en_GB' => 'Domestic', 'en_US' => 'Domestic', 'de_DE' => 'Inland'), array('en_GB' => 'EU', 'en_US' => 'European Union', 'de_DE' => 'EU')); $locales = array('de_DE', 'en_GB', 'en_US'); $fallbackLocale = false; if (!in_array(Translatable::get_current_locale(), $locales)) { $locales[] = Translatable::get_current_locale(); $fallbackLocale = Translatable::get_current_locale(); } if ($fallbackLocale !== false) { $zones[0][$fallbackLocale] = $zones[0]['en_US']; $zones[1][$fallbackLocale] = $zones[1]['en_US']; } foreach ($zones as $zone) { $zoneObj = new SilvercartZone(); $zoneObj->write(); $zoneObj->SilvercartCarriers()->add($carrier); $zoneObj->write(); foreach ($zone as $locale => $title) { $zoneLanguage = SilvercartZoneLanguage::get()->filter(array('SilvercartZoneID' => $zoneObj->ID, 'Locale' => $locale))->first(); if (!$zoneLanguage) { $zoneLanguage = new SilvercartZoneLanguage(); $zoneLanguage->SilvercartZoneID = $zoneObj->ID; $zoneLanguage->Locale = $locale; } $zoneLanguage->Title = $title; $zoneLanguage->write(); } } } //Retrieve the active country if exists $country = SilvercartCountry::get()->filter('Active', '1')->first(); if (!$country) { //Retrieve the country dynamically depending on the installation language $installationLanguage = i18n::get_locale(); $ISO2 = substr($installationLanguage, -2); $country = SilvercartCountry::get()->filter('ISO2', $ISO2)->first(); if (!$country) { $country = new SilvercartCountry(); $country->Title = 'Testcountry'; $country->ISO2 = $ISO2; $country->ISO3 = $ISO2; } $country->Active = true; $country->write(); } $zoneDomestic = DataObject::get_by_id('SilvercartZone', 1); $zoneDomestic->SilvercartCountries()->add($country); // create if not exists, activate and relate payment method $paymentMethod = SilvercartPaymentPrepayment::get()->first(); if (!$paymentMethod) { $paymentMethodHandler = new SilvercartPaymentMethod(); $paymentMethodHandler->requireDefaultRecords(); } $paymentMethod = SilvercartPaymentPrepayment::get()->first(); $paymentMethod->isActive = true; $orderStatusPending = SilvercartOrderStatus::get()->filter('Code', 'pending')->first(); if ($orderStatusPending) { $paymentMethod->orderStatus = $orderStatusPending->Code; } $paymentMethod->write(); $country->SilvercartPaymentMethods()->add($paymentMethod); // create a shipping method $shippingMethod = SilvercartShippingMethod::get()->first(); if (!$shippingMethod) { $shippingMethod = new SilvercartShippingMethod(); //relate shipping method to carrier $shippingMethod->SilvercartCarrierID = $carrier->ID; } $shippingMethod->isActive = 1; $shippingMethod->write(); $shippingMethod->SilvercartZones()->add($zoneDomestic); //create the language objects for the shipping method $shippingMethodTranslations = array('de_DE' => 'Paket', 'en_GB' => 'Package', 'en_US' => 'Package'); $locales = array('de_DE', 'en_GB', 'en_US'); $fallbackLocale = false; if (!in_array(Translatable::get_current_locale(), $locales)) { $locales[] = Translatable::get_current_locale(); $fallbackLocale = Translatable::get_current_locale(); } if ($fallbackLocale !== false) { $shippingMethodTranslations[$fallbackLocale] = $shippingMethodTranslations['en_US']; } foreach ($shippingMethodTranslations as $locale => $title) { $shippingMethodLanguage = SilvercartShippingMethodLanguage::get()->filter(array('Locale' => $locale, 'SilvercartShippingMethodID' => $shippingMethod->ID))->first(); if (!$shippingMethodLanguage) { $shippingMethodLanguage = new SilvercartShippingMethodLanguage(); $shippingMethodLanguage->Locale = $locale; $shippingMethodLanguage->SilvercartShippingMethodID = $shippingMethod->ID; } $shippingMethodLanguage->Title = $title; $shippingMethodLanguage->write(); } // create a shipping fee and relate it to zone, tax and shipping method $shippingFee = SilvercartShippingFee::get()->first(); if (!$shippingFee) { $shippingFee = new SilvercartShippingFee(); $shippingFee->MaximumWeight = '100000'; $shippingFee->UnlimitedWeight = true; $shippingFee->Price = new Money(); $shippingFee->Price->setAmount('3.9'); $shippingFee->Price->setCurrency('EUR'); } $shippingFee->SilvercartShippingMethodID = $shippingMethod->ID; $shippingFee->SilvercartZoneID = $zoneDomestic->ID; $higherTaxRate = SilvercartTax::get()->filter('Rate', '19')->first(); $shippingFee->SilvercartTaxID = $higherTaxRate->ID; $shippingFee->write(); return true; } } return false; }