/** * Logged in users get directed to the next step immediately. * * @return void * * @author Sascha Koehler <*****@*****.**>, Seabstian Diel <*****@*****.**> * @since 08.04.2011 */ public function isConditionForDisplayFulfilled() { $isConditionForDisplayFulfilled = false; if (!SilvercartCustomer::currentRegisteredCustomer()) { $isConditionForDisplayFulfilled = true; } return $isConditionForDisplayFulfilled; }
/** * The newsletter checkbox should not be shown if a registered customer has * already subscribed to the newsletter. * * @return boolean answer * * @author Roland Lehmann <*****@*****.**> * @since 22.7.2011 */ public function showNewsletterCheckbox() { $customer = SilvercartCustomer::currentRegisteredCustomer(); if ($customer && $customer->SubscribedToNewsletter == 1) { return false; } return true; }
/** * We save the data of the user here. * * @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 Sascha Koehler <*****@*****.**> * @since 22.03.2011 */ protected function submitSuccess($data, $form, $formData) { $member = SilvercartCustomer::currentRegisteredCustomer(); if ($member) { $formData['Salutation'] = $member->Salutation; $formData['FirstName'] = $member->FirstName; $formData['Surname'] = $member->Surname; $formData['Email'] = $member->Email; // ---------------------------------------------------------------- // For registered and logged in customers all we have to do is set // the respective field in the customer object. // ---------------------------------------------------------------- switch ($formData['NewsletterAction']) { case '1': SilvercartNewsletter::subscribeRegisteredCustomer($member); $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.SUBSCRIBED_SUCCESSFULLY'), $formData['Email'])); break; case '2': default: SilvercartNewsletter::unSubscribeRegisteredCustomer($member); $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.UNSUBSCRIBED_SUCCESSFULLY'), $formData['Email'])); } } else { // ---------------------------------------------------------------- // For unregistered customers we have to add / remove them from // the datastore for unregistered newsletter recipients. // // If the given email address belongs to a registered customer we // should not do anything but ask the user to log in first. // ---------------------------------------------------------------- if (SilvercartNewsletter::isEmailAllocatedByRegularCustomer($formData['Email'])) { $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.REGULAR_CUSTOMER_WITH_SAME_EMAIL_EXISTS'), $formData['Email'], '/Security/Login/?BackURL=' . $this->controller->PageByIdentifierCode('SilvercartNewsletterPage')->Link())); } else { if ($formData['NewsletterAction'] == '1') { // -------------------------------------------------------- // Subscribe to newsletter. // If the user is already subscribed we display a // message accordingly. // -------------------------------------------------------- if (SilvercartNewsletter::isEmailAllocatedByAnonymousRecipient($formData['Email'])) { $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.ALREADY_SUBSCRIBED'), $formData['Email'])); } else { SilvercartNewsletter::subscribeAnonymousCustomer($formData['Salutation'], $formData['FirstName'], $formData['Surname'], $formData['Email']); $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.SUBSCRIBED_SUCCESSFULLY_FOR_OPT_IN'), $formData['Email'])); } } else { // -------------------------------------------------------- // Unsubscribe from newsletter. // If no email address exists we display a message // accordingly. // -------------------------------------------------------- if (SilvercartNewsletter::isEmailAllocatedByAnonymousRecipient($formData['Email'])) { SilvercartNewsletter::unSubscribeAnonymousCustomer($formData['Email']); $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.UNSUBSCRIBED_SUCCESSFULLY'), $formData['Email'])); } else { $this->setSessionMessage(sprintf(_t('SilvercartNewsletterStatus.NO_EMAIL_FOUND'), $formData['Email'])); } } } } $redirectLink = '/'; $responsePage = SilvercartPage_Controller::PageByIdentifierCode("SilvercartNewsletterResponsePage"); if ($responsePage) { $redirectLink = $responsePage->RelativeLink(); } $this->controller->redirect($redirectLink); }
/** * Returns the current customer. * * @return Member */ public function getCustomer() { return SilvercartCustomer::currentRegisteredCustomer(); }
/** * 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; }
/** * Set initial form values * * @param bool $withUpdate Set to false to skip updates by decorator. * * @return void * * @author Sebastian Diel <*****@*****.**> * @since 16.07.2014 */ public function getFormFields($withUpdate = true) { // -------------------------------------------------------------------- // Set i18n labels // -------------------------------------------------------------------- $this->formFields['InvoiceAddressAsShippingAddress']['title'] = _t('SilvercartAddress.InvoiceAddressAsShippingAddress'); $this->formFields['InvoiceAddress']['title'] = _t('SilvercartPage.BILLING_ADDRESS'); $this->formFields['ShippingAddress']['title'] = _t('SilvercartPage.SHIPPING_ADDRESS'); // -------------------------------------------------------------------- // Insert values from customers saved addresses // -------------------------------------------------------------------- $member = SilvercartCustomer::currentRegisteredCustomer(); //method located in decorator; can not be called via class Member if ($member) { if ($member->SilvercartInvoiceAddress()->ID > 0) { $this->formFields['InvoiceAddress']['value'] = array($member->SilvercartInvoiceAddress()->ID => $member->SilvercartInvoiceAddress()->ID); } else { $this->formFields['InvoiceAddress']['value'] = $member->SilvercartAddresses()->map()->toArray(); } $this->formFields['ShippingAddress']['value'] = $member->SilvercartAddresses()->map()->toArray(); if ($member->SilvercartInvoiceAddress()) { $this->formFields['InvoiceAddress']['selectedValue'] = $member->SilvercartInvoiceAddress()->ID; } if ($member->SilvercartShippingAddress()) { $this->formFields['ShippingAddress']['selectedValue'] = $member->SilvercartShippingAddress()->ID; } } // -------------------------------------------------------------------- // 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')); } if ($this->InvoiceAddressIsAlwaysShippingAddress()) { $this->formFields['InvoiceAddressAsShippingAddress']['type'] = 'HiddenField'; unset($this->formFields['InvoiceAddressAsShippingAddress']['jsEvents']); $this->formFields['ShippingAddress']['selectedValue'] = $this->formFields['InvoiceAddress']['selectedValue']; } return parent::getFormFields($withUpdate); }
/** * Is customer logged in? * * @return bool * * @author Sebastian Diel <*****@*****.**> * @since 01.07.2011 */ public function isCustomerLoggedIn() { $isLoggedIn = false; if (SilvercartCustomer::currentRegisteredCustomer()) { $isLoggedIn = true; } return $isLoggedIn; }