/**
  * emailing admin and or running custom code to update newsletter status
  * @param DataObject $order Order
  * @return Boolean
  **/
 public function doStep(Order $order)
 {
     $billingAddress = $order->BillingAddress();
     $member = $order->Member();
     if ($member && $billingAddress) {
         $recipient = Recipient::get()->filter(array("Email" => $billingAddress->Email))->first();
         if (!$recipient) {
             $recipient = Recipient::create();
             $recipient->Email = $billingAddress->Email;
         }
         $recipient->FirstName = $billingAddress->FirstName;
         $recipient->Surname = $billingAddress->Surname;
         $recipient->write();
         $mailingListToAdd = $member->MailingLists();
         DB::query("DELETE FROM MailingList_Recipients WHERE RecipientID = " . $recipient->ID . ";");
         if ($mailingListToAdd->count()) {
             $recipientsMailingLists = $recipient->MailingLists();
             $recipientsMailingLists->addMany($mailingListToAdd->map("ID", "ID")->toArray());
             if ($this->SendMessageToAdmin) {
                 $member = $order->Member();
                 if ($member) {
                     if ($member->NewsletterSignup) {
                         $from = Order_Email::get_from_email();
                         $subject = _t("NewsletterSignup.NEWSLETTERREGISTRATIONUPDATE", "newsletter registration update");
                         $billingAddressOutput = "";
                         if ($billingAddress) {
                             $billingAddressOutput = $billingAddress->renderWith("Order_AddressBilling");
                         }
                         $body = "\n\t\t\t\t\t\t\t\t" . _t("NewsletterSignup.EMAIL", "Email") . ": <strong>" . $member->Email . "</strong>" . "<br /><br />" . _t("NewsletterSignup.SIGNUP", "Signed Up") . ": <strong>" . ($member->NewsletterSignup ? _t("NewsletterSignup.YES", "Yes") : _t("NewsletterSignup.NO", "No")) . "</strong>" . "<br /><br />" . $billingAddressOutput;
                         $email = new Email($from, $to = Order_Email::get_from_email(), $subject, $body);
                         $email->send();
                         //copy!
                         if ($this->SendCopyTo) {
                             $email = new Email($from, $to = $this->SendCopyTo, $subject, $body);
                             $email->send();
                         }
                     }
                     //this can be used to connect with third parties (e.g. )
                 }
             }
         }
         $this->extend("updateNewsletterStatus", $member, $recipient);
     }
     return true;
 }
 public function getFormFields(Order $order)
 {
     if (Member::currentUser() || $order->Member()->exists()) {
         return FieldList::create();
     }
     $content = $this->content ?: _t('LoginCheckoutComponent.ALREADY_HAVE_AN_ACCOUNT?', 'Already have an account? <a class="checkout--login-link" href="{{ link }}">Sign in here</a>');
     $link = $this->link ?: singleton('Security')->Link('login');
     return FieldList::create(FormMessageField::create('LoginMessage', str_replace('{{ link }}', $link, $content), $this->type));
 }
 /**
  * @param String $name
  * @param Order $order
  * @param Member $member
  */
 function __construct($name, Order $order, Member $member = null)
 {
     if (!$member) {
         $member = $order->Member();
     }
     if (!$member) {
         $member = new Member();
     }
     $orderSteps = OrderStep::get();
     $where = "\"HideStepFromCustomer\" = 0";
     $currentStep = $order->CurrentStepVisibleToCustomer();
     if ($member->IsShopAdmin()) {
         $where = "";
         $currentStep = $order->MyStep();
     } else {
         $currentStep = $order->CurrentStepVisibleToCustomer();
         $orderSteps->filter(array("HideStepFromCustomer" => 0));
     }
     $future = false;
     $html = "\r\n\t\t<div class=\"orderStepField\">\r\n\t\t\t<ol>";
     if ($orderSteps->count()) {
         foreach ($orderSteps as $orderStep) {
             $description = "";
             if ($member->IsShopAdmin()) {
                 if ($orderStep->Description) {
                     $description = " title=\"" . Convert::raw2att($orderStep->Description) . "\" ";
                 }
             }
             $class = "";
             if ($orderStep->ID == $currentStep->ID) {
                 $future = true;
                 $class .= " current";
             } elseif ($future) {
                 $class .= " todo";
             } else {
                 $class .= " done";
             }
             $html .= '<li class="' . $class . '" ' . $description . '>' . $orderStep->Title . '</li>';
         }
     } else {
         $html .= "no steps";
     }
     $html .= "</ol><div class=\"clear\"></div></div>";
     if ($currentStep->Description) {
         $html .= "\r\n\t\t\t\t<p>" . "<strong>" . $currentStep->Title . "</strong> " . _t("OrderStepField.STEP", "step") . ": " . "<i>" . $currentStep->Description . "</i>" . "</p>";
     }
     $this->content = $html;
     Requirements::themedCSS("OrderStepField", 'ecommerce');
     parent::__construct($name);
 }
 /**
  * Process payment form and return next step in the payment process.
  * Steps taken are:
  * 1. create new payment
  * 2. save form into payment
  * 3. return payment result
  *
  * @param Order $order - the order that is being paid
  * @param Form $form - the form that is being submitted
  * @param Array $data - Array of data that is submittted
  * @return Boolean - if successful, this method will return TRUE
  */
 public static function process_payment_form_and_return_next_step($order, $form, $data)
 {
     if (!$order) {
         $form->sessionMessage(_t('EcommercePayment.NOORDER', 'Order not found.'), 'bad');
         Director::redirectBack();
         return false;
     }
     $paidBy = $order->Member();
     if (!$paidBy) {
         $paidBy = Member::currentUser();
     }
     $paymentClass = !empty($data['PaymentMethod']) ? $data['PaymentMethod'] : null;
     $payment = class_exists($paymentClass) ? new $paymentClass() : null;
     if (!($payment && $payment instanceof Payment)) {
         $form->sessionMessage(_t('EcommercePayment.NOPAYMENTOPTION', 'No Payment option selected.'), 'bad');
         Director::redirectBack();
         return false;
     }
     // Save payment data from form and process payment
     $form->saveInto($payment);
     $payment->OrderID = $order->ID;
     if (is_object($paidBy)) {
         $payment->PaidByID = $paidBy->ID;
     }
     $payment->Amount = $order->TotalOutstandingAsMoneyObject();
     $payment->write();
     // Process payment, get the result back
     $result = $payment->processPayment($data, $form);
     if (!$result instanceof Payment_Result) {
         return false;
     } else {
         if ($result->isProcessing()) {
             //IMPORTANT!!!
             // isProcessing(): Long payment process redirected to another website (PayPal, Worldpay)
             //redirection is taken care of by payment processor
             return $result->getValue();
         } else {
             //payment is done, redirect to either returntolink
             //OR to the link of the order ....
             if (isset($data["returntolink"])) {
                 Director::redirect($data["returntolink"]);
             } else {
                 Director::redirect($order->Link());
             }
         }
         return true;
     }
 }
 /**
  * Send a message to the client containing the latest
  * note of {@link OrderStatusLog} and the current status.
  *
  * Used in {@link OrderReport}.
  *
  * @param string $note Optional note-content (instead of using the OrderStatusLog)
  */
 public function sendStatusChange($title, $note = null)
 {
     if (!$note) {
         $latestLog = OrderStatusLog::get()->filter("OrderID", $this->order->ID)->filter("SentToCustomer", 1)->first();
         if ($latestLog) {
             $note = $latestLog->Note;
             $title = $latestLog->Title;
         }
     }
     $member = $this->order->Member();
     if (Config::inst()->get('OrderProcessor', 'receipt_email')) {
         $adminEmail = Config::inst()->get('OrderProcessor', 'receipt_email');
     } else {
         $adminEmail = Email::config()->admin_email;
     }
     $e = Order_statusEmail::create();
     $e->populateTemplate(array("Order" => $this->order, "Member" => $member, "Note" => $note));
     $e->setFrom($adminEmail);
     $e->setSubject($title);
     $e->setTo($member->Email);
     $e->send();
 }
 public function getConstraints(Order $order, $form = null)
 {
     $member = Member::currentUser() ?: $order->Member();
     if (!$member || !$member->exists() || !$member->AddressBook()->exists()) {
         return [];
     }
     $required = parent::getRequiredFields($order);
     $constraints = [];
     $namespace = $this->name();
     foreach ($member->AddressBook() as $address) {
         foreach ($required as $requirement) {
             $constraints[$namespace . '_address-' . $address->ID . '[' . $requirement . ']'] = (new RequiredIfStrict($namespace . '_Use', '[value=address-' . $address->ID . ']:checked'))->setMessage(_t('AlternateAddressBookCheckoutComponent.' . $this->addresstype . '-REQUIRED_IF', 'This value is required when ' . strtolower($this->addresstype) . ' to: {address}', ['address' => $address->toString()]));
         }
     }
     if ($this->allowNew) {
         foreach ($required as $requirement) {
             $constraints[$namespace . '_new[' . $requirement . ']'] = (new RequiredIfStrict($namespace . '_Use', '[value=new]:checked'))->setMessage(_t('AlternateAddressBookCheckoutComponent.' . $this->addresstype . '-REQUIRED_IF_NEW', 'This value is required when ' . strtolower($this->addresstype) . ' to a new address'));
         }
     }
     return $constraints;
 }