当前位置: 首页>>代码示例>>PHP>>正文


PHP ShoppingCart::uses_different_shipping_address方法代码示例

本文整理汇总了PHP中ShoppingCart::uses_different_shipping_address方法的典型用法代码示例。如果您正苦于以下问题:PHP ShoppingCart::uses_different_shipping_address方法的具体用法?PHP ShoppingCart::uses_different_shipping_address怎么用?PHP ShoppingCart::uses_different_shipping_address使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ShoppingCart的用法示例。


在下文中一共展示了ShoppingCart::uses_different_shipping_address方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 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);
 }
开发者ID:nicolaas,项目名称:silverstripe-ecommerce,代码行数:68,代码来源:OrderForm.php

示例2: __construct

 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);
 }
开发者ID:riddler7,项目名称:silverstripe-ecommerce,代码行数:94,代码来源:OrderForm.php


注:本文中的ShoppingCart::uses_different_shipping_address方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。