Author: Frank Mullenger (frankmullenger@gmail.com)
Inheritance: extends Form
 public function PaymentMethodForm()
 {
     $form = new CheckoutForm($this->owner, "PaymentMethodForm", $this->checkoutconfig());
     $form->setActions(new FieldList(FormAction::create("setpaymentmethod", "Continue")));
     $this->owner->extend('updatePaymentMethodForm', $form);
     return $form;
 }
 public function CouponForm()
 {
     $form = new CheckoutForm($this->owner, "CouponForm", $this->checkoutconfig());
     $form->setActions(new FieldList(FormAction::create("setcoupon", "Continue")));
     $this->owner->extend('updateCouponForm', $form);
     return $form;
 }
 public function BillingAddressForm()
 {
     $form = new CheckoutForm($this->owner, 'BillingAddressForm', $this->billingconfig());
     $form->setActions(new FieldList(new FormAction("setbillingaddress", "Continue")));
     $this->owner->extend('updateBillingAddressForm', $form);
     return $form;
 }
 public function CreateAccountForm()
 {
     $form = new CheckoutForm($this->owner, "CreateAccountForm", $this->registerconfig());
     $form->setActions(new FieldList(new FormAction('docreateaccount', 'Create New Account')));
     $form->getValidator()->addRequiredField("Password");
     $this->owner->extend('updateCreateAccountForm', $form);
     return $form;
 }
 public function ContactDetailsForm()
 {
     $cart = ShoppingCart::curr();
     if (!$cart) {
         return false;
     }
     $config = new CheckoutComponentConfig(ShoppingCart::curr());
     $config->addComponent(new CustomerDetailsCheckoutComponent());
     $form = new CheckoutForm($this->owner, 'ContactDetailsForm', $config);
     $form->setRedirectLink($this->NextStepLink());
     $form->setActions(new FieldList(new FormAction("checkoutSubmit", "Continue")));
     $this->owner->extend('updateContactDetailsForm', $form);
     return $form;
 }
 public function BillingAddressForm()
 {
     $form = CheckoutForm::create($this->owner, 'BillingAddressForm', $this->billingconfig());
     $form->setActions(FieldList::create(FormAction::create("setbillingaddress", _t('CheckoutStep.Continue', "Continue"))));
     $this->owner->extend('updateBillingAddressForm', $form);
     return $form;
 }
 public function PaymentMethodForm()
 {
     $form = CheckoutForm::create($this->owner, "PaymentMethodForm", $this->checkoutconfig());
     $form->setActions(FieldList::create(FormAction::create("setpaymentmethod", _t('CheckoutStep.CONTINUE', "Continue"))));
     $this->owner->extend('updatePaymentMethodForm', $form);
     return $form;
 }
 public function CreateAccountForm()
 {
     $form = CheckoutForm::create($this->owner, "CreateAccountForm", $this->registerconfig());
     $form->setActions(FieldList::create(FormAction::create('docreateaccount', _t('CheckoutStep_Membership.CreateNewAccount', 'Create New Account', 'This is an action (Button label)'))));
     $form->getValidator()->addRequiredField("Password");
     $this->owner->extend('updateCreateAccountForm', $form);
     return $form;
 }
 public function testCheckoutFormForSingleCountrySiteWithReadonlyFieldsForCountry()
 {
     // Set as a single country site
     $this->loadFixture("shop/tests/fixtures/singlecountry.yml");
     $singlecountry = SiteConfig::current_site_config();
     $this->assertEquals("NZ", $singlecountry->getSingleCountry(), "Confirm that website is setup as a single country site");
     $order = ShoppingCart::curr();
     $config = new SinglePageCheckoutComponentConfig($order);
     $form = new CheckoutForm($this->checkoutcontroller, "OrderForm", $config);
     // no country fields due to readonly field
     $dataCountryAbsent = array("CustomerDetailsCheckoutComponent_FirstName" => "Jane", "CustomerDetailsCheckoutComponent_Surname" => "Smith", "CustomerDetailsCheckoutComponent_Email" => "*****@*****.**", "ShippingAddressCheckoutComponent_Address" => "1234 Green Lane", "ShippingAddressCheckoutComponent_AddressLine2" => "Building 2", "ShippingAddressCheckoutComponent_City" => "Bleasdfweorville", "ShippingAddressCheckoutComponent_State" => "Trumpo", "ShippingAddressCheckoutComponent_PostalCode" => "4123", "ShippingAddressCheckoutComponent_Phone" => "032092277", "BillingAddressCheckoutComponent_Address" => "1234 Green Lane", "BillingAddressCheckoutComponent_AddressLine2" => "Building 2", "BillingAddressCheckoutComponent_City" => "Bleasdfweorville", "BillingAddressCheckoutComponent_State" => "Trumpo", "BillingAddressCheckoutComponent_PostalCode" => "4123", "BillingAddressCheckoutComponent_Phone" => "032092277", "PaymentCheckoutComponent_PaymentMethod" => "Dummy", "NotesCheckoutComponent_Notes" => "Leave it around the back", "TermsCheckoutComponent_ReadTermsAndConditions" => "1");
     $form->loadDataFrom($dataCountryAbsent, true);
     $valid = $form->validate();
     $errors = $form->getValidator()->getErrors();
     $this->assertTrue($valid, print_r($errors, true));
     $this->assertTrue($form->Fields()->fieldByName("ShippingAddressCheckoutComponent_Country_readonly")->isReadonly(), "Shipping Address Country field is readonly");
     $this->assertTrue($form->Fields()->fieldByName("BillingAddressCheckoutComponent_Country_readonly")->isReadonly(), "Billing Address Country field is readonly");
     $form->checkoutSubmit($dataCountryAbsent, $form);
     $shipping = $order->ShippingAddress();
     $this->assertEquals("NZ", $shipping->Country);
     $billing = $order->BillingAddress();
     $this->assertEquals("NZ", $billing->Country);
 }
Esempio n. 10
0
 public function testCheckoutForm()
 {
     $order = ShoppingCart::curr();
     $config = new SinglePageCheckoutComponentConfig($order);
     $form = new CheckoutForm($this->checkoutcontroller, "OrderForm", $config);
     $data = array("CustomerDetailsCheckoutComponent_FirstName" => "Jane", "CustomerDetailsCheckoutComponent_Surname" => "Smith", "CustomerDetailsCheckoutComponent_Email" => "*****@*****.**", "ShippingAddressCheckoutComponent_Country" => "NZ", "ShippingAddressCheckoutComponent_Address" => "1234 Green Lane", "ShippingAddressCheckoutComponent_AddressLine2" => "Building 2", "ShippingAddressCheckoutComponent_City" => "Bleasdfweorville", "ShippingAddressCheckoutComponent_State" => "Trumpo", "ShippingAddressCheckoutComponent_PostalCode" => "4123", "ShippingAddressCheckoutComponent_Phone" => "032092277", "BillingAddressCheckoutComponent_Country" => "NZ", "BillingAddressCheckoutComponent_Address" => "1234 Green Lane", "BillingAddressCheckoutComponent_AddressLine2" => "Building 2", "BillingAddressCheckoutComponent_City" => "Bleasdfweorville", "BillingAddressCheckoutComponent_State" => "Trumpo", "BillingAddressCheckoutComponent_PostalCode" => "4123", "BillingAddressCheckoutComponent_Phone" => "032092277", "PaymentCheckoutComponent_PaymentMethod" => "Dummy", "NotesCheckoutComponent_Notes" => "Leave it around the back", "TermsCheckoutComponent_ReadTermsAndConditions" => "1");
     $form->loadDataFrom($data, true);
     $valid = $form->validate();
     $errors = $form->getValidator()->getErrors();
     $this->assertTrue($valid);
     $form->checkoutSubmit($data, $form);
     $this->assertEquals("Jane", $order->FirstName);
     $shipping = $order->ShippingAddress();
     $this->assertEquals("NZ", $shipping->Country);
     $this->assertEquals("Cart", $order->Status);
     $this->markTestIncomplete('test invalid data');
     $this->markTestIncomplete('test components individually');
 }
 /**
  * Return all payment modules that have a sub form
  * such that the end user is prompted for input
  *
  * @return array $arrModuleForms
  * Array of CForms for each payment method that has one
  */
 public function getAlternativePaymentMethodsThatUseSubForms()
 {
     $arrModuleForms = parent::getAlternativePaymentMethodsThatUseSubForms();
     $arrRemoveIds = array();
     foreach ($arrModuleForms as $id => $form) {
         // get the input elements of this form
         $objElements = $form->getElements();
         // isolate the list into an array we can check
         $arrKeys = $objElements->getKeys();
         if (count($arrKeys) == 0) {
             // no input fields
             $arrRemoveIds[] = $id;
         }
     }
     foreach ($arrRemoveIds as $id) {
         unset($arrModuleForms[$id]);
     }
     return $arrModuleForms;
 }
 /**
  * Update the order form cart, called via AJAX with current order form data.
  * Renders the cart and sends that back for displaying on the order form page.
  * 
  * @param SS_HTTPRequest $data Form data sent via AJAX POST.
  * @return String Rendered cart for the order form, template include 'CheckoutFormOrder'.
  */
 function updateOrderFormCart(SS_HTTPRequest $data)
 {
     if ($data->isPOST()) {
         $fields = array();
         $validator = new OrderFormValidator();
         $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
         $order = CartControllerExtension::get_current_order();
         //Update the Order
         $order->addAddressesAtCheckout($data->postVars());
         $order->addModifiersAtCheckout($data->postVars());
         //TODO update personal details, notes and payment type?
         //Create the part of the form that displays the Order
         $this->addItemFields($fields, $validator, $order);
         $this->addModifierFields($fields, $validator, $order);
         //This is going to go through and add modifiers based on current Form DATA
         //TODO This should be constructed for non-dropdown fields as well
         //Update modifier form fields so that the dropdown values are correct
         $newModifierData = array();
         $subTotalModifiers = isset($fields['SubTotalModifiers']) ? $fields['SubTotalModifiers'] : array();
         $totalModifiers = isset($fields['Modifiers']) ? $fields['Modifiers'] : array();
         $modifierFields = array_merge($subTotalModifiers, $totalModifiers);
         foreach ($modifierFields as $field) {
             if (method_exists($field, 'updateValue')) {
                 $field->updateValue($order);
             }
             $modifierClassName = get_class($field->getModifier());
             $newModifierData['Modifiers'][$modifierClassName] = $field->Value();
         }
         //Add modifiers to the order again so that the new values are used
         $order->addModifiersAtCheckout($newModifierData);
         $actions = new FieldSet(new FormAction('ProcessOrder', _t('CheckoutPage.PROCEED_TO_PAY', "Proceed to pay")));
         $form = new CheckoutForm($this, 'OrderForm', $fields, $actions, $validator, $order);
         $form->disableSecurityToken();
         $form->validate();
         return $form->renderWith('CheckoutFormOrder');
     }
 }
Esempio n. 13
0
 public function __construct($controller, $name, CheckoutComponentConfig $config)
 {
     parent::__construct($controller, $name, $config);
     $this->orderProcessor = Injector::inst()->create('OrderProcessor', $config->getOrder());
 }
Esempio n. 14
0
 /**
  * @param string $type
  * @param null $intCountry
  * @return array
  */
 public function getStates($type = 'billing', $intCountry = null)
 {
     $obj = new CheckoutForm();
     return $obj->getStates($type, $intCountry);
 }
Esempio n. 15
0
 /**
  * Called by AJAX from checkout for Calculate Shipping. Builds a grid of
  * shipping scenarios including shipping price and cart total prices. The
  * results are cached client-side in the browser allowing the user to click
  * through and see updated cart totals without initiating another AJAX
  * request.
  * @return string JSON encoded shipping options.
  */
 public function actionAjaxCalculateShipping()
 {
     if (isset($_POST['CheckoutForm']) === false) {
         return $this->renderJSON(array('result' => 'error', 'errormsg' => 'Must POST a CheckoutForm'));
     }
     Yii::log("Performing an AJAX Shipping Calculation Request", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     // We run the items through the model for verification.
     $model = new CheckoutForm();
     $model->attributes = $_POST['CheckoutForm'];
     if (Yii::app()->params['SHIP_SAME_BILLSHIP']) {
         $model->billingSameAsShipping = 1;
     }
     $model->scenario = 'CalculateShipping';
     // Copy address book to field if necessary.
     $model->fillFieldsFromPreselect();
     // Set up the exception handle for the remainder of this function.
     $handleException = function (Exception $e) {
         Yii::log($e->getMessage(), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__);
         return $this->renderJSON(array('result' => 'error', 'errormsg' => $e->getMessage()));
     };
     try {
         self::validateCheckoutForm($model);
     } catch (Exception $e) {
         return $handleException($e);
     }
     Yii::log("Successfully validated shipping request", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     // Clone the model because we're going to make some changes we may
     // not want to retain.
     // TODO: Accommodate spaces in the postal code in the shipping modules themselves.
     $checkoutForm = clone $model;
     $checkoutForm->shippingPostal = str_replace(" ", "", $checkoutForm->shippingPostal);
     $hasPromoCodeBeforeUpdatingTaxCode = Yii::app()->shoppingcart->hasPromoCode;
     try {
         $arrCartScenario = Shipping::getCartScenarios($checkoutForm);
     } catch (Exception $e) {
         return $handleException($e);
     }
     // A promo code can be removed as a result of getting updated
     // cart scenarios if the tax code has changed and the promo
     // code theshold is no longer met.
     // TODO: Do not modify the shoppingcart tax code in getCartScenarios,
     // it is surprising. See a similar TODO in Shipping::getCartScenarios.
     $hasPromoCodeBeforeAfterUpdatingTaxCode = Yii::app()->shoppingcart->hasPromoCode;
     $wasPromoCodeRemoved = false;
     if ($hasPromoCodeBeforeUpdatingTaxCode === true && $hasPromoCodeBeforeAfterUpdatingTaxCode === false) {
         $wasPromoCodeRemoved = true;
     }
     // Sort the shipping options based on sort order, then on price.
     usort($arrCartScenario, function ($item1, $item2) {
         if ($item1['sortOrder'] === $item2['sortOrder'] && $item1['shippingPrice'] === $item2['shippingPrice']) {
             return 0;
         }
         if ($item1['sortOrder'] === $item2['sortOrder']) {
             return $item1['shippingPrice'] > $item2['shippingPrice'] ? 1 : -1;
         }
         return $item1['sortOrder'] > $item2['sortOrder'] ? 1 : -1;
     });
     $arrFormattedCartScenario = $this->formatCartScenarios($arrCartScenario);
     // Store the results in our session so we don't have to recalculate whatever they picked.
     // TODO: Much of this may be unnecessary with the refactoring completed
     // as part of advanced checkout.
     Yii::log("Populating caches", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     Yii::app()->session['ship.htmlCartItems.cache'] = $arrFormattedCartScenario['renderedCartItems'];
     Yii::app()->session['ship.prices.cache'] = $arrFormattedCartScenario['shippingOptionPrices'];
     Yii::app()->session['ship.formattedPrices.cache'] = $arrFormattedCartScenario['formattedShippingOptionPrices'];
     Yii::app()->session['ship.priorityRadio.cache'] = $arrFormattedCartScenario['renderedPriorityRadioButtonList'];
     Yii::app()->session['ship.providerLabels.cache'] = $arrFormattedCartScenario['shippingProviderLabels'];
     Yii::app()->session['ship.priorityLabels.cache'] = $arrFormattedCartScenario['shippingPriorityLabels'];
     Yii::app()->session['ship.providerRadio.cache'] = $arrFormattedCartScenario['renderedProviderRadioButtonList'];
     Yii::app()->session['ship.formattedCartTotals.cache'] = $arrFormattedCartScenario['formattedCartTotals'];
     Yii::app()->session['ship.taxes.cache'] = $arrFormattedCartScenario['renderedCartTaxes'];
     $errormsg = null;
     if (Yii::app()->user->hasFlash('error')) {
         // The error message may contain HTML. Since the JavaScript
         // displays it in an alert, we don't want that.
         $errormsg = strip_tags(Yii::app()->user->getFlash('error'));
     }
     $arrReturn = array('cartitems' => $arrFormattedCartScenario['renderedCartItems'], 'paymentmodules' => $model->getPaymentMethodsAjax(), 'prices' => $arrFormattedCartScenario['formattedShippingOptionPrices'], 'priority' => $arrFormattedCartScenario['renderedPriorityRadioButtonList'], 'errormsg' => $errormsg, 'provider' => $arrFormattedCartScenario['renderedProviderRadioButtonList'], 'result' => 'success', 'taxes' => $arrFormattedCartScenario['renderedCartTaxes'], 'totals' => $arrFormattedCartScenario['formattedCartTotals'], 'wasPromoCodeRemoved' => $wasPromoCodeRemoved);
     Yii::log("Returning JSON encoded shipping", 'info', 'application.' . __CLASS__ . "." . __FUNCTION__);
     return $this->renderJSON($arrReturn);
 }