/**
  * This method will be call if there are no validation error
  *
  * @param SS_HTTPRequest $data     input data
  * @param Form           $form     form object
  * @param array          $formData secured form data
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 14.04.2015
  */
 protected function submitSuccess($data, $form, $formData)
 {
     $member = $this->getCustomer();
     if ($member) {
         $country = DataObject::get_by_id('SilvercartCountry', $formData['Country']);
         if ($country) {
             $formData['SilvercartCountryID'] = $country->ID;
         }
         $formData['MemberID'] = $member->ID;
         $address = new SilvercartAddress();
         $address->write();
         $address->update($formData);
         $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());
         }
     }
 }
 /**
  * returns address data as ArrayData to control in template
  *
  * @return ArrayData
  *
  * @author Sebastian Diel <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 15.11.2014
  */
 public function AddressData()
 {
     $checkoutData = $this->controller->getCombinedStepData();
     if (array_key_exists('ShippingAddress', $checkoutData) && SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['ShippingAddress'])) {
         $shippingAddress = SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['ShippingAddress']);
     } else {
         /**
          * @deprecated Fallback for potential dependencies 
          */
         $shippingAddress = SilvercartTools::extractAddressDataFrom('Shipping', $checkoutData);
         $shippingAddress = $this->getAssociativeAddressData($shippingAddress);
         $shippingAddress = new SilvercartAddress($shippingAddress);
         $shippingAddress->setIsAnonymousShippingAddress(true);
     }
     if (array_key_exists('InvoiceAddress', $checkoutData) && SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['InvoiceAddress'])) {
         $invoiceAddress = SilvercartCustomer::currentUser()->SilvercartAddresses()->Find('ID', $checkoutData['InvoiceAddress']);
     } else {
         /**
          * @deprecated Fallback for potential dependencies 
          */
         $invoiceAddress = SilvercartTools::extractAddressDataFrom('Invoice', $checkoutData);
         $invoiceAddress = $this->getAssociativeAddressData($invoiceAddress, 'Invoice');
         $invoiceAddress = new SilvercartAddress($invoiceAddress);
         $invoiceAddress->setIsAnonymousInvoiceAddress(true);
         if ($this->isAnonymousInvoiceAddressEqualShippingAddress($checkoutData)) {
             $invoiceAddress->setIsAnonymousShippingAddress(true);
         }
     }
     if (array_key_exists('InvoiceAddress', $checkoutData) && array_key_exists('ShippingAddress', $checkoutData)) {
         if ($checkoutData['InvoiceAddress'] === $checkoutData['ShippingAddress']) {
             if (is_array($invoiceAddress)) {
                 /**
                  * @deprecated Fallback for potential dependencies 
                  */
                 $invoiceAddress['isInvoiceAndShippingAddress'] = true;
             } else {
                 SilvercartCustomer::currentUser()->SilvercartShippingAddressID = $checkoutData['ShippingAddress'];
                 SilvercartCustomer::currentUser()->SilvercartInvoiceAddressID = $checkoutData['InvoiceAddress'];
             }
         }
     }
     $addressData = new ArrayData(array('SilvercartShippingAddress' => $shippingAddress, 'SilvercartInvoiceAddress' => $invoiceAddress));
     return $addressData;
 }
 /**
  * Returns the context address.
  * 
  * @return SilvercartAddress
  */
 public function getAddress()
 {
     $member = SilvercartCustomer::currentUser();
     $id = $this->customParameters['addressID'];
     if ($member && $id) {
         $filter = array("MemberID" => $member->ID, "ID" => $id);
         $this->address = SilvercartAddress::get()->filter($filter)->first();
     }
     return $this->address;
 }
 /**
  * statements to be called on instanciation
  *
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 04.03.2014
  */
 public function init()
 {
     $addressID = false;
     if (isset($_POST['addressID'])) {
         $addressID = Convert::raw2sql($_POST['addressID']);
     } else {
         $addressID = $this->getRequest()->param('ID');
     }
     $this->setAddressID($addressID);
     $this->setBreadcrumbElementID($addressID);
     if (is_numeric($addressID)) {
         // get the address to check whether it is related to the actual customer or not.
         $address = SilvercartAddress::get()->byID($addressID);
         if ($address->MemberID > 0) {
             if ($address->Member()->ID != Member::currentUserID()) {
                 // the address is not related to the customer, redirect elsewhere...
                 $this->redirect($this->Parent()->Link());
             }
         } else {
             $this->redirect($this->Parent()->Link());
         }
     } else {
         $this->redirect($this->Parent()->Link());
     }
     $this->registerCustomHtmlForm('SilvercartEditAddressForm', new SilvercartEditAddressForm($this, array('addressID' => $addressID)));
     parent::init();
 }
Пример #5
0
 /**
  * Sets the customer readonly state for invoice addresses.
  * 
  * @param bool $invoice_address_is_readonly Set to true to make the invoice address readonly
  * 
  * @return void
  */
 public static function set_invoice_address_is_readonly($invoice_address_is_readonly)
 {
     self::$invoice_address_is_readonly = $invoice_address_is_readonly;
 }
 /**
  * No validation errors occured, so we register the customer and send
  * mails with further instructions for the double opt-in procedure.
  *
  * @param SS_HTTPRequest $data       SS session data
  * @param Form           $form       the form object
  * @param array          $formData   CustomHTMLForms session data
  * @param bool           $doRedirect Set to true to redirect after submitSuccess
  *
  * @return void
  * 
  * @author Sebastian Diel <*****@*****.**>,
  *         Roland Lehmann <*****@*****.**>,
  *         Sascha Koehler <*****@*****.**>
  * @since 28.01.2015
  */
 protected function submitSuccess($data, $form, $formData, $doRedirect = true)
 {
     $anonymousCustomer = false;
     /*
      * Logout anonymous users and save their shoppingcart temporarily.
      */
     if (SilvercartCustomer::currentUser()) {
         $anonymousCustomer = SilvercartCustomer::currentUser();
         SilvercartCustomer::currentUser()->logOut();
     }
     // Aggregate Data and set defaults
     $formData['MemberID'] = Member::currentUserID();
     $formData['Locale'] = Translatable::get_current_locale();
     if ($this->demandBirthdayDate()) {
         $formData['Birthday'] = $formData['BirthdayYear'] . '-' . $formData['BirthdayMonth'] . '-' . $formData['BirthdayDay'];
         if ($this->UseMinimumAgeToOrder()) {
             if (!SilvercartConfig::CheckMinimumAgeToOrder($formData['Birthday'])) {
                 $this->errorMessages['BirthdayDay'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY'), 'BirthdayDay' => array('message' => SilvercartConfig::MinimumAgeToOrderError()));
                 $this->errorMessages['BirthdayMonth'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY'), 'BirthdayMonth' => array('message' => SilvercartConfig::MinimumAgeToOrderError()));
                 $this->errorMessages['BirthdayYear'] = array('message' => SilvercartConfig::MinimumAgeToOrderError(), 'fieldname' => _t('SilvercartPage.BIRTHDAY'), 'BirthdayYear' => array('message' => SilvercartConfig::MinimumAgeToOrderError()));
                 $this->setSubmitSuccess(false);
                 return $this->submitFailure($data, $form);
             }
         }
     }
     // Create new regular customer and perform a log in
     $customer = new Member();
     // Pass shoppingcart to registered customer and delete the anonymous
     // customer.
     if ($anonymousCustomer) {
         $newShoppingCart = $anonymousCustomer->getCart()->duplicate(true);
         foreach ($anonymousCustomer->getCart()->SilvercartShoppingCartPositions() as $shoppingCartPosition) {
             $newShoppingCartPosition = $shoppingCartPosition->duplicate(false);
             $newShoppingCartPosition->SilvercartShoppingCartID = $newShoppingCart->ID;
             $newShoppingCartPosition->write();
             $shoppingCartPosition->transferToNewPosition($newShoppingCartPosition);
         }
         $customer->SilvercartShoppingCartID = $newShoppingCart->ID;
         $anonymousCustomer->delete();
     }
     $customer->castedUpdate($formData);
     $customer->write();
     $customer->logIn();
     $customer->changePassword($formData['Password']);
     $customerGroup = $this->getTargetCustomerGroup($formData);
     if ($customerGroup) {
         $customer->Groups()->add($customerGroup);
     }
     // Create ShippingAddress for customer and populate it with registration data
     $address = new SilvercartAddress();
     $address->castedUpdate($formData);
     $country = DataObject::get_by_id('SilvercartCountry', (int) $formData['Country']);
     if ($country) {
         $address->SilvercartCountryID = $country->ID;
     }
     $address->write();
     $this->extend('updateRegisteredAddress', $address, $data, $form, $formData);
     //connect the ShippingAddress and the InvoiceAddress to the customer
     $customer->SilvercartShippingAddressID = $address->ID;
     $customer->SilvercartInvoiceAddressID = $address->ID;
     $customer->SilvercartAddresses()->add($address);
     $customer->write();
     // Remove from the anonymous newsletter recipients list
     if (SilvercartAnonymousNewsletterRecipient::doesExist($customer->Email)) {
         $recipient = SilvercartAnonymousNewsletterRecipient::getByEmailAddress($customer->Email);
         if ($recipient->NewsletterOptInStatus) {
             $customer->NewsletterOptInStatus = 1;
             $customer->NewsletterConfirmationHash = $recipient->NewsletterOptInConfirmationHash;
             $customer->write();
         }
         SilvercartAnonymousNewsletterRecipient::removeByEmailAddress($customer->Email);
     }
     if ($customer->SubscribedToNewsletter && !$customer->NewsletterOptInStatus) {
         SilvercartNewsletter::subscribeRegisteredCustomer($customer);
     }
     $this->extend('updateRegisteredCustomer', $customer, $data, $form, $formData);
     if ($doRedirect) {
         // Redirect to welcome page
         if (array_key_exists('backlink', $formData) && !empty($formData['backlink'])) {
             $this->controller->redirect($formData['backlink']);
         } else {
             $this->controller->redirect($this->controller->PageByIdentifierCode('SilvercartRegisterConfirmationPage')->Link());
         }
     }
 }
 /**
  * Returns handling costs for this payment method
  *
  * @return Money a money object
  */
 public function getHandlingCost()
 {
     $controller = Controller::curr();
     $member = SilvercartCustomer::currentRegisteredCustomer();
     $handlingCostToUse = false;
     if (method_exists($controller, 'getAddress')) {
         // 1) Use shipping address from checkout
         $shippingAddress = $controller->getAddress('Shipping');
     } else {
         if ($member && $member->ShippingAddressID > 0) {
             // 2) Use customer's default shipping address
             $shippingAddress = $member->ShippingAddress();
         } else {
             // 3) Generate shipping address with shop's default country
             $currentShopLocale = i18n::get_lang_from_locale(i18n::get_locale());
             $shippingAddress = new SilvercartAddress();
             $shippingAddress->SilvercartCountry = SilvercartCountry::get()->filter('ISO2', strtoupper($currentShopLocale))->first();
         }
     }
     if (!$shippingAddress) {
         return false;
     }
     $zonesDefined = false;
     foreach ($this->SilvercartHandlingCosts() as $handlingCost) {
         $zone = $handlingCost->SilvercartZone();
         if ($zone->SilvercartCountries()->find('ISO3', $shippingAddress->SilvercartCountry()->ISO3)) {
             $handlingCostToUse = $handlingCost;
             $zonesDefined = true;
             break;
         }
     }
     // Fallback if SilvercartHandlingCosts are available but no zone is defined
     if (!$zonesDefined) {
         if ($this->SilvercartHandlingCosts()->Count() > 0) {
             $handlingCostToUse = $this->SilvercartHandlingCosts()->First();
         } else {
             $silvercartTax = SilvercartTax::get()->filter('isDefault', 1)->first();
             $handlingCostToUse = new SilvercartHandlingCost();
             $handlingCostToUse->SilvercartPaymentMethod = $this;
             $handlingCostToUse->SilvercartTax = $silvercartTax;
             $handlingCostToUse->SilvercartTaxID = $silvercartTax->ID;
             $handlingCostToUse->amount = new Money();
             $handlingCostToUse->amount->setAmount(0);
             $handlingCostToUse->amount->setCurrency(SilvercartConfig::DefaultCurrency());
         }
     }
     return $handlingCostToUse;
 }