Source of file PostagePaymentForm.php
Size: 6,413 Bytes - Last Modified: 2021-12-24T05:16:24+00:00
/var/www/docs.ssmods.com/process/src/code/forms/PostagePaymentForm.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 | <?php /** * Description of CheckoutForm * * @author morven */ class PostagePaymentForm extends Form { public function __construct($controller, $name = "PostagePaymentForm") { $cart = ShoppingCart::get(); if (!Checkout::config()->simple_checkout && !$cart->isCollection() && $cart->isDeliverable()) { // Get delivery data and postage areas from session $delivery_data = Session::get("Checkout.DeliveryDetailsForm.data"); $country = $delivery_data['DeliveryCountry']; $postcode = $delivery_data['DeliveryPostCode']; $postage_areas = new ShippingCalculator($postcode, $country); $postage_areas ->setCost($cart->SubTotalCost) ->setWeight($cart->TotalWeight) ->setItems($cart->TotalItems); $postage_areas = $postage_areas->getPostageAreas(); // Loop through all postage areas and generate a new list $postage_array = array(); foreach ($postage_areas as $area) { $area_currency = new Currency("Cost"); if (ShoppingCart::IncludesTax()) { $area_currency->setValue($area->Total()); } else { $area_currency->setValue($area->Cost); } $postage_array[$area->ID] = $area->Title . " (" . $area_currency->Nice() . ")"; } if (Session::get('Checkout.PostageID')) { $postage_id = Session::get('Checkout.PostageID'); } elseif ($postage_areas->exists()) { $postage_id = $postage_areas->first()->ID; } else { $postage_id = 0; } if (count($postage_array)) { $select_postage_field = OptionsetField::create( "PostageID", _t('Checkout.PostageSelection', 'Please select your preferred postage'), $postage_array )->setValue($postage_id); } else { $select_postage_field = ReadonlyField::create( "NoPostage", "", _t('Checkout.NoPostageSelection', 'Unfortunately we cannot deliver to your address') )->addExtraClass("label") ->addExtraClass("label-red"); } // Setup postage fields $postage_field = CompositeField::create( HeaderField::create("PostageHeader", _t('Checkout.Postage', "Postage")), $select_postage_field )->setName("PostageFields"); } elseif ($cart->isCollection()) { $postage_field = CompositeField::create( HeaderField::create("PostageHeader", _t('Checkout.CollectionOnly', "Collection Only")), ReadonlyField::create( "CollectionText", "", _t("Checkout.ItemsReservedInstore", "Your items will be held instore until you collect them") ) )->setName("CollectionFields"); } elseif (!$cart->isDeliverable()) { $postage_field = CompositeField::create( HeaderField::create( "PostageHeader", _t('Checkout.Postage', "Postage") ), ReadonlyField::create( "CollectionText", "", _t("Checkout.NoDeliveryForOrder", "Your order does not contain items that can be posted") ) )->setName("CollectionFields"); } else { $postage_field = null; } // Get available payment methods and setup payment $payment_methods = ArrayList::create(); foreach (SiteConfig::current_site_config()->PaymentMethods() as $payment_method) { if ($payment_method->canView()) { $payment_methods->add($payment_method); } } // Deal with payment methods if ($payment_methods->exists()) { $payment_field = OptionsetField::create( 'PaymentMethodID', _t('Checkout.PaymentSelection', 'Please choose how you would like to pay'), $payment_methods->map('ID', 'Label'), $payment_methods->filter('Default', 1)->first()->ID )->setTemplate("PaymentsOptionsetField"); } else { $payment_field = ReadonlyField::create( "PaymentMethodID", _t('Checkout.PaymentSelection', 'Please choose how you would like to pay'), _t('Checkout.NoPaymentMethods', 'You cannot pay at this time, if you feel there has been an error please contact us.') ); } $payment_field = CompositeField::create( HeaderField::create('PaymentHeading', _t('Checkout.Payment', 'Payment'), 2), $payment_field )->setName("PaymentFields"); $fields = FieldList::create( CompositeField::create( $postage_field, $payment_field )->setName("PostagePaymentFields") ->setColumnCount(2) ); if ($payment_methods->exists()) { $actions = FieldList::create( FormAction::create('doContinue', _t('Checkout.PaymentDetails', 'Enter Payment Details')) ->addExtraClass('checkout-action-next') ); } else { $actions = FieldList::create(); } $validator = RequiredFields::create(array( "PostageID", "PaymentMethod" )); parent::__construct($controller, $name, $fields, $actions, $validator); $this->setTemplate($this->ClassName); } public function getBackURL() { return $this->controller->Link("billing"); } public function doContinue($data) { Session::set('Checkout.PaymentMethodID', $data['PaymentMethodID']); Session::set("Checkout.PostageID", $data["PostageID"]); $url = Controller::join_links( Director::absoluteBaseUrl(), Payment_Controller::config()->url_segment ); return $this ->controller ->redirect($url); } } |