Ejemplo n.º 1
0
 /**
  * @covers sAdmin::sValidateStep2ShippingAddress
  */
 public function testsValidateStep2ShippingAddress()
 {
     // Test with no rules, should always validate
     $result = $this->module->sValidateStep2ShippingAddress(array());
     $this->assertInternalType('array', $result);
     $this->assertArrayHasKey('sErrorFlag', $result);
     $this->assertArrayHasKey('sErrorMessages', $result);
     $this->assertNull($result['sErrorFlag']);
     $this->assertNull($result['sErrorMessages']);
     $testRuleSet = array('testField1' => array('required' => 1), 'testField2' => array('required' => 0), 'testField3' => array('required' => 1));
     // Test failing validation, should have 2 failing fields
     $result = $this->module->sValidateStep2ShippingAddress($testRuleSet);
     $this->assertInternalType('array', $result);
     $this->assertArrayHasKey('sErrorFlag', $result);
     $this->assertArrayHasKey('sErrorMessages', $result);
     $this->assertCount(2, $result['sErrorFlag']);
     $this->assertArrayHasKey('testField1', $result['sErrorFlag']);
     $this->assertArrayHasKey('testField3', $result['sErrorFlag']);
     $this->assertCount(1, $result['sErrorMessages']);
     // Setup dummy test data and test with it, see it passes
     $this->front->Request()->setPost(array('testField1' => 'testValue', 'testField2' => 'testValue', 'testField3' => 'testValue'));
     $result = $this->module->sValidateStep2ShippingAddress($testRuleSet);
     $this->assertInternalType('array', $result);
     $this->assertArrayHasKey('sErrorFlag', $result);
     $this->assertArrayHasKey('sErrorMessages', $result);
     $this->assertNull($result['sErrorFlag']);
     $this->assertNull($result['sErrorMessages']);
 }
Ejemplo n.º 2
0
 /**
  * Validates the shipping informations
  *
  * @return array - shipping data with error flags and msg
  */
 public function validateShipping()
 {
     $countryData = $this->admin->sGetCountryList();
     $countryIds = array_column($countryData, 'id');
     $rules = array('salutation' => array('required' => 1), 'company' => array('required' => 0), 'firstname' => array('required' => 1), 'lastname' => array('required' => 1), 'street' => array('required' => 1), 'streetnumber' => array('required' => 1), 'zipcode' => array('required' => 1), 'city' => array('required' => 1), 'department' => array('required' => 0), 'text1' => array('required' => 0), 'text2' => array('required' => 0), 'text3' => array('required' => 0), 'text4' => array('required' => 0), 'text5' => array('required' => 0), 'text6' => array('required' => 0));
     if (Shopware()->Config()->get('sCOUNTRYSHIPPING')) {
         $rules['country'] = array('required' => 1, 'in' => $countryIds);
         // Check if state selection is required
         if (!empty($this->post["shipping"]["country"])) {
             $stateSelectionRequired = Shopware()->Db()->fetchRow("SELECT display_state_in_registration, force_state_in_registration\n                    FROM s_core_countries WHERE id = ?", array($this->post["shipping"]["country"]));
             if ($stateSelectionRequired["display_state_in_registration"]) {
                 $countryDataIndex = array_search($this->post["shipping"]["country"], $countryIds);
                 $statesIds = array_column($countryData[$countryDataIndex]['states'], 'id');
                 // if not required, allow empty values
                 if (!$stateSelectionRequired["force_state_in_registration"]) {
                     $statesIds[] = "";
                 }
                 $rules["stateID"] = array("required" => $stateSelectionRequired["force_state_in_registration"], 'in' => $statesIds);
             }
             $this->post["shipping"]["stateID"] = $this->post["shipping"]["country_shipping_state_" . $this->post["shipping"]["country"]];
             unset($this->post["shipping"]["country_shipping_state_" . $this->post["shipping"]["country"]]);
         }
     }
     $rules = Enlight()->Events()->filter('Shopware_Controllers_Frontend_Register_validateShipping_FilterRules', $rules, array('subject' => $this));
     $this->admin->sSYSTEM->_POST = $this->post['shipping'];
     $checkData = $this->admin->sValidateStep2ShippingAddress($rules);
     return $checkData;
 }
Ejemplo n.º 3
0
 /**
  * Save shipping action
  *
  * Save shipping address data
  */
 public function saveShippingAction()
 {
     if ($this->Request()->isPost()) {
         $countryData = $this->admin->sGetCountryList();
         $countryIds = array_column($countryData, 'id');
         $rules = array('salutation' => array('required' => 1), 'company' => array('required' => 0), 'firstname' => array('required' => 1), 'lastname' => array('required' => 1), 'street' => array('required' => 1), 'streetnumber' => array('required' => 1), 'zipcode' => array('required' => 1), 'city' => array('required' => 1), 'department' => array('required' => 0), 'text1' => array('required' => 0), 'text2' => array('required' => 0), 'text3' => array('required' => 0), 'text4' => array('required' => 0), 'text5' => array('required' => 0), 'text6' => array('required' => 0));
         if ($this->Request()->getParam('sSelectAddress')) {
             $address = $this->admin->sGetPreviousAddresses('shipping', $this->Request()->getParam('sSelectAddress'));
             if (!empty($address['hash'])) {
                 $address = array_merge($this->View()->sUserData['shippingaddress'], $address);
                 $this->admin->sSYSTEM->_POST = $address;
             }
         } else {
             $this->admin->sSYSTEM->_POST = $this->Request()->getPost();
         }
         $values = $this->Request()->getPost('register');
         if (Shopware()->Config()->get('sCOUNTRYSHIPPING')) {
             $rules['country'] = array('required' => 1, 'in' => $countryIds);
             // State selection
             if (!empty($values["shipping"]["country"])) {
                 $stateSelectionRequired = Shopware()->Db()->fetchRow("\n                    SELECT display_state_in_registration, force_state_in_registration\n                    FROM s_core_countries WHERE id = ?", array($values["shipping"]["country"]));
                 if ($stateSelectionRequired["display_state_in_registration"]) {
                     $countryDataIndex = array_search($values["shipping"]["country"], $countryIds);
                     $statesIds = array_column($countryData[$countryDataIndex]['states'], 'id');
                     // if not required, allow empty values
                     if (!$stateSelectionRequired["force_state_in_registration"]) {
                         $statesIds[] = "";
                     }
                     $rules["stateID"] = array("required" => $stateSelectionRequired["force_state_in_registration"], 'in' => $statesIds);
                 }
                 if ($stateSelectionRequired["display_state_in_registration"] == false && $stateSelectionRequired["force_state_in_registration"] == false) {
                     $this->admin->sSYSTEM->_POST["register"]["shipping"]["stateID"] = $values["shipping"]["stateID"] = 0;
                 } else {
                     $this->admin->sSYSTEM->_POST["register"]["shipping"]["stateID"] = $values["shipping"]["stateID"] = $values["shipping"]["country_shipping_state_" . $values["shipping"]["country"]];
                 }
                 unset($values["shipping"]["country_shipping_state_" . $values["shipping"]["country"]]);
             }
         }
         if (!empty($values)) {
             $this->admin->sSYSTEM->_POST = array_merge($values['shipping'], $this->admin->sSYSTEM->_POST->toArray());
         }
         $checkData = $this->admin->sValidateStep2ShippingAddress($rules, true);
         if (!empty($checkData['sErrorMessages'])) {
             $this->View()->sErrorFlag = $checkData['sErrorFlag'];
             $this->View()->sErrorMessages = $checkData['sErrorMessages'];
             return $this->forward('shipping');
         } else {
             $this->admin->sUpdateShipping();
         }
     }
     if (!($target = $this->Request()->getParam('sTarget'))) {
         $target = 'account';
     }
     $this->redirect(array('controller' => $target, 'action' => 'index', 'success' => 'shipping'));
 }