use new list of countries and adapt backend and frontend to it

This commit is contained in:
GotPPay
2018-09-13 05:50:10 +02:00
committed by Bilal Catic
parent 5d91576fb7
commit b93aed107b
4 changed files with 28 additions and 47 deletions

View File

@@ -9,7 +9,7 @@ class Wiass_REST_User_API {
private static $namespace = 'wiaas'; private static $namespace = 'wiaas';
public function __construct() { 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(){ 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); return new WP_REST_Response($countries);
} }

View File

@@ -17,18 +17,21 @@ class Wiaas_Countries {
*/ */
private static $available_countries = array( private static $available_countries = array(
'Sweden' => array( 'Sweden' => array(
'id' => 1,
'name' => 'Sweden', 'name' => 'Sweden',
'code' => 'se', 'code' => 'se',
'vat' => 9 , 'vat' => 9 ,
'currency' => 'SEK' 'currency' => 'SEK'
), ),
'Denmark' => array( 'Denmark' => array(
'id' => 2,
'name' => 'Denmark', 'name' => 'Denmark',
'code' => 'dk', 'code' => 'dk',
'vat' => 9 , 'vat' => 9 ,
'currency' => 'DKK' 'currency' => 'DKK'
), ),
'Finland' => array( 'Finland' => array(
'id' => 3,
'name' => 'Finland', 'name' => 'Finland',
'code' => 'fi', 'code' => 'fi',
'vat' => 9 , 'vat' => 9 ,
@@ -41,6 +44,24 @@ class Wiaas_Countries {
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy')); 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 * Registers product taxonomy for avaiable countries
*/ */

View File

@@ -8,7 +8,7 @@ defined( 'ABSPATH' ) || exit;
class Wiaas_User { class Wiaas_User {
public static function init() { 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('init', array(__CLASS__, 'load_user_organization'));
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30); add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
@@ -45,7 +45,7 @@ class Wiaas_User {
if ($received_address->id){ if ($received_address->id){
$updated = array( $updated = array(
'id' => $received_address->id, '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, 'deliveryMail' => $received_address->deliveryMail,
'idCountrySelected' => $received_address->idCountrySelected, 'idCountrySelected' => $received_address->idCountrySelected,
'city' => $received_address->city, 'city' => $received_address->city,
@@ -64,7 +64,7 @@ class Wiaas_User {
}else{ }else{
$new_delivery_address = array( $new_delivery_address = array(
'id' => time(), '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, 'deliveryMail' => $received_address->deliveryMail,
'idCountrySelected' => $received_address->idCountrySelected, 'idCountrySelected' => $received_address->idCountrySelected,
'city' => $received_address->city, 'city' => $received_address->city,
@@ -89,7 +89,7 @@ class Wiaas_User {
if ($received_address->id){ if ($received_address->id){
$updated = array( $updated = array(
'id' => $received_address->id, '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, 'deliveryMail' => $received_address->deliveryMail,
'idCountrySelected' => $received_address->idCountrySelected, 'idCountrySelected' => $received_address->idCountrySelected,
'city' => $received_address->city, 'city' => $received_address->city,
@@ -108,7 +108,7 @@ class Wiaas_User {
}else{ }else{
$new_billing_address = array( $new_billing_address = array(
'id' => time(), '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, 'deliveryMail' => $received_address->deliveryMail,
'idCountrySelected' => $received_address->idCountrySelected, 'idCountrySelected' => $received_address->idCountrySelected,
'city' => $received_address->city, 'city' => $received_address->city,

View File

@@ -1,40 +0,0 @@
<?php
// Exit if accessed directly
defined( 'ABSPATH' ) || exit;
class Wiaas_User_Profile {
const LIST_OF_COUNTRIES = [
array(
'idCountry' => '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 '';
}
}