/** * constructor for a region object * * If null is passed for parameters an empty region is created * * @access public * * @since 3.8.14 * * @param int|string|null required $country The country identifier, can be the string ISO code, * or the numeric wpec country id * * @param int|string|null|array required $region The region identifier, can be the text region code, * or the numeric region id, if an array is passed a * new region will be created and saved in the permanent * data store */ public function __construct($country, $region) { // if a country id or code is passed make sure we have a valid country_id $country_id = $country ? WPSC_Countries::get_country_id($country) : 0; // if we are creating a region use the country_id we just validated and get the region code if (is_array($region)) { $region['country_id'] = $country_id; $region_id_or_code = $this->_save_region_data($region); } else { $region_id_or_code = $region; } // if we have both a country country id and a region id/code we can construct this object if ($country && $region_id_or_code) { $region_id = WPSC_Countries::get_region_id($country_id, $region_id_or_code); if ($country_id && $region_id) { $wpsc_country = new WPSC_Country($country_id); $wpsc_region = $wpsc_country->get_region($region_id); if ($wpsc_region) { $this->_code = $wpsc_region->_code; $this->_id = $wpsc_region->_id; $this->_country_id = $wpsc_region->_country_id; $this->_name = $wpsc_region->_name; $this->_tax = $wpsc_region->_tax; } } } }
/** * a country's constructor * * @access public * * @since 3.8.14 * * @param int|string|array required $country_identifier the country identifier, can be the string ISO code, * or the integer country id, or an array of data used * to create a new country * * @return object WPSC_Country */ public function __construct($country, $deprecated = null) { if ($country) { if (is_array($country)) { // if we get an array as an argument we are making a new country $country_id_or_isocode = WPSC_Countries::_save_country_data($country); } else { // we are constructing a country using a numeric id or ISO code $country_id_or_isocode = $country; } // make sure we have a valid country id $country_id = WPSC_Countries::get_country_id($country_id_or_isocode); if ($country_id) { $wpsc_country = WPSC_Countries::get_country($country_id); foreach ($wpsc_country as $property => $value) { // copy the properties in this copy of the country $this->{$property} = $value; } } } // if the regions maps has not been initialized we should create an empty map now if (empty($this->_regions)) { $this->_regions = new WPSC_Data_Map(); } if (empty($this->_region_id_by_region_code)) { $this->_region_id_by_region_code = new WPSC_Data_Map(); } if (empty($this->_region_id_by_region_name)) { $this->_region_id_by_region_name = new WPSC_Data_Map(); } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // As a result of merging the legacy WPSC_Country class we no longer need the "col" constructor parameter // that was in the prior version of this class. // // if deprecated processing is enabled we will give a message, just as if we were allowed to put class // methods in the deprecated file, if deprecated processing is not enabled we exit with the method, much // like would happen with an undefined function call. // // TODO: This processing is added at version 3.8.14 and intended to be removed after a reasonable number // of interim releases. See GitHub Issue https://github.com/wp-e-commerce/WP-e-Commerce/issues/1016 ///////////////////////////////////////////////////////////////////////////////////////////////////////// if (!empty($deprecated)) { if (defined('WPSC_LOAD_DEPRECATED') && WPSC_LOAD_DEPRECATED) { _wpsc_deprecated_argument(__FUNCTION__, '3.8.14', $this->_parameter_no_longer_used_message('col', __FUNCTION__)); } } // setup default properties filter add_filter('wpsc_country_get_property', array(__CLASS__, '_wpsc_country_default_properties'), 10, 2); }