/**
  * executed if there are no valdation errors on submit
  * Form data is saved in session
  *
  * @param SS_HTTPRequest $data     contains the frameworks form data
  * @param Form           $form     not used
  * @param array          $formData contains the modules form data
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 15.11.2014
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $member = SilvercartCustomer::currentUser();
     $id = $formData['addressID'];
     if ($member && $id) {
         $filter = array("MemberID" => $member->ID, "ID" => $id);
         $address = SilvercartAddress::get()->filter($filter)->first();
         if ($address->canEdit()) {
             $address->castedUpdate($formData);
             $country = SilvercartCountry::get()->byID($formData['Country']);
             if ($country) {
                 $address->SilvercartCountryID = $country->ID;
             }
             $address->write();
         }
         $this->submitSuccess = true;
         if (Session::get("redirect")) {
             $this->controller->redirect(Session::get("redirect"));
             Session::clear("redirect");
         } else {
             $addressHolder = SilvercartPage_Controller::PageByIdentifierCode("SilvercartAddressHolder");
             $this->controller->redirect($addressHolder->RelativeLink());
         }
     }
 }
    $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)) {
                    $translation = new SilvercartCountryLanguage();
                    $translation->Locale = $locale;
                    $translation->Title = $data['SilvercartCountry.' . $key];
                    $translation->write();
                    $country->SilvercartCountryLanguages()->add($translation);
                }
            }
        }
    }
}
 /**
  * Returns a dropdown map sorted by prioritive countries
  * 
  * @param bool   $onlyActive  Search only for active coutries?
  * @param string $emptyString String to show for empty value
  * 
  * @return array
  */
 public static function getPrioritiveDropdownMap($onlyActive = true, $emptyString = null)
 {
     $key = 0;
     if ($onlyActive) {
         $key = 1;
     }
     if (!is_null($emptyString)) {
         $key .= md5($emptyString);
     }
     if (!array_key_exists($key, self::$prioritiveDropdownMap)) {
         $dropdownMap = array();
         if (!is_null($emptyString)) {
             $dropdownMap[''] = $emptyString;
         }
         if (self::getPrioritiveCountryCount() > 0) {
             $prioritiveCountries = self::getPrioritiveCountries($onlyActive);
             foreach ($prioritiveCountries->map()->toArray() as $id => $title) {
                 $dropdownMap[$id] = $title;
             }
         }
         if (self::getNonPrioritiveCountryCount() > 0) {
             if (is_null($emptyString) && count($dropdownMap) > 0 || !is_null($emptyString) && count($dropdownMap) > 1) {
                 $dropdownMap[' '] = '------------------------';
             }
             $nonPrioritiveCountries = self::getNonPrioritiveCountries($onlyActive);
             foreach ($nonPrioritiveCountries->map()->toArray() as $id => $title) {
                 $dropdownMap[$id] = $title;
             }
         }
         if (empty($dropdownMap) && SilvercartTools::isBackendEnvironment()) {
             $allCountries = SilvercartCountry::get();
             $dropdownMap = $allCountries->map()->toArray();
         }
         self::$prioritiveDropdownMap[$key] = $dropdownMap;
     }
     return self::$prioritiveDropdownMap[$key];
 }
 /**
  * Returns the free of shipping costs from value if specified.
  * 
  * @param SilvercartCountry $shippingCountry Shipping country
  *
  * @return Money
  *
  * @author Sascha Koehler <*****@*****.**>,
  *         Sebastian Diel <*****@*****.**>
  * @since 17.07.2013
  */
 public static function FreeOfShippingCostsFrom($shippingCountry = null)
 {
     self::$freeOfShippingCostsFrom = self::getConfig()->freeOfShippingCostsFrom;
     if (!$shippingCountry instanceof SilvercartCountry && Controller::curr()->hasMethod('getCombinedStepData')) {
         $checkoutData = Controller::curr()->getCombinedStepData();
         if (array_key_exists('Shipping_Country', $checkoutData)) {
             $shippingCountryID = $checkoutData['Shipping_Country'];
             $shippingCountry = SilvercartCountry::get()->byID($shippingCountryID);
         }
     }
     if ($shippingCountry && !is_null($shippingCountry->freeOfShippingCostsFrom->getAmount()) && is_numeric($shippingCountry->freeOfShippingCostsFrom->getAmount())) {
         $shippingCountry->freeOfShippingCostsFrom->getAmount();
         self::$freeOfShippingCostsFrom = $shippingCountry->freeOfShippingCostsFrom;
     }
     return self::$freeOfShippingCostsFrom;
 }
 /**
  * Set initial form values
  *
  * @return void
  *
  * @author Roland Lehmann <*****@*****.**>, Sebastian Diel <*****@*****.**>
  * @since 07.12.2012
  */
 protected function fillInFieldValues()
 {
     // --------------------------------------------------------------------
     // Set i18n labels
     // --------------------------------------------------------------------
     $this->formFields['InvoiceAddressAsShippingAddress']['title'] = _t('SilvercartAddress.InvoiceAddressAsShippingAddress');
     $this->formFields['Invoice_Salutation']['title'] = _t('SilvercartAddress.SALUTATION', 'salutation');
     $this->formFields['Invoice_Salutation']['value'] = array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES', 'misses'), "Herr" => _t('SilvercartAddress.MISTER', 'mister'));
     $this->formFields['Invoice_AcademicTitle']['title'] = _t('SilvercartAddress.AcademicTitle', 'Academic title');
     $this->formFields['Invoice_FirstName']['title'] = _t('SilvercartAddress.FIRSTNAME', 'firstname');
     $this->formFields['Invoice_Surname']['title'] = _t('SilvercartAddress.SURNAME', 'surname');
     $this->formFields['Invoice_Addition']['title'] = _t('SilvercartAddress.ADDITION', 'addition');
     $this->formFields['Invoice_Street']['title'] = _t('SilvercartAddress.STREET', 'street');
     $this->formFields['Invoice_StreetNumber']['title'] = _t('SilvercartAddress.STREETNUMBER', 'streetnumber');
     $this->formFields['Invoice_Postcode']['title'] = _t('SilvercartAddress.POSTCODE', 'postcode');
     $this->formFields['Invoice_City']['title'] = _t('SilvercartAddress.CITY', 'city');
     $this->formFields['Invoice_Phone']['title'] = _t('SilvercartAddress.PHONE', 'phone');
     $this->formFields['Invoice_PhoneAreaCode']['title'] = _t('SilvercartAddress.PHONEAREACODE', 'phone area code');
     $this->formFields['Invoice_Country']['title'] = _t('SilvercartCountry.SINGULARNAME');
     $this->formFields['Shipping_Salutation']['title'] = _t('SilvercartAddress.SALUTATION');
     $this->formFields['Shipping_Salutation']['value'] = array('' => _t('SilvercartEditAddressForm.EMPTYSTRING_PLEASECHOOSE'), "Frau" => _t('SilvercartAddress.MISSES'), "Herr" => _t('SilvercartAddress.MISTER'));
     $this->formFields['Shipping_AcademicTitle']['title'] = _t('SilvercartAddress.AcademicTitle');
     $this->formFields['Shipping_FirstName']['title'] = _t('SilvercartAddress.FIRSTNAME');
     $this->formFields['Shipping_Surname']['title'] = _t('SilvercartAddress.SURNAME');
     $this->formFields['Shipping_Addition']['title'] = _t('SilvercartAddress.ADDITION');
     $this->formFields['Shipping_Street']['title'] = _t('SilvercartAddress.STREET');
     $this->formFields['Shipping_StreetNumber']['title'] = _t('SilvercartAddress.STREETNUMBER');
     $this->formFields['Shipping_Postcode']['title'] = _t('SilvercartAddress.POSTCODE');
     $this->formFields['Shipping_City']['title'] = _t('SilvercartAddress.CITY');
     $this->formFields['Shipping_Phone']['title'] = _t('SilvercartAddress.PHONE');
     $this->formFields['Shipping_PhoneAreaCode']['title'] = _t('SilvercartAddress.PHONEAREACODE');
     $this->formFields['Shipping_Country']['title'] = _t('SilvercartCountry.SINGULARNAME');
     $countries = SilvercartCountry::get()->filter('Active', 1);
     if ($countries->exists()) {
         $this->formFields['Shipping_Country']['value'] = SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartCheckoutFormStep2.EMPTYSTRING_COUNTRY'));
         $this->formFields['Invoice_Country']['value'] = SilvercartCountry::getPrioritiveDropdownMap(true, _t('SilvercartCheckoutFormStep2.EMPTYSTRING_COUNTRY'));
     }
     // --------------------------------------------------------------------
     // Insert values from previous entries the customer has made
     // --------------------------------------------------------------------
     $this->controller->fillFormFields($this->formFields);
     if ($this->formFields['InvoiceAddressAsShippingAddress']['value'] == '1') {
         $this->controller->addJavascriptOnloadSnippet(array('deactivateShippingAddressValidation();
                 $(\'#ShippingAddressFields\').css(\'display\', \'none\');', 'loadInTheEnd'));
     }
 }
 /**
  * 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;
 }
示例#7
0
 /**
  * Returns whether this zone is related to all active countries
  *
  * @return boolean 
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 08.06.2012
  */
 public function hasAllCountries()
 {
     /* @var $countries ArrayList */
     $countries = $this->SilvercartCountries();
     $availableCountries = SilvercartCountry::get()->filter("Active", 1);
     $hasAllCountries = true;
     foreach ($availableCountries as $availableCountry) {
         if (!$countries->find('ID', $availableCountry->ID)) {
             $hasAllCountries = false;
             break;
         }
     }
     return $hasAllCountries;
 }
 /**
  * Creates an address using the given checkout data and prefix.
  * 
  * @param array  $checkoutData Checkout data
  * @param string $prefix       Prefix
  * 
  * @return SilvercartAddress
  */
 public function getAddressByCheckoutData($checkoutData, $prefix = 'Invoice')
 {
     $db = Config::inst()->get('SilvercartAddress', 'db');
     $has_one = Config::inst()->get('SilvercartAddress', 'has_one');
     $address = new SilvercartAddress();
     foreach (array_keys($db) as $fieldname) {
         if (array_key_exists($prefix . '_' . $fieldname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $fieldname];
         }
     }
     foreach (array_keys($has_one) as $relationname) {
         $fieldname = $relationname . 'ID';
         $plainFieldname = str_replace('Silvercart', '', $fieldname);
         $plainRelationname = str_replace('Silvercart', '', $relationname);
         if (array_key_exists($prefix . '_' . $relationname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $relationname];
         } elseif (array_key_exists($prefix . '_' . $fieldname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $fieldname];
         } elseif (array_key_exists($prefix . '_' . $plainRelationname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $plainRelationname];
         } elseif (array_key_exists($prefix . '_' . $plainFieldname, $checkoutData)) {
             $address->{$fieldname} = $checkoutData[$prefix . '_' . $plainFieldname];
         }
         if (!is_null($address->{$fieldname})) {
             $address->{$plainFieldname} = $address->{$fieldname};
         }
     }
     if (is_null($address->IsPackstation) || $prefix == 'Invoice') {
         $address->IsPackstation = false;
     }
     $address->Country = SilvercartCountry::get()->byID($address->SilvercartCountryID);
     return $address;
 }
 /**
  * Returns the current shipping country
  *
  * @return SilvercartCountry
  * 
  * @author Sebastian Diel <*****@*****.**>
  * @since 15.11.2014
  */
 public function ShippingCountry()
 {
     $customer = SilvercartCustomer::currentUser();
     $shippingCountry = null;
     if ($customer) {
         $shippingCountry = $customer->SilvercartShippingAddress()->SilvercartCountry();
     }
     if (is_null($shippingCountry) || $shippingCountry->ID == 0) {
         $shippingCountry = SilvercartCountry::get()->filter(array('ISO2' => substr(Translatable::get_current_locale(), 3), 'Active' => 1))->first();
     }
     return $shippingCountry;
 }
 /**
  * Checks, whether an activated country exists or not.
  *
  * @return array
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>
  * @since 18.04.2011
  */
 public function checkActiveCountries()
 {
     $hasActiveCountries = false;
     /*
      * We have to bypass DataObject::get_one() because it would ignore active
      * countries without a translation of the current locale
      */
     $items = SilvercartCountry::get()->filter(array("Active" => 1));
     if ($items->count() > 0) {
         $hasActiveCountries = true;
     }
     return array('status' => $hasActiveCountries, 'message' => sprintf(_t('SilvercartConfig.ERROR_MESSAGE_NO_ACTIVATED_COUNTRY', 'No activated country found. Please <a href="%s/admin/settings/">log in</a> and choose "SilverCart Configuration -> countries" to activate a country.'), Director::baseURL()));
 }