diff --git a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php index 0ebfb24..1615ad5 100644 --- a/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php +++ b/backend/app/plugins/wiaas/includes/api/class-wiaas-rest-user-api.php @@ -9,7 +9,7 @@ class Wiass_REST_User_API { private static $namespace = 'wiaas'; public function __construct() { - include_once dirname( __FILE__ ) . '/user/class-wiaas-user-profile.php'; + include_once dirname( __FILE__ ) . '/../class-wiaas-countries.php'; } @@ -43,7 +43,7 @@ class Wiass_REST_User_API { } public static function get_countries(){ - $countries = Wiaas_User_Profile::get_list_of_countries(); + $countries = Wiaas_Countries::get_list_of_countries(); return new WP_REST_Response($countries); } diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-countries.php b/backend/app/plugins/wiaas/includes/class-wiaas-countries.php index 375a013..f88e161 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-countries.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-countries.php @@ -17,18 +17,21 @@ class Wiaas_Countries { */ private static $available_countries = array( 'Sweden' => array( + 'id' => 1, 'name' => 'Sweden', 'code' => 'se', 'vat' => 9 , 'currency' => 'SEK' ), 'Denmark' => array( + 'id' => 2, 'name' => 'Denmark', 'code' => 'dk', 'vat' => 9 , 'currency' => 'DKK' ), 'Finland' => array( + 'id' => 3, 'name' => 'Finland', 'code' => 'fi', 'vat' => 9 , @@ -41,6 +44,24 @@ class Wiaas_Countries { add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy')); } + public static function get_list_of_countries(){ + $result = []; + foreach(self::$available_countries as $country){ + array_push($result, array( + 'idCountry' => $country['id'], + 'countryName' => $country['name'] + )); + } + return $result; + } + + public static function get_country_name_by_id($id){ + foreach(self::$available_countries as $country){ + if ($country['id'] == $id) return $country['name']; + } + return ''; + } + /** * Registers product taxonomy for avaiable countries */ diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-user.php b/backend/app/plugins/wiaas/includes/class-wiaas-user.php index fe6efd0..69441de 100644 --- a/backend/app/plugins/wiaas/includes/class-wiaas-user.php +++ b/backend/app/plugins/wiaas/includes/class-wiaas-user.php @@ -8,7 +8,7 @@ defined( 'ABSPATH' ) || exit; class Wiaas_User { public static function init() { - include_once dirname( __FILE__ ) . '/user/class-wiaas-user-profile.php'; + include_once dirname( __FILE__ ) . '/class-wiaas-countries.php'; add_action('init', array(__CLASS__, 'load_user_organization')); add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30); @@ -45,7 +45,7 @@ class Wiaas_User { if ($received_address->id){ $updated = array( 'id' => $received_address->id, - 'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected), + 'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected), 'deliveryMail' => $received_address->deliveryMail, 'idCountrySelected' => $received_address->idCountrySelected, 'city' => $received_address->city, @@ -64,7 +64,7 @@ class Wiaas_User { }else{ $new_delivery_address = array( 'id' => time(), - 'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected), + 'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected), 'deliveryMail' => $received_address->deliveryMail, 'idCountrySelected' => $received_address->idCountrySelected, 'city' => $received_address->city, @@ -89,7 +89,7 @@ class Wiaas_User { if ($received_address->id){ $updated = array( 'id' => $received_address->id, - 'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected), + 'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected), 'deliveryMail' => $received_address->deliveryMail, 'idCountrySelected' => $received_address->idCountrySelected, 'city' => $received_address->city, @@ -108,7 +108,7 @@ class Wiaas_User { }else{ $new_billing_address = array( 'id' => time(), - 'countryName' => Wiaas_User_Profile::get_country_name_by_id($received_address->idCountrySelected), + 'countryName' => Wiaas_Countries::get_country_name_by_id($received_address->idCountrySelected), 'deliveryMail' => $received_address->deliveryMail, 'idCountrySelected' => $received_address->idCountrySelected, 'city' => $received_address->city, diff --git a/backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php b/backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php deleted file mode 100644 index a13ede6..0000000 --- a/backend/app/plugins/wiaas/includes/user/class-wiaas-user-profile.php +++ /dev/null @@ -1,40 +0,0 @@ - '1', - 'countryName' => 'Sweden' - ), - array( - 'idCountry' => '2', - 'countryName' => 'Finland' - ), - array( - 'idCountry' => '3', - 'countryName' => 'Denmark' - ) - ]; - - public static function get_list_of_countries(){ - return self::LIST_OF_COUNTRIES; - } - - public static function check_country_id($id){ - foreach (self::LIST_OF_COUNTRIES as $country){ - if ($country['idCountry'] === $id) return true; - } - return false; - } - - public static function get_country_name_by_id($id){ - foreach(self::LIST_OF_COUNTRIES as $country){ - if ($country['idCountry'] === $id) return $country['countryName']; - } - return ''; - } -} \ No newline at end of file