/** * @covers sAdmin::sUpdateShipping */ public function testsUpdateShipping() { // Test no user id $this->assertFalse($this->module->sUpdateShipping()); $customer = $this->createDummyCustomer(); $this->session->offsetSet('sUserId', $customer->getId()); // With user id but with no data, operation is successful $this->assertTrue($this->module->sUpdateShipping()); // Setup dummy test data and test with it $postData = array('company' => 'Testcompany', 'department' => 'Testdepartment', 'salutation' => 'Testsalutation', 'firstname' => 'Testfirstname', 'lastname' => 'Testlastname', 'street' => 'Teststreet', 'streetnumber' => 'Teststreetnumber', 'zipcode' => 'Testzipcode', 'city' => 'Testcity', 'country' => '2', 'stateID' => '4', 'text1' => 'TestText1', 'text2' => 'TestText2', 'text3' => 'TestText3', 'text4' => 'TestText4', 'text5' => 'TestText5', 'text6' => 'TestText6'); $this->front->Request()->setPost($postData); $this->assertTrue($this->module->sUpdateShipping()); $result = Shopware()->Db()->fetchRow(' SELECT * FROM s_user_shippingaddress LEFT JOIN s_user_shippingaddress_attributes ON s_user_shippingaddress.id = s_user_shippingaddress_attributes.shippingID WHERE s_user_shippingaddress.userID = ? ', array($customer->getId())); // Prepare testData for comparison $postData['countryID'] = $postData['country']; unset($postData['country']); $this->assertArrayHasKey('id', $result); foreach ($postData as $key => $value) { $this->assertEquals($value, $result[$key]); } $this->deleteDummyCustomer($customer); }
/** * 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')); }