/** * @covers sAdmin::sGetPremiumShippingcosts */ public function testsGetPremiumShippingcosts() { // No basket, return false, $this->assertFalse($this->module->sGetPremiumShippingcosts()); $countries = $this->module->sGetCountryList(); foreach ($countries as $country) { if ($country['countryiso']) { $germany = $country; break; } } $this->module->sSYSTEM->sSESSION_ID = uniqid(); $this->session->offsetSet('sessionId', $this->module->sSYSTEM->sSESSION_ID); $this->basketModule->sAddArticle('SW10010'); // With country data, no dispatch method $this->assertEquals(array('brutto' => 0, 'netto' => 0), $this->module->sGetPremiumShippingcosts($germany)); // With dispatch method $this->session->offsetSet('sDispatch', 9); $result = $this->module->sGetPremiumShippingcosts($germany); $this->assertArrayHasKey('brutto', $result); $this->assertArrayHasKey('netto', $result); $this->assertArrayHasKey('value', $result); $this->assertArrayHasKey('factor', $result); $this->assertArrayHasKey('surcharge', $result); $this->assertArrayHasKey('tax', $result); }
/** * 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; }
/** * 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')); }
/** * Shipping action method * * Read shipping address data */ public function shippingAction() { $this->View()->sShippingPreviously = $this->admin->sGetPreviousAddresses('shipping'); $this->View()->sCountryList = $this->admin->sGetCountryList(); $this->View()->sTarget = $this->Request()->getParam('sTarget', $this->Request()->getControllerName()); if(!empty($this->View()->sUserData['shippingaddress'])) { if($this->Request()->isPost()) { $address = array_merge($this->View()->sUserData['shippingaddress'], $this->Request()->getPost()); }else { $address = $this->View()->sUserData['shippingaddress']; } $address['country'] = $address['countryID']; $address['country_shipping_state_'.$address['countryID']] = $address['stateID']; unset($address['id'], $address['countryID']); $this->View()->sFormData = $address; } }
/** * Get all countries from database via sAdmin object * * @return array list of countries */ public function getCountryList() { return $this->admin->sGetCountryList(); }