public function testFindLink()
 {
     $this->checkoutpage = $this->objFromFixture('CheckoutPage', 'checkout');
     $this->checkoutpage->publish('Stage', 'Live');
     $link = CheckoutPage::find_link();
     $this->assertEquals(Director::baseURL() . 'checkout/', $link, 'find_link() returns the correct link to checkout.');
 }
 function redirect($status = "success", $message = "")
 {
     if (Director::is_ajax()) {
         return $status;
         //TODO: allow for custom return types, eg json - similar to ShoppingCart::return_data()
     }
     Director::redirect(CheckoutPage::find_link());
 }
 public function getPasswordFields()
 {
     $loginlink = "Security/login?BackURL=" . CheckoutPage::find_link(true);
     $fields = FieldList::create(HeaderField::create(_t('CheckoutField.MEMBERSHIPDETAILS', 'Membership Details'), 3), LiteralField::create('MemberInfo', '<p class="message warning">' . _t('CheckoutField.MEMBERINFO', 'If you are already a member please') . " <a href=\"{$loginlink}\">" . _t('OrderForm.LogIn', 'log in') . '</a>.' . '</p>'), LiteralField::create('AccountInfo', '<p>' . _t('CheckoutField.ACCOUNTINFO', 'Please choose a password, so you can login and check your order history in the future') . '</p>'), $this->getPasswordField());
     if (!Checkout::user_membership_required()) {
         $pwf->setCanBeEmpty(true);
     }
     return $fields;
 }
 public function getPasswordFields()
 {
     $loginlink = "Security/login?BackURL=" . CheckoutPage::find_link(true);
     $fields = FieldList::create(HeaderField::create(_t('CheckoutField.MembershipDetails', 'Membership Details'), 3), LiteralField::create('MemberInfo', '<p class="message warning">' . _t('CheckoutField.MemberLoginInfo', 'If you are already a member please <a href="{LoginUrl}">log in</a>', '', array('LoginUrl' => $loginlink)) . '</p>'), LiteralField::create('AccountInfo', '<p>' . _t('CheckoutField.AccountInfo', 'Please choose a password, so you can login and check your order history in the future') . '</p>'), $pwf = $this->getPasswordField());
     if (!Checkout::user_membership_required()) {
         $pwf->setCanBeEmpty(true);
     }
     return $fields;
 }
 function testFindLink()
 {
     $link = CheckoutPage::find_link();
     $this->assertEquals(Director::baseURL() . 'checkout/', $link, 'find_link() returns the correct link to checkout.');
     /* If there is no checkout page, then an exception is thrown */
     $page = DataObject::get_one('CheckoutPage');
     $page->delete();
     $page->flushCache();
     $this->setExpectedException('Exception');
     $link = CheckoutPage::find_link();
 }
 /**
  * Save the changes to the form, and redirect to the checkout page
  */
 function proceed($data, $form, $request)
 {
     $member = Member::currentUser();
     if (!$member) {
         return false;
     }
     $form->saveInto($member);
     $member->write();
     $form->sessionMessage(_t("MemberForm.DETAILSSAVED", 'Your details have been saved'), 'good');
     Director::redirect(CheckoutPage::find_link());
     return true;
 }
 /**
  * Save the changes to the form, and redirect to the checkout page
  *
  * @param array          $data
  * @param Form           $form
  * @param SS_HTTPRequest $request
  *
  * @return bool|SS_HTTPResponse
  */
 public function proceed($data, $form, $request)
 {
     $member = Member::currentUser();
     if (!$member) {
         return false;
     }
     $form->saveInto($member);
     $member->write();
     $form->sessionMessage(_t("MemberForm.DetailsSaved", 'Your details have been saved'), 'good');
     $this->extend('updateShopAccountFormResponse', $request, $form, $data, $response);
     return $response ?: $this->getController()->redirect(CheckoutPage::find_link());
 }
 public function run($request)
 {
     $cart = ShoppingCart::singleton();
     $count = $request->getVar('count') ? $request->getVar('count') : 5;
     if ($products = Versioned::get_by_stage("Product", "Live", "", "RAND()", "", $count)) {
         foreach ($products as $product) {
             $variations = $product->Variations();
             if ($variations->exists()) {
                 $product = $variations->sort("RAND()")->first();
             }
             $quantity = (int) rand(1, 5);
             if ($product->canPurchase(Member::currentUser(), $quantity)) {
                 $cart->add($product, $quantity);
             }
         }
     }
     Controller::curr()->redirect(CheckoutPage::find_link());
 }
 /**
  * work out the options for the user
  **/
 protected function workOutMessagesAndActions()
 {
     if (!$this->workedOutMessagesAndActions) {
         $this->actionLinks = new ArrayList(array());
         //what order are we viewing?
         $viewingRealCurrentOrder = $this->CurrentOrderIsInCart();
         $currentUserID = Member::currentUserID();
         //Continue Shopping
         if (isset($this->ContinueShoppingLabel) && $this->ContinueShoppingLabel) {
             if ($viewingRealCurrentOrder) {
                 if ($this->isCartPage()) {
                     $continueLink = $this->ContinueShoppingLink();
                     if ($continueLink) {
                         $this->actionLinks->push(new ArrayData(array("Title" => $this->ContinueShoppingLabel, "Link" => $continueLink)));
                     }
                 }
             }
         }
         //Proceed To CheckoutLabel
         if (isset($this->ProceedToCheckoutLabel) && $this->ProceedToCheckoutLabel) {
             if ($viewingRealCurrentOrder) {
                 if ($this->isCartPage()) {
                     $checkoutPageLink = CheckoutPage::find_link();
                     if ($checkoutPageLink && $this->currentOrder && $this->currentOrder->getTotalItems()) {
                         $this->actionLinks->push(new ArrayData(array("Title" => $this->ProceedToCheckoutLabel, "Link" => $checkoutPageLink)));
                     }
                 }
             }
         }
         //view account details
         if (isset($this->ShowAccountLabel) && $this->ShowAccountLabel) {
             if ($this->isOrderConfirmationPage() || $this->isCartPage()) {
                 if (AccountPage::find_link()) {
                     if ($currentUserID) {
                         $this->actionLinks->push(new ArrayData(array("Title" => $this->ShowAccountLabel, "Link" => AccountPage::find_link())));
                     }
                 }
             }
         }
         //go to current order
         if (isset($this->CurrentOrderLinkLabel) && $this->CurrentOrderLinkLabel) {
             if ($this->isCartPage()) {
                 if (!$viewingRealCurrentOrder) {
                     $this->actionLinks->push(new ArrayData(array("Title" => $this->CurrentOrderLinkLabel, "Link" => ShoppingCart::current_order()->Link())));
                 }
             }
         }
         //Save order - we assume only current ones can be saved.
         if (isset($this->SaveOrderLinkLabel) && $this->SaveOrderLinkLabel) {
             if ($viewingRealCurrentOrder) {
                 if ($currentUserID && $this->currentOrder->MemberID == $currentUserID) {
                     if ($this->isCartPage()) {
                         if ($this->currentOrder && $this->currentOrder->getTotalItems() && !$this->currentOrder->IsSubmitted()) {
                             $this->actionLinks->push(new ArrayData(array("Title" => $this->SaveOrderLinkLabel, "Link" => $this->Link("saveorder") . "/" . $this->currentOrder->ID . "/")));
                         }
                     }
                 }
             }
         }
         //load order
         if (isset($this->LoadOrderLinkLabel) && $this->LoadOrderLinkLabel) {
             if ($this->isCartPage() && $this->currentOrder) {
                 if (!$viewingRealCurrentOrder) {
                     $this->actionLinks->push(new ArrayData(array("Title" => $this->LoadOrderLinkLabel, "Link" => $this->Link("loadorder") . "/" . $this->currentOrder->ID . "/")));
                 }
             }
         }
         //delete order
         if (isset($this->DeleteOrderLinkLabel) && $this->DeleteOrderLinkLabel) {
             if ($this->isCartPage() && $this->currentOrder) {
                 if (!$viewingRealCurrentOrder) {
                     $this->actionLinks->push(new ArrayData(array("Title" => $this->DeleteOrderLinkLabel, "Link" => $this->Link("deleteorder") . "/" . $this->currentOrder->ID . "/")));
                 }
             }
         }
         //Start new order
         //Strictly speaking this is only part of the
         //OrderConfirmationPage but we put it here for simplicity's sake
         if (isset($this->StartNewOrderLinkLabel) && $this->StartNewOrderLinkLabel) {
             if ($this->isOrderConfirmationPage()) {
                 $this->actionLinks->push(new ArrayData(array("Title" => $this->StartNewOrderLinkLabel, "Link" => CartPage::new_order_link($this->currentOrder->ID))));
             }
         }
         //copy order
         //Strictly speaking this is only part of the
         //OrderConfirmationPage but we put it here for simplicity's sake
         if (isset($this->CopyOrderLinkLabel) && $this->CopyOrderLinkLabel) {
             if ($this->isOrderConfirmationPage() && $this->currentOrder->ID) {
                 $this->actionLinks->push(new ArrayData(array("Title" => $this->CopyOrderLinkLabel, "Link" => OrderConfirmationPage::copy_order_link($this->currentOrder->ID))));
             }
         }
         //actions from modifiers
         if ($this->isOrderConfirmationPage() && $this->currentOrder->ID) {
             $modifiers = $this->currentOrder->Modifiers();
             if ($modifiers->count()) {
                 foreach ($modifiers as $modifier) {
                     $array = $modifier->PostSubmitAction();
                     if (is_array($array) && count($array)) {
                         $this->actionLinks->push(new ArrayData($array));
                     }
                 }
             }
         }
         //log out
         //Strictly speaking this is only part of the
         //OrderConfirmationPage but we put it here for simplicity's sake
         if (Member::currentUser()) {
             if ($this->isOrderConfirmationPage()) {
                 $this->actionLinks->push(new ArrayData(array("Title" => _t("CartPage.LOGOUT", "log out"), "Link" => "/Security/logout/")));
             }
         }
         //no items
         if ($this->currentOrder) {
             if (!$this->currentOrder->getTotalItems()) {
                 $this->message = $this->NoItemsInOrderMessage;
             }
         } else {
             $this->message = $this->NonExistingOrderMessage;
         }
         $this->workedOutMessagesAndActions = true;
         //does nothing at present....
     }
 }
 /**
  *
  * @return String
  */
 function AddToCartAndGoToCheckoutLink()
 {
     $array = $this->linkParameters();
     $array["BackURL"] = urlencode(CheckoutPage::find_link());
     return ShoppingCart_Controller::add_item_link($this->ID, $this->ClassName, $array);
 }
 function __construct($controller, $name)
 {
     //Requirements::themedCSS('OrderForm');
     // 1) Member and shipping fields
     $member = Member::currentUser();
     $memberFields = new CompositeField(singleton('Member')->getEcommerceFields());
     $requiredFields = singleton('Member')->getEcommerceRequiredFields();
     if (ShoppingCart::uses_different_shipping_address()) {
         $countryField = new DropdownField('ShippingCountry', _t('OrderForm.Country', 'Country'), Geoip::getCountryDropDown(), EcommerceRole::find_country());
         $shippingFields = new CompositeField(new HeaderField(_t('OrderForm.SendGoodsToDifferentAddress', 'Send goods to different address'), 3), new LiteralField('ShippingNote', '<p class="message warning">' . _t('OrderForm.ShippingNote', 'Your goods will be sent to the address below.') . '</p>'), new LiteralField('Help', '<p>' . _t('OrderForm.Help', 'You can use this for gift giving. No billing information will be disclosed to this address.') . '</p>'), new TextField('ShippingName', _t('OrderForm.Name', 'Name')), new TextField('ShippingAddress', _t('OrderForm.Address', 'Address')), new TextField('ShippingAddress2', _t('OrderForm.Address2', '')), new TextField('ShippingCity', _t('OrderForm.City', 'City')), $countryField, new HiddenField('UseShippingAddress', '', true), $changeshippingbutton = new FormAction_WithoutLabel('useMemberShippingAddress', _t('OrderForm.UseBillingAddress', 'Use Billing Address for Shipping')));
         //Need to to this because 'FormAction_WithoutLabel' has no text on the actual button
         $changeshippingbutton->setButtonContent(_t('OrderForm.UseBillingAddress', 'Use Billing Address for Shipping'));
         $changeshippingbutton->useButtonTag = true;
         $requiredFields[] = 'ShippingName';
         $requiredFields[] = 'ShippingAddress';
         $requiredFields[] = 'ShippingCity';
         $requiredFields[] = 'ShippingCountry';
     } else {
         $countryField = $memberFields->fieldByName('Country');
         $shippingFields = new FormAction_WithoutLabel('useDifferentShippingAddress', _t('OrderForm.useDifferentShippingAddress', 'Use Different Shipping Address'));
         //Need to to this because 'FormAction_WithoutLabel' has no text on the actual button
         $shippingFields->setButtonContent(_t('OrderForm.useDifferentShippingAddress', 'Use Different Shipping Address'));
         $shippingFields->useButtonTag = true;
     }
     if ($countryField) {
         $countryField->addExtraClass('ajaxCountryField');
         $setCountryLinkID = $countryField->id() . '_SetCountryLink';
         $setContryLink = ShoppingCart::set_country_link();
         $memberFields->push(new HiddenField($setCountryLinkID, '', $setContryLink));
     }
     $leftFields = new CompositeField($memberFields, $shippingFields);
     $leftFields->setID('LeftOrder');
     $rightFields = new CompositeField();
     $rightFields->setID('RightOrder');
     if (!$member) {
         $rightFields->push(new HeaderField(_t('OrderForm.MembershipDetails', 'Membership Details'), 3));
         $rightFields->push(new LiteralField('MemberInfo', '<p class="message warning">' . _t('OrderForm.MemberInfo', 'If you are already a member please') . " <a href=\"Security/login?BackURL=" . CheckoutPage::find_link(true) . "/\">" . _t('OrderForm.LogIn', 'log in') . '</a>.</p>'));
         $rightFields->push(new LiteralField('AccountInfo', '<p>' . _t('OrderForm.AccountInfo', 'Please choose a password, so you can login and check your order history in the future') . '</p><br/>'));
         $rightFields->push(new FieldGroup($pwf = new ConfirmedPasswordField('Password', _t('OrderForm.Password', 'Password'))));
         //if user doesn't fill out password, we assume they don't want to become a member
         //TODO: allow different ways of specifying that you want to become a member
         if (self::$user_membership_optional) {
             $pwf->setCanBeEmpty(true);
         }
         if (self::$force_membership || !self::$user_membership_optional) {
             $requiredFields[] = 'Password[_Password]';
             $requiredFields[] = 'Password[_ConfirmPassword]';
             //TODO: allow extending this to provide other ways of indicating that you want to become a member
         }
     } else {
         $rightFields->push(new LiteralField('MemberInfo', '<p class="message good">' . sprintf(_t('OrderForm.LoggedInAs', 'You are logged in as %s.'), $member->getName()) . " <a href=\"Security/logout?BackURL=" . CheckoutPage::find_link(true) . "/\">" . _t('OrderForm.LogOut', 'log out') . '</a>.</p>'));
     }
     // 2) Payment fields
     $currentOrder = ShoppingCart::current_order();
     $totalobj = DBField::create('Currency', $currentOrder->Total());
     //should instead be $totalobj = $currentOrder->dbObject('Total');
     $paymentFields = Payment::combined_form_fields($totalobj->Nice());
     foreach ($paymentFields as $field) {
         $rightFields->push($field);
     }
     if ($paymentRequiredFields = Payment::combined_form_requirements()) {
         $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
     }
     // 3) Put all the fields in one FieldSet
     $fields = new FieldSet($leftFields, $rightFields);
     // 4) Terms and conditions field
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($controller->TermsPageID && ($termsPage = $controller->TermsPage())) {
         $bottomFields = new CompositeField(new CheckboxField('ReadTermsAndConditions', sprintf(_t('OrderForm.TERMSANDCONDITIONS', "I agree to the terms and conditions stated on the <a href=\"%s\" title=\"Read the shop terms and conditions for this site\">terms and conditions</a> page"), $termsPage->Link())));
         $bottomFields->setID('BottomOrder');
         $fields->push($bottomFields);
         $requiredFields[] = 'ReadTermsAndConditions';
         //TODO: this doesn't work for check-boxes
     }
     // 5) Actions and required fields creation
     $actions = new FieldSet(new FormAction('processOrder', _t('OrderForm.processOrder', 'Place order and make payment')));
     $requiredFields = new CustomRequiredFields($requiredFields);
     $this->extend('updateValidator', $requiredFields);
     $this->extend('updateFields', $fields);
     // 6) Form construction
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
     // 7) Member details loading
     if ($member && $member->ID) {
         $this->loadDataFrom($member);
     }
     // 8) Country field value update
     if ($countryField) {
         $currentOrder = ShoppingCart::current_order();
         $currentOrderCountry = $currentOrder->findShippingCountry(true);
         $countryField->setValue($currentOrderCountry);
     }
     //allow updating via decoration
     $this->extend('updateForm', $this);
 }
 /**
  * Save the changes to the form, and redirect to the checkout page
  * @return Boolean + redirection
  */
 function proceed($data, $form, $request)
 {
     return $this->processForm($data, $form, $request, CheckoutPage::find_link());
 }
 static function get_login_invite_alternative_text()
 {
     return str_replace("Security/login/", "Security/login/?BackURL=/" . CheckoutPage::find_link(true), self::$login_invite_alternative_text);
 }
示例#14
0
 /**
  *
  * @return String (URLSegment)
  **/
 function CheckoutLink()
 {
     return CheckoutPage::find_link();
 }
 public function testNestedCheckoutForm()
 {
     $this->assertEquals(Director::baseURL() . 'shop/checkout/', CheckoutPage::find_link(), 'Link is: ' . CheckoutPage::find_link());
 }
 public function testNestedCheckoutForm()
 {
     // NOTE: the "myshop" here comes from the fixtures
     $this->assertEquals(Director::baseURL() . 'myshop/checkout/', CheckoutPage::find_link(), 'Link is: ' . CheckoutPage::find_link());
 }
 function __construct($controller, $name)
 {
     Requirements::themedCSS('OrderForm');
     // 1) Member and shipping fields
     $member = Member::currentUser() ? Member::currentUser() : singleton('Member');
     $memberFields = new CompositeField($member->getEcommerceFields());
     $requiredFields = $member->getEcommerceRequiredFields();
     if (ShoppingCart::uses_different_shipping_address()) {
         $countryField = new DropdownField('ShippingCountry', 'Country', Geoip::getCountryDropDown(), EcommerceRole::findCountry());
         $shippingFields = new CompositeField(new HeaderField('Send goods to different address', 3), new LiteralField('ShippingNote', '<p class="warningMessage"><em>Your goods will be sent to the address below.</em></p>'), new LiteralField('Help', '<p>You can use this for gift giving. No billing information will be disclosed to this address.</p>'), new TextField('ShippingName', 'Name'), new TextField('ShippingAddress', 'Address'), new TextField('ShippingAddress2', ''), new TextField('ShippingCity', 'City'), $countryField, new HiddenField('UseShippingAddress', '', true), new FormAction_WithoutLabel('useMemberShippingAddress', 'Use Billing Address for Shipping'));
         $requiredFields[] = 'ShippingName';
         $requiredFields[] = 'ShippingAddress';
         $requiredFields[] = 'ShippingCity';
         $requiredFields[] = 'ShippingCountry';
     } else {
         $countryField = $memberFields->fieldByName('Country');
         $shippingFields = new FormAction_WithoutLabel('useDifferentShippingAddress', 'Use Different Shipping Address');
     }
     $countryField->addExtraClass('ajaxCountryField');
     $setCountryLinkID = $countryField->id() . '_SetCountryLink';
     $setContryLink = ShoppingCart_Controller::set_country_link();
     $memberFields->push(new HiddenField($setCountryLinkID, '', $setContryLink));
     $leftFields = new CompositeField($memberFields, $shippingFields);
     $leftFields->setID('LeftOrder');
     $rightFields = new CompositeField();
     $rightFields->setID('RightOrder');
     if (!$member->ID || $member->Password == '') {
         $rightFields->push(new HeaderField('Membership Details', 3));
         $rightFields->push(new LiteralField('MemberInfo', "<p class=\"message good\">If you are already a member, please <a href=\"Security/login?BackURL=" . CheckoutPage::find_link(true) . "/\">log in</a>.</p>"));
         $rightFields->push(new LiteralField('AccountInfo', "<p>Please choose a password, so you can login and check your order history in the future.</p><br/>"));
         $rightFields->push(new FieldGroup(new ConfirmedPasswordField('Password', 'Password')));
         $requiredFields[] = 'Password[_Password]';
         $requiredFields[] = 'Password[_ConfirmPassword]';
     }
     // 2) Payment fields
     $currentOrder = ShoppingCart::current_order();
     $total = '$' . number_format($currentOrder->Total(), 2);
     $paymentFields = Payment::combined_form_fields("{$total} " . $currentOrder->Currency(), $currentOrder->Total());
     foreach ($paymentFields as $field) {
         $rightFields->push($field);
     }
     if ($paymentRequiredFields = Payment::combined_form_requirements()) {
         $requiredFields = array_merge($requiredFields, $paymentRequiredFields);
     }
     // 3) Put all the fields in one FieldSet
     $fields = new FieldSet($leftFields, $rightFields);
     // 4) Terms and conditions field
     // If a terms and conditions page exists, we need to create a field to confirm the user has read it
     if ($controller->TermsPageID && ($termsPage = DataObject::get_by_id('Page', $controller->TermsPageID))) {
         $bottomFields = new CompositeField(new CheckboxField('ReadTermsAndConditions', "I agree to the terms and conditions stated on the <a href=\"{$termsPage->URLSegment}\" title=\"Read the shop terms and conditions for this site\">terms and conditions</a> page"));
         $bottomFields->setID('BottomOrder');
         $fields->push($bottomFields);
         $requiredFields[] = 'ReadTermsAndConditions';
     }
     // 5) Actions and required fields creation
     $actions = new FieldSet(new FormAction('processOrder', 'Place order and make payment'));
     $requiredFields = new CustomRequiredFields($requiredFields);
     // 6) Form construction
     parent::__construct($controller, $name, $fields, $actions, $requiredFields);
     // 7) Member details loading
     if ($member->ID) {
         $this->loadDataFrom($member);
     }
     // 8) Country field value update
     $currentOrder = ShoppingCart::current_order();
     $currentOrderCountry = $currentOrder->findShippingCountry(true);
     $countryField->setValue($currentOrderCountry);
 }
示例#18
0
 /**
  * Get the link for finishing order processing.
  */
 public function Link()
 {
     if (Member::currentUser()) {
         return Controller::join_links(AccountPage::find_link(), 'order', $this->ID);
     }
     return CheckoutPage::find_link(false, "order", $this->ID);
 }
 public function getCheckoutLink()
 {
     return CheckoutPage::find_link();
 }
示例#20
0
 /**
  * Return a link to the {@link CheckoutPage} instance
  * that exists in the database.
  *
  * @return string
  */
 function checkoutLink()
 {
     return $this->ID ? CheckoutPage::get_checkout_order_link($this->ID) : CheckoutPage::find_link();
 }