function __construct($controller, $name) { Requirements::javascript(ECOMMERCE_DIR . '/javascript/OrderFormWithShippingAddress.js'); parent::__construct($controller, $name); if (self::$fixed_country_code) { $defaultCountry = self::$fixed_country_code; } else { $defaultCountry = EcommerceRole::find_country(); } $countryField = new DropdownField('ShippingCountry', 'Country', Geoip::getCountryDropDown(), $defaultCountry, $this); $shippingFields = new Tab("ShippingDetails", new HeaderField('Delivery Address', 3, $this), new LiteralField('ShippingNote', '<p class="warningMessage"><em>Your goods will be sent to the address below.</em></p>'), new TextField('ShippingName', 'Name', null, 100, $this), new TextField('ShippingAddress', 'Address', null, 100, $this), new TextField('ShippingAddress2', '', null, 100, $this), new TextField('ShippingCity', 'City', null, 100, $this), $countryField); //$this->fields->push($shippingFields); $this->fields->addFieldToTab("", new CheckboxField("UseShippingAddress", "Use Alternative Delivery Address")); $this->fields->addFieldToTab("", $shippingFields); foreach ($this->fields->dataFields() as $i => $child) { if (is_object($child)) { $name = $child->Name(); switch ($name) { case "Address": $child->setTitle('Address'); break; default: break; } } } }
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); }
/** * Returns the correct shipping address. If there is an alternate * shipping country then it uses that. Failing that, it returns * the country of the member. * * @TODO This is pretty complicated code. It can be simplified. * * @param boolean $codeOnly If true, returns only the country code, instead * of the full name. * @return string */ function findShippingCountry($codeOnly = false) { if (!$this->ID) { $country = ShoppingCart::has_country() ? ShoppingCart::get_country() : EcommerceRole::find_country(); } elseif (!$this->UseShippingAddress || !($country = $this->ShippingCountry)) { $country = EcommerceRole::find_country(); } return $codeOnly ? $country : EcommerceRole::find_country_title($country); }
protected function LiveCountry() { return EcommerceRole::find_country(); }