private function loadModel($id) { $model=Destination::model()->findByPk($id); if($model===null) throw new CHttpException(404,'The requested page does not exist.'); return $model; }
public function getDestinaByPk($id) { $model = Destination::model()->find(array( 'select'=>'name', 'condition'=>"id=$id", )); return $model->name; }
public static function VerifyAnyDestination() { $objAnyDest = Destination::model()->findByAttributes(array('country' => null, 'state' => null)); if (!$objAnyDest instanceof Destination) { $objTax = TaxCode::GetNoTaxCode(); if ($objTax) { $objNewAny = new Destination(); $objNewAny->country = null; $objNewAny->state = null; $objNewAny->zipcode1 = ''; $objNewAny->zipcode2 = ''; $objNewAny->taxcode = $objTax->lsid; $objNewAny->save(); } } }
protected function getDestionaModel() { $des = explode(';',$this->to_addr); $str = '没有目的地'; $tempArr = array(); $DestArr = Destination::model()->findAll(array('select'=>'id,name')); if(!empty($DestArr)){ $str = ''; foreach($DestArr as $model){ $tempArr[$model->id] = $model->name; } if(is_array($des)){ $slash = ''; foreach($des as $destid){ $str .= $slash.$tempArr[$destid]; $slash = '/'; } }else{ $str = $tempArr[$des]; } } return $str; }
public function actionUpdatedestination() { $pk = Yii::app()->getRequest()->getPost('pk'); $name = Yii::app()->getRequest()->getPost('name'); $value = Yii::app()->getRequest()->getPost('value'); if ($name == "country" && $value == 'DELETE') { Destination::model()->deleteByPk($pk); echo "delete"; } else { if ($value == '') { $value = null; } if ($name == "country" && $value == '0') { $value = null; } if ($name == "state" && $value == '0') { $value = null; } $obj = Destination::model()->findByPk($pk); $obj->{$name} = $value; $obj->save(); echo "success"; } }
/** * For a product, returns tax rate for all defined destinations * Useful for RSS exports * @return TaxGrid[] */ public function GetTaxRateGrid() { $arrGrid = array(); $intTaxStatus = $this->tax_status_id; $objStatus = TaxStatus::LoadByLS($intTaxStatus); $objDestinations = Destination::model()->findAll(); foreach ($objDestinations as $objDestination) { //Because of differences in how Google defines zip code ranges, we can't convert our ranges //to theirs. At this time we won't be able to support zip code ranges if (!is_null($objDestination->country) && $objDestination->Zipcode1 == '') { $objTaxCode = TaxCode::LoadByLS($objDestination->taxcode); //print_r($objTaxCode); $fltRate = 0.0; for ($x = 1; $x <= 5; $x++) { $statusstring = "tax" . $x . "_status"; $codestring = "tax" . $x . "_rate"; if ($objStatus->{$statusstring} == 0) { $fltRate += $objTaxCode->{$codestring}; } } //Our four elements $strCountry = Country::CodeById($objDestination->country); if (!is_null($objDestination->state)) { $strState = State::CodeById($objDestination->state); } else { $strState = ''; } //$fltRate -- built above $strTaxShip = Yii::app()->params['SHIPPING_TAXABLE'] == '1' ? "y" : "n"; $arrGrid[] = array($strCountry, $strState, $fltRate, $strTaxShip); } } return $arrGrid; }
/** * Get the available shipping states for a given country. * * Respects SHIP_RESTRICT_DESTINATION - if this configuration is enable * then only the states that are defined will be returned. * * @param string $intCountryId The ID of the country. * @return string[] An associative array mapping the state ID to the state * code. */ public static function getCountryShippingStates($intCountryId) { $noStatesAvailable = array('' => 'n/a'); if (is_null($intCountryId)) { $intCountryId = _xls_get_conf('DEFAULT_COUNTRY', 224); } $criteria = new CDbCriteria(); $criteria->alias = 'state'; $criteria->select = 'state.id, state.code'; $criteria->addCondition('country_id = :country_id'); $criteria->addCondition('active = 1'); $criteria->order = 'state.sort_order, state.state'; // Check for 'only ship to defined destinations'. if (Yii::app()->params['SHIP_RESTRICT_DESTINATION']) { // If we have an entry for the country in xlsws_destination with a // null state, that means that the destination is defined for the // entire country so we don't need to restrict by state. // That's because state IS NULL corresponds to State=ANY. $destinations = Destination::model()->findAll('country=:country_id AND state IS NULL', array('country_id' => $intCountryId)); // If there are no results then we don't have a destination for the // country as a whole so we restrict further by state. if (count($destinations) === 0) { // Filter the results further by state destinations. $criteria->join = 'JOIN xlsws_destination ON (xlsws_destination.state = state.id)'; } } $criteria->params[':country_id'] = $intCountryId; $states = State::model()->findAll($criteria); if (count($states) === 0) { return $noStatesAvailable; } return CHtml::listData($states, 'id', 'code'); }
/** * Check if the necessary checkout modules are active. * * @return array $errors - messages of the errors based on the module. */ public static function checkAllModulesConfigured() { $errors = array(); if (count(Modules::getModulesByCategory(true, 'payment')) === 0) { array_push($errors, 'There are no active payment methods.'); } if (count(Modules::getModulesByCategory(true, 'shipping')) === 0) { array_push($errors, 'There are no active shipping methods.'); } if (count(Destination::model()->findAll()) === 0) { array_push($errors, 'Destinations are not configured.'); } return $errors; }
/** * 18 Change destination tables and map to country/state ids */ protected function actionConvertDestinationTables() { //Convert Wish List items to new formats //Ship to me //Ship to buyer //Keep in store //find and remove any destinations with an erroneous taxcode $sql = 'SELECT `id` FROM `xlsws_destination` WHERE `taxcode` NOT IN (SELECT xlsws_tax_code.lsid FROM xlsws_tax_code);'; $array = Yii::app()->db->createCommand($sql)->queryAll(); foreach ($array as $a) { Yii::log('Destination id ' . $a['id'] . 'deleted due to erroneous tax code', 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); _dbx('DELETE FROM `xlsws_destination` WHERE `id`=' . $a['id'] . ';'); } $objDestinations = Destination::model()->findAll(); foreach ($objDestinations as $objDestination) { if ($objDestination->country == "*") { $objDestination->country = null; } else { if (!is_numeric($objDestination->country)) { $objC = Country::LoadByCode($objDestination->country); $objDestination->country = $objC->id; } } if ($objDestination->state == "*" || $objDestination->state == null) { $objDestination->state = null; } else { if (!is_numeric($objDestination->state)) { $objS = State::LoadByCode($objDestination->state, $objDestination->country); $objDestination->state = $objS->id; } } if (!$objDestination->save()) { return print_r($objDestination->getErrors()); } } //Need to map destinations to IDs before doing this _dbx("update `xlsws_destination` set country=null where country=0;"); _dbx("update `xlsws_destination` set state=null where state=0;"); _dbx("ALTER TABLE `xlsws_destination` CHANGE `country` `country` INT(11) UNSIGNED NULL DEFAULT NULL;"); _dbx("ALTER TABLE `xlsws_destination` CHANGE `state` `state` INT(11) UNSIGNED NULL DEFAULT NULL;"); _dbx("ALTER TABLE `xlsws_destination` CHANGE `taxcode` `taxcode` INT(11) UNSIGNED NULL DEFAULT NULL;"); _dbx("ALTER TABLE `xlsws_destination` ADD FOREIGN KEY (`state`) REFERENCES `xlsws_state` (`id`);"); _dbx("ALTER TABLE `xlsws_destination` ADD FOREIGN KEY (`country`) REFERENCES `xlsws_country` (`id`);"); _dbx("ALTER TABLE `xlsws_destination` ADD FOREIGN KEY (`taxcode`) REFERENCES `xlsws_tax_code` (`lsid`);"); _dbx("ALTER TABLE `xlsws_category` CHANGE `custom_page` `custom_page` INT(11) UNSIGNED NULL DEFAULT NULL;"); _dbx("UPDATE `xlsws_category` set `custom_page`=null where `custom_page`=0;"); _dbx("ALTER TABLE `xlsws_category` ADD FOREIGN KEY (`custom_page`) REFERENCES `xlsws_custom_page` (`id`);"); _dbx("ALTER TABLE `xlsws_country` DROP `code_a3`;"); _dbx("update `xlsws_shipping_tiers` set `class_name`='tieredshipping';"); return array('result' => "success", 'makeline' => 19, 'tag' => 'Applying database schema changes', 'total' => 50); }
public static function LoadByCountry($strCountry, $blnRestrict = false) { $objCountry = Country::LoadByCode($strCountry); if ($blnRestrict) { if (count(Destination::model()->countByAttributes(array('country' => $objCountry->id, 'state' => null)))) { $arrStates = State::model()->findAllByAttributes(array('country_id' => $objCountry->id, 'active' => 1), State::GetDefaultOrdering()); return Destination::ConvertStatesToDestinations($objCountry->id, $arrStates); } } return Destination::model()->findAll('country IS NULL OR country=:t1 ' . Destination::GetDefaultOrdering(true), array(':t1' => $objCountry->id)); }