Beispiel #1
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');
 }
 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);
 }
 /**
  * Create an order form for customers to fill out their details and pass the order
  * on to the payment class.
  * 
  * @return CheckoutForm The checkout/order form 
  */
 function OrderForm()
 {
     $fields = array();
     $validator = new OrderFormValidator();
     $member = Customer::currentUser() ? Customer::currentUser() : singleton('Customer');
     $order = CartControllerExtension::get_current_order();
     $billingAddress = $member->BillingAddress();
     $shippingAddress = $member->ShippingAddress();
     $this->addBillingAddressFields($fields, $validator);
     $this->addShippingAddressFields($fields, $validator);
     $this->addPersonalDetailsFields($fields, $validator, $member);
     $this->addItemFields($fields, $validator, $order);
     $this->addModifierFields($fields, $validator, $order);
     $this->addNotesField($fields, $validator);
     $this->addPaymentFields($fields, $validator, $order);
     $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();
     //Need to disable the js validation because not using custom validation messages
     $validator->setJavascriptValidationHandler('none');
     if ($member->ID) {
         $form->loadDataFrom($member);
     }
     if ($billingAddress) {
         $form->loadDataFrom($billingAddress->getCheckoutFormData('Billing'));
     }
     if ($shippingAddress) {
         $form->loadDataFrom($shippingAddress->getCheckoutFormData('Shipping'));
     }
     //Hook for editing the checkout page order form
     $this->extend('updateOrderForm', $form);
     return $form;
 }