diff --git a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-countries.php b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-countries.php
new file mode 100644
index 0000000..342f59f
--- /dev/null
+++ b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-countries.php
@@ -0,0 +1,71 @@
+'. $code . '';
+ }
+
+ if ($column === 'wiaas_vat') {
+
+ $vat = get_term_meta($id, '_wiaas_country_vat', true);
+ $columns .= ''. $vat . '';
+ }
+
+ if ($column === 'wiaas_currency') {
+
+ $currency = get_term_meta($id, '_wiaas_country_currency', true);
+ $columns .= ''. $currency . '';
+ }
+
+ return $columns;
+ }
+
+ public static function populate_country_codes($field) {
+ $countries_list = Wiaas_Countries::get_country_choices();
+
+ $countries_choices = array();
+ foreach ($countries_list as $code => $name) {
+
+ $countries_choices[$code] = $code . ' - ' . $name;
+ }
+
+ $field['choices'] = $countries_choices;
+
+ return $field;
+ }
+
+ public static function populate_country_currencies($field) {
+
+ $field['choices'] = Wiaas_Countries::get_currency_choices();
+
+ return $field;
+ }
+}
+
+Wiaas_Admin_Countries::init();
diff --git a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php
index 981a56e..6f99af4 100644
--- a/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php
+++ b/backend/app/plugins/wiaas/includes/admin/class-wiaas-admin-delivery-process.php
@@ -7,6 +7,7 @@ class Wiaas_Admin_Delivery_Process {
require_once dirname( __FILE__ ) . '/delivery-process/wiaas-admin-delivery-process-ajax.php';
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-flow.php';
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-order.php';
+ require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-delivery-process-list.php';
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
}
diff --git a/backend/app/plugins/wiaas/includes/admin/delivery-process/class-wiaas-admin-delivery-process-list.php b/backend/app/plugins/wiaas/includes/admin/delivery-process/class-wiaas-admin-delivery-process-list.php
new file mode 100644
index 0000000..596c8a5
--- /dev/null
+++ b/backend/app/plugins/wiaas/includes/admin/delivery-process/class-wiaas-admin-delivery-process-list.php
@@ -0,0 +1,150 @@
+id );
+
+ $title = strtolower($form_details['title']);
+
+ $delivery_settings = rgar($form_details, 'wiaas_delivery_process');
+ $country_code = ! empty($delivery_settings) ? $delivery_settings['delivery_country'] : '';
+ $country_name = Wiaas_Countries::get_available_country_name_by_code($country_code);
+ $country_name = strtolower($country_name);
+
+ if (strpos($title, $search_query) !== false || strpos($country_code, $search_query) !== false ||
+ strpos($country_name, $search_query) !== false) {
+ $filtered_forms[] = $form;
+ }
+ }
+
+ return $filtered_forms;
+ }
+
+ return $forms;
+ }
+
+ /**
+ * Remove unused actions and add workflow action for delivery forms list
+ *
+ * @param array $actions
+ * @param int $form_id
+ *
+ * @return mixed
+ */
+ public static function filter_gform_form_actions($actions, $form_id) {
+ unset($actions['entries']);
+ unset($actions['preview']);
+ unset($actions['edit']);
+
+ $actions['wiaas_workflow'] = array(
+ 'label' => __( 'Workflow', 'wiaas' ),
+ 'short_label' => esc_html__( 'Workflow', 'wiaas' ),
+ 'title' => __( 'Edit workflow', 'wiaas' ),
+ 'url' => '?page=gf_edit_forms&view=settings&id=' . $form_id . '&subview=gravityflow',
+ 'priority' => 1000,
+ );
+
+ return $actions;
+ }
+
+ /**
+ * Render country column for delivery process forms list
+ *
+ * @param mixed $form
+ */
+ public static function render_gform_form_list_wiaas_country_column($form) {
+
+ $form_details = GFAPI::get_form($form->id);
+ $delivery_settings = rgar($form_details, 'wiaas_delivery_process');
+
+ $country_code = ! empty($delivery_settings) ? $delivery_settings['delivery_country'] : '';
+
+ $country_name = Wiaas_Countries::get_available_country_name_by_code($country_code);
+
+ echo '' . esc_html_e($country_name) . '';
+ }
+
+ /**
+ * Render actions column for delivery process forms list
+ * @param mixed $form
+ */
+ public static function render_gform_form_list_wiaas_actions_column($form) {
+
+ $form_details = GFAPI::get_form($form->id);
+ $delivery_settings = rgar($form_details, 'wiaas_delivery_process');
+
+ $form_type = ! empty($delivery_settings) ? $delivery_settings['delivery_form_type'] : '';
+
+ ?>
+ Workflow
+
+ |
+ Change Country
+ get_currency())
- );
+ $list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country($country_code);
?>
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 2b8cf3e..44bad74 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
@@ -43,7 +43,7 @@ class Wiass_REST_User_API {
}
public static function get_countries(){
- $countries = Wiaas_Countries::get_list_of_countries();
+ $countries = Wiaas_Countries::get_available_countries();
return rest_ensure_response($countries);
}
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-admin.php b/backend/app/plugins/wiaas/includes/class-wiaas-admin.php
index 5c5ef1f..45cb271 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-admin.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-admin.php
@@ -30,6 +30,8 @@ class Wiaas_Admin {
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-user-profile.php';
+ require_once dirname(__FILE__) . '/admin/class-wiaas-admin-countries.php';
+
add_action( 'admin_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'), 100 );
}
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php
index 4549663..3f3e766 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-cart.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-cart.php
@@ -492,6 +492,8 @@ class Wiaas_Cart {
$country = get_user_meta(get_current_user_id(), '_wiaas_cart_items_country', true);
$currency = empty($country) ? get_woocommerce_currency() : $country['currency'];
+ $order->add_meta_data('_wiaas_country_code', $country['code']);
+
$order->set_currency($currency);
// get order commercial lead
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-countries.php b/backend/app/plugins/wiaas/includes/class-wiaas-countries.php
index a88c14f..bf67897 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-countries.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-countries.php
@@ -12,28 +12,19 @@ if ( ! defined( 'ABSPATH' ) ) {
class Wiaas_Countries {
/**
- * Available countries for wiaas
+ * Default available countries for wiaas
* @var array
*/
- private static $available_countries = array(
- 'Sweden' => array(
- 'id' => 1,
- 'name' => 'Sweden',
- 'code' => 'se',
+ private static $default_countries = array(
+ 'se' => array(
'vat' => 9 ,
'currency' => 'SEK'
),
- 'Denmark' => array(
- 'id' => 2,
- 'name' => 'Denmark',
- 'code' => 'dk',
+ 'dk' => array(
'vat' => 9 ,
'currency' => 'DKK'
),
- 'Finland' => array(
- 'id' => 3,
- 'name' => 'Finland',
- 'code' => 'fi',
+ 'fi' => array(
'vat' => 9 ,
'currency' => 'EUR'
),
@@ -44,31 +35,97 @@ 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(
- 'country_id' => $country['id'],
- 'country_name' => $country['name']
- ));
+ /**
+ * Retrieve all possible country choices
+ *
+ * @return array
+ */
+ public static function get_country_choices() {
+ $countries = new WC_Countries();
+ $choices = array();
+
+ foreach ($countries->get_countries() as $code => $name) {
+ $choices[strtolower($code)] = $name;
}
- return $result;
+
+ return $choices;
}
- public static function get_country_name_by_id($id){
- foreach(self::$available_countries as $country){
- if ($country['id'] == $id) return $country['name'];
- }
- return '';
+ /**
+ * Retrieve all possible currency choices
+ *
+ * @return array
+ */
+ public static function get_currency_choices() {
+ return get_woocommerce_currencies();
}
- public static function get_country_code_by_currency($currency) {
+ /**
+ * Retrieve list of available countries setup by administrator
+ *
+ * @return array
+ */
+ public static function get_available_countries() {
+ $available_countries = [];
- foreach (self::$available_countries as $country) {
+ $available_country_terms = get_terms(array(
+ 'taxonomy' => 'product_country',
+ 'hide_empty' => false,
+ ));
- if ($country['currency'] === $currency) {
+ foreach($available_country_terms as $country_term) {
+ $code = get_term_meta($country_term->term_id, '_wiaas_country_code', true);
+ $currency = get_term_meta($country_term->term_id, '_wiaas_country_currency', true);
+ $vat = get_term_meta($country_term->term_id, '_wiaas_country_vat', true);
- return $country['code'];
+ $available_countries[] = array(
+ 'id' => $country_term->term_id,
+ 'name' => $country_term->name,
+ 'code' => $code,
+ 'currency' => $currency,
+ 'vat' => $vat
+ );
+ }
+
+ return $available_countries;
+ }
+
+ /**
+ * Retrieve country name by code for available country
+ *
+ * @param string $code
+ *
+ * @return string|null
+ */
+ public static function get_available_country_name_by_code($code) {
+ $available_countries = self::get_available_countries();
+
+ foreach ($available_countries as $available_country) {
+
+ if ($available_country['code'] === $code) {
+
+ return $available_country['name'];
+ }
+ }
+
+ return null;
+ }
+
+ /**
+ * Retrieve country code by currency for available country
+ *
+ * @param string $currency
+ *
+ * @return string|null
+ */
+ public static function get_available_country_code_by_currency($currency) {
+ $available_countries = self::get_available_countries();
+
+ foreach ($available_countries as $available_country) {
+
+ if ($available_country['currency'] === $currency) {
+
+ return $available_country['code'];
}
}
@@ -106,8 +163,27 @@ class Wiaas_Countries {
register_taxonomy( 'product_country', array( 'product' ), $args );
- foreach (self::$available_countries as $available_country) {
- wp_insert_term($available_country['name'], 'product_country');
+ $choices = self::get_country_choices();
+
+ foreach (self::$default_countries as $code => $info) {
+
+ $name = $choices[$code];
+
+ if (has_term($name)) {
+ // bail out
+ return;
+ }
+
+ $name = $choices[$code];
+ $result = wp_insert_term($name, 'product_country');
+
+ if (is_wp_error($result)) {
+ continue;
+ }
+
+ update_term_meta($result->term_id, '_wiaas_country_code', $code);
+ update_term_meta($result->term_id, '_wiaas_country_currency', $info['currency']);
+ update_term_meta($result->term_id, '_wiaas_country_vat', $info['vat']);
}
}
@@ -128,10 +204,25 @@ class Wiaas_Countries {
* @return array|null
*/
public static function get_product_country($product) {
- $product_country = get_the_terms($product->get_id(), 'product_country');
- return is_array($product_country) && isset($product_country[0]) ?
- self::$available_countries[$product_country[0]->name] :
- null;
+ $country_terms = get_the_terms($product->get_id(), 'product_country');
+
+ if (is_wp_error($country_terms) || empty($country_terms) || empty($country_terms[0])) {
+ return null;
+ }
+
+ $country_term = $country_terms[0];
+
+ $code = get_term_meta($country_term->term_id, '_wiaas_country_code', true);
+ $currency = get_term_meta($country_term->term_id, '_wiaas_country_currency', true);
+ $vat = get_term_meta($country_term->term_id, '_wiaas_country_vat', true);
+
+ return array(
+ 'id' => $country_term->term_id,
+ 'name' => $country_term->name,
+ 'code' => $code,
+ 'currency' => $currency,
+ 'vat' => $vat
+ );
}
/**
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php b/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php
index 73c78cd..94bfa13 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-db-update.php
@@ -18,15 +18,18 @@ class Wiaas_DB_Update {
'20181018044450' => 'wiaas_db_setup_create_customer_commercial_lead_table',
'20181018054450' => 'wiaas_db_update_update_commercial_lead_capabilities',
'20181018064450' => 'wiaas_db_update_add_organization_info_ui_fields',
- '20191019014550' => 'wiaas_db_update_add_general_ui_fields',
- '20191019014650' => 'wiaas_db_update_add_product_properties_ui_fields',
- '20191020014650' => 'wiaas_create_organization_roles_capabilities',
- '20191030162450' => 'wiaas_db_update_update_supplier_order_capabilities',
- '20191102112451' => 'wiaas_disable_processing_order_email_delivery',
- '20191131172850' => 'wiaas_db_update_update_delivery_forms',
- '20191131182856' => 'wiaas_db_update_enable_workflow_inbox_for_roles',
- '20191201133550' => 'wiaas_db_update_add_bundle_properties_ui_field',
- '20191202133553' => 'wiaas_db_update_add_installation_date_delivery_action_form'
+ '20181019014550' => 'wiaas_db_update_add_general_ui_fields',
+ '20181019014650' => 'wiaas_db_update_add_product_properties_ui_fields',
+ '20181020014650' => 'wiaas_create_organization_roles_capabilities',
+ '20181021162450' => 'wiaas_db_update_update_supplier_order_capabilities',
+ '20181102112451' => 'wiaas_disable_processing_order_email_delivery',
+ '20181103172850' => 'wiaas_db_update_update_delivery_forms',
+ '20181104182856' => 'wiaas_db_update_enable_workflow_inbox_for_roles',
+ '20181105133550' => 'wiaas_db_update_add_bundle_properties_ui_field',
+ '20181106133553' => 'wiaas_db_update_add_installation_date_delivery_action_form',
+ '20181125133553' => 'wiaas_db_update_add_country_settings_ui_fields',
+ '20181125143553' => 'wiaas_db_migration_fix_user_profile_addresses', // remove after migration
+ '20181125153553' => 'wiaas_db_migration_fix_countries' // remove after migration
);
public static function execute() {
diff --git a/backend/app/plugins/wiaas/includes/class-wiaas-order.php b/backend/app/plugins/wiaas/includes/class-wiaas-order.php
index ec34773..f5042b9 100644
--- a/backend/app/plugins/wiaas/includes/class-wiaas-order.php
+++ b/backend/app/plugins/wiaas/includes/class-wiaas-order.php
@@ -400,7 +400,22 @@ class Wiaas_Order {
public static function get_order_tender($order_id) {
return get_post_meta($order_id, '_wiaas_tender', true);
- }
+ }
+
+ public static function get_order_country_code($order_id) {
+
+ $order = wc_get_order($order_id);
+
+ $code = $order->get_meta('_wiaas_country_code');
+
+ if (empty($code)) {
+ $code = Wiaas_Countries::get_available_country_code_by_currency($order->get_currency());
+ $order->add_meta_data('_wiaas_country_code', $code);
+ $order->save_meta_data();
+ }
+
+ return $code;
+ }
/**
* PRIVATE
diff --git a/backend/app/plugins/wiaas/includes/db-updates/data/wiaas-ui-field-country-settings.json b/backend/app/plugins/wiaas/includes/db-updates/data/wiaas-ui-field-country-settings.json
new file mode 100644
index 0000000..cf148aa
--- /dev/null
+++ b/backend/app/plugins/wiaas/includes/db-updates/data/wiaas-ui-field-country-settings.json
@@ -0,0 +1,501 @@
+[
+ {
+ "key": "group_5bdad38fcebee",
+ "title": "Country settings",
+ "fields": [
+ {
+ "key": "field_5bdad398384e1",
+ "label": "Code",
+ "name": "_wiaas_country_code",
+ "type": "select",
+ "instructions": "",
+ "required": 1,
+ "conditional_logic": 0,
+ "wrapper": {
+ "width": "",
+ "class": "",
+ "id": ""
+ },
+ "choices": {
+ "ax": "ax - Åland Islands",
+ "af": "af - Afghanistan",
+ "al": "al - Albania",
+ "dz": "dz - Algeria",
+ "as": "as - American Samoa",
+ "ad": "ad - Andorra",
+ "ao": "ao - Angola",
+ "ai": "ai - Anguilla",
+ "aq": "aq - Antarctica",
+ "ag": "ag - Antigua and Barbuda",
+ "ar": "ar - Argentina",
+ "am": "am - Armenia",
+ "aw": "aw - Aruba",
+ "au": "au - Australia",
+ "at": "at - Austria",
+ "az": "az - Azerbaijan",
+ "bs": "bs - Bahamas",
+ "bh": "bh - Bahrain",
+ "bd": "bd - Bangladesh",
+ "bb": "bb - Barbados",
+ "by": "by - Belarus",
+ "pw": "pw - Belau",
+ "be": "be - Belgium",
+ "bz": "bz - Belize",
+ "bj": "bj - Benin",
+ "bm": "bm - Bermuda",
+ "bt": "bt - Bhutan",
+ "bo": "bo - Bolivia",
+ "bq": "bq - Bonaire, Saint Eustatius and Saba",
+ "ba": "ba - Bosnia and Herzegovina",
+ "bw": "bw - Botswana",
+ "bv": "bv - Bouvet Island",
+ "br": "br - Brazil",
+ "io": "io - British Indian Ocean Territory",
+ "vg": "vg - British Virgin Islands",
+ "bn": "bn - Brunei",
+ "bg": "bg - Bulgaria",
+ "bf": "bf - Burkina Faso",
+ "bi": "bi - Burundi",
+ "kh": "kh - Cambodia",
+ "cm": "cm - Cameroon",
+ "ca": "ca - Canada",
+ "cv": "cv - Cape Verde",
+ "ky": "ky - Cayman Islands",
+ "cf": "cf - Central African Republic",
+ "td": "td - Chad",
+ "cl": "cl - Chile",
+ "cn": "cn - China",
+ "cx": "cx - Christmas Island",
+ "cc": "cc - Cocos (Keeling) Islands",
+ "co": "co - Colombia",
+ "km": "km - Comoros",
+ "cg": "cg - Congo (Brazzaville)",
+ "cd": "cd - Congo (Kinshasa)",
+ "ck": "ck - Cook Islands",
+ "cr": "cr - Costa Rica",
+ "hr": "hr - Croatia",
+ "cu": "cu - Cuba",
+ "cw": "cw - Curaçao",
+ "cy": "cy - Cyprus",
+ "cz": "cz - Czech Republic",
+ "dk": "dk - Denmark",
+ "dj": "dj - Djibouti",
+ "dm": "dm - Dominica",
+ "do": "do - Dominican Republic",
+ "ec": "ec - Ecuador",
+ "eg": "eg - Egypt",
+ "sv": "sv - El Salvador",
+ "gq": "gq - Equatorial Guinea",
+ "er": "er - Eritrea",
+ "ee": "ee - Estonia",
+ "et": "et - Ethiopia",
+ "fk": "fk - Falkland Islands",
+ "fo": "fo - Faroe Islands",
+ "fj": "fj - Fiji",
+ "fi": "fi - Finland",
+ "fr": "fr - France",
+ "gf": "gf - French Guiana",
+ "pf": "pf - French Polynesia",
+ "tf": "tf - French Southern Territories",
+ "ga": "ga - Gabon",
+ "gm": "gm - Gambia",
+ "ge": "ge - Georgia",
+ "de": "de - Germany",
+ "gh": "gh - Ghana",
+ "gi": "gi - Gibraltar",
+ "gr": "gr - Greece",
+ "gl": "gl - Greenland",
+ "gd": "gd - Grenada",
+ "gp": "gp - Guadeloupe",
+ "gu": "gu - Guam",
+ "gt": "gt - Guatemala",
+ "gg": "gg - Guernsey",
+ "gn": "gn - Guinea",
+ "gw": "gw - Guinea-Bissau",
+ "gy": "gy - Guyana",
+ "ht": "ht - Haiti",
+ "hm": "hm - Heard Island and McDonald Islands",
+ "hn": "hn - Honduras",
+ "hk": "hk - Hong Kong",
+ "hu": "hu - Hungary",
+ "is": "is - Iceland",
+ "in": "in - India",
+ "id": "id - Indonesia",
+ "ir": "ir - Iran",
+ "iq": "iq - Iraq",
+ "ie": "ie - Ireland",
+ "im": "im - Isle of Man",
+ "il": "il - Israel",
+ "it": "it - Italy",
+ "ci": "ci - Ivory Coast",
+ "jm": "jm - Jamaica",
+ "jp": "jp - Japan",
+ "je": "je - Jersey",
+ "jo": "jo - Jordan",
+ "kz": "kz - Kazakhstan",
+ "ke": "ke - Kenya",
+ "ki": "ki - Kiribati",
+ "kw": "kw - Kuwait",
+ "kg": "kg - Kyrgyzstan",
+ "la": "la - Laos",
+ "lv": "lv - Latvia",
+ "lb": "lb - Lebanon",
+ "ls": "ls - Lesotho",
+ "lr": "lr - Liberia",
+ "ly": "ly - Libya",
+ "li": "li - Liechtenstein",
+ "lt": "lt - Lithuania",
+ "lu": "lu - Luxembourg",
+ "mo": "mo - Macao S.A.R., China",
+ "mk": "mk - Macedonia",
+ "mg": "mg - Madagascar",
+ "mw": "mw - Malawi",
+ "my": "my - Malaysia",
+ "mv": "mv - Maldives",
+ "ml": "ml - Mali",
+ "mt": "mt - Malta",
+ "mh": "mh - Marshall Islands",
+ "mq": "mq - Martinique",
+ "mr": "mr - Mauritania",
+ "mu": "mu - Mauritius",
+ "yt": "yt - Mayotte",
+ "mx": "mx - Mexico",
+ "fm": "fm - Micronesia",
+ "md": "md - Moldova",
+ "mc": "mc - Monaco",
+ "mn": "mn - Mongolia",
+ "me": "me - Montenegro",
+ "ms": "ms - Montserrat",
+ "ma": "ma - Morocco",
+ "mz": "mz - Mozambique",
+ "mm": "mm - Myanmar",
+ "na": "na - Namibia",
+ "nr": "nr - Nauru",
+ "np": "np - Nepal",
+ "nl": "nl - Netherlands",
+ "nc": "nc - New Caledonia",
+ "nz": "nz - New Zealand",
+ "ni": "ni - Nicaragua",
+ "ne": "ne - Niger",
+ "ng": "ng - Nigeria",
+ "nu": "nu - Niue",
+ "nf": "nf - Norfolk Island",
+ "kp": "kp - North Korea",
+ "mp": "mp - Northern Mariana Islands",
+ "no": "no - Norway",
+ "om": "om - Oman",
+ "pk": "pk - Pakistan",
+ "ps": "ps - Palestinian Territory",
+ "pa": "pa - Panama",
+ "pg": "pg - Papua New Guinea",
+ "py": "py - Paraguay",
+ "pe": "pe - Peru",
+ "ph": "ph - Philippines",
+ "pn": "pn - Pitcairn",
+ "pl": "pl - Poland",
+ "pt": "pt - Portugal",
+ "pr": "pr - Puerto Rico",
+ "qa": "qa - Qatar",
+ "re": "re - Reunion",
+ "ro": "ro - Romania",
+ "ru": "ru - Russia",
+ "rw": "rw - Rwanda",
+ "st": "st - São Tomé and Príncipe",
+ "bl": "bl - Saint Barthélemy",
+ "sh": "sh - Saint Helena",
+ "kn": "kn - Saint Kitts and Nevis",
+ "lc": "lc - Saint Lucia",
+ "sx": "sx - Saint Martin (Dutch part)",
+ "mf": "mf - Saint Martin (French part)",
+ "pm": "pm - Saint Pierre and Miquelon",
+ "vc": "vc - Saint Vincent and the Grenadines",
+ "ws": "ws - Samoa",
+ "sm": "sm - San Marino",
+ "sa": "sa - Saudi Arabia",
+ "sn": "sn - Senegal",
+ "rs": "rs - Serbia",
+ "sc": "sc - Seychelles",
+ "sl": "sl - Sierra Leone",
+ "sg": "sg - Singapore",
+ "sk": "sk - Slovakia",
+ "si": "si - Slovenia",
+ "sb": "sb - Solomon Islands",
+ "so": "so - Somalia",
+ "za": "za - South Africa",
+ "gs": "gs - South Georgia\/Sandwich Islands",
+ "kr": "kr - South Korea",
+ "ss": "ss - South Sudan",
+ "es": "es - Spain",
+ "lk": "lk - Sri Lanka",
+ "sd": "sd - Sudan",
+ "sr": "sr - Suriname",
+ "sj": "sj - Svalbard and Jan Mayen",
+ "sz": "sz - Swaziland",
+ "se": "se - Sweden",
+ "ch": "ch - Switzerland",
+ "sy": "sy - Syria",
+ "tw": "tw - Taiwan",
+ "tj": "tj - Tajikistan",
+ "tz": "tz - Tanzania",
+ "th": "th - Thailand",
+ "tl": "tl - Timor-Leste",
+ "tg": "tg - Togo",
+ "tk": "tk - Tokelau",
+ "to": "to - Tonga",
+ "tt": "tt - Trinidad and Tobago",
+ "tn": "tn - Tunisia",
+ "tr": "tr - Turkey",
+ "tm": "tm - Turkmenistan",
+ "tc": "tc - Turks and Caicos Islands",
+ "tv": "tv - Tuvalu",
+ "ug": "ug - Uganda",
+ "ua": "ua - Ukraine",
+ "ae": "ae - United Arab Emirates",
+ "gb": "gb - United Kingdom (UK)",
+ "us": "us - United States (US)",
+ "um": "um - United States (US) Minor Outlying Islands",
+ "vi": "vi - United States (US) Virgin Islands",
+ "uy": "uy - Uruguay",
+ "uz": "uz - Uzbekistan",
+ "vu": "vu - Vanuatu",
+ "va": "va - Vatican",
+ "ve": "ve - Venezuela",
+ "vn": "vn - Vietnam",
+ "wf": "wf - Wallis and Futuna",
+ "eh": "eh - Western Sahara",
+ "ye": "ye - Yemen",
+ "zm": "zm - Zambia",
+ "zw": "zw - Zimbabwe"
+ },
+ "default_value": [],
+ "allow_null": 0,
+ "multiple": 0,
+ "ui": 1,
+ "ajax": 0,
+ "return_format": "value",
+ "placeholder": ""
+ },
+ {
+ "key": "field_5bfc4b4fa5992",
+ "label": "Currency",
+ "name": "_wiaas_country_currency",
+ "type": "select",
+ "instructions": "",
+ "required": 1,
+ "conditional_logic": 0,
+ "wrapper": {
+ "width": "",
+ "class": "",
+ "id": ""
+ },
+ "choices": {
+ "AED": "United Arab Emirates dirham",
+ "AFN": "Afghan afghani",
+ "ALL": "Albanian lek",
+ "AMD": "Armenian dram",
+ "ANG": "Netherlands Antillean guilder",
+ "AOA": "Angolan kwanza",
+ "ARS": "Argentine peso",
+ "AUD": "Australian dollar",
+ "AWG": "Aruban florin",
+ "AZN": "Azerbaijani manat",
+ "BAM": "Bosnia and Herzegovina convertible mark",
+ "BBD": "Barbadian dollar",
+ "BDT": "Bangladeshi taka",
+ "BGN": "Bulgarian lev",
+ "BHD": "Bahraini dinar",
+ "BIF": "Burundian franc",
+ "BMD": "Bermudian dollar",
+ "BND": "Brunei dollar",
+ "BOB": "Bolivian boliviano",
+ "BRL": "Brazilian real",
+ "BSD": "Bahamian dollar",
+ "BTC": "Bitcoin",
+ "BTN": "Bhutanese ngultrum",
+ "BWP": "Botswana pula",
+ "BYR": "Belarusian ruble (old)",
+ "BYN": "Belarusian ruble",
+ "BZD": "Belize dollar",
+ "CAD": "Canadian dollar",
+ "CDF": "Congolese franc",
+ "CHF": "Swiss franc",
+ "CLP": "Chilean peso",
+ "CNY": "Chinese yuan",
+ "COP": "Colombian peso",
+ "CRC": "Costa Rican colón",
+ "CUC": "Cuban convertible peso",
+ "CUP": "Cuban peso",
+ "CVE": "Cape Verdean escudo",
+ "CZK": "Czech koruna",
+ "DJF": "Djiboutian franc",
+ "DKK": "Danish krone",
+ "DOP": "Dominican peso",
+ "DZD": "Algerian dinar",
+ "EGP": "Egyptian pound",
+ "ERN": "Eritrean nakfa",
+ "ETB": "Ethiopian birr",
+ "EUR": "Euro",
+ "FJD": "Fijian dollar",
+ "FKP": "Falkland Islands pound",
+ "GBP": "Pound sterling",
+ "GEL": "Georgian lari",
+ "GGP": "Guernsey pound",
+ "GHS": "Ghana cedi",
+ "GIP": "Gibraltar pound",
+ "GMD": "Gambian dalasi",
+ "GNF": "Guinean franc",
+ "GTQ": "Guatemalan quetzal",
+ "GYD": "Guyanese dollar",
+ "HKD": "Hong Kong dollar",
+ "HNL": "Honduran lempira",
+ "HRK": "Croatian kuna",
+ "HTG": "Haitian gourde",
+ "HUF": "Hungarian forint",
+ "IDR": "Indonesian rupiah",
+ "ILS": "Israeli new shekel",
+ "IMP": "Manx pound",
+ "INR": "Indian rupee",
+ "IQD": "Iraqi dinar",
+ "IRR": "Iranian rial",
+ "IRT": "Iranian toman",
+ "ISK": "Icelandic króna",
+ "JEP": "Jersey pound",
+ "JMD": "Jamaican dollar",
+ "JOD": "Jordanian dinar",
+ "JPY": "Japanese yen",
+ "KES": "Kenyan shilling",
+ "KGS": "Kyrgyzstani som",
+ "KHR": "Cambodian riel",
+ "KMF": "Comorian franc",
+ "KPW": "North Korean won",
+ "KRW": "South Korean won",
+ "KWD": "Kuwaiti dinar",
+ "KYD": "Cayman Islands dollar",
+ "KZT": "Kazakhstani tenge",
+ "LAK": "Lao kip",
+ "LBP": "Lebanese pound",
+ "LKR": "Sri Lankan rupee",
+ "LRD": "Liberian dollar",
+ "LSL": "Lesotho loti",
+ "LYD": "Libyan dinar",
+ "MAD": "Moroccan dirham",
+ "MDL": "Moldovan leu",
+ "MGA": "Malagasy ariary",
+ "MKD": "Macedonian denar",
+ "MMK": "Burmese kyat",
+ "MNT": "Mongolian tögrög",
+ "MOP": "Macanese pataca",
+ "MRO": "Mauritanian ouguiya",
+ "MUR": "Mauritian rupee",
+ "MVR": "Maldivian rufiyaa",
+ "MWK": "Malawian kwacha",
+ "MXN": "Mexican peso",
+ "MYR": "Malaysian ringgit",
+ "MZN": "Mozambican metical",
+ "NAD": "Namibian dollar",
+ "NGN": "Nigerian naira",
+ "NIO": "Nicaraguan córdoba",
+ "NOK": "Norwegian krone",
+ "NPR": "Nepalese rupee",
+ "NZD": "New Zealand dollar",
+ "OMR": "Omani rial",
+ "PAB": "Panamanian balboa",
+ "PEN": "Peruvian nuevo sol",
+ "PGK": "Papua New Guinean kina",
+ "PHP": "Philippine peso",
+ "PKR": "Pakistani rupee",
+ "PLN": "Polish złoty",
+ "PRB": "Transnistrian ruble",
+ "PYG": "Paraguayan guaraní",
+ "QAR": "Qatari riyal",
+ "RON": "Romanian leu",
+ "RSD": "Serbian dinar",
+ "RUB": "Russian ruble",
+ "RWF": "Rwandan franc",
+ "SAR": "Saudi riyal",
+ "SBD": "Solomon Islands dollar",
+ "SCR": "Seychellois rupee",
+ "SDG": "Sudanese pound",
+ "SEK": "Swedish krona",
+ "SGD": "Singapore dollar",
+ "SHP": "Saint Helena pound",
+ "SLL": "Sierra Leonean leone",
+ "SOS": "Somali shilling",
+ "SRD": "Surinamese dollar",
+ "SSP": "South Sudanese pound",
+ "STD": "São Tomé and Príncipe dobra",
+ "SYP": "Syrian pound",
+ "SZL": "Swazi lilangeni",
+ "THB": "Thai baht",
+ "TJS": "Tajikistani somoni",
+ "TMT": "Turkmenistan manat",
+ "TND": "Tunisian dinar",
+ "TOP": "Tongan paʻanga",
+ "TRY": "Turkish lira",
+ "TTD": "Trinidad and Tobago dollar",
+ "TWD": "New Taiwan dollar",
+ "TZS": "Tanzanian shilling",
+ "UAH": "Ukrainian hryvnia",
+ "UGX": "Ugandan shilling",
+ "USD": "United States (US) dollar",
+ "UYU": "Uruguayan peso",
+ "UZS": "Uzbekistani som",
+ "VEF": "Venezuelan bolívar",
+ "VND": "Vietnamese đồng",
+ "VUV": "Vanuatu vatu",
+ "WST": "Samoan tālā",
+ "XAF": "Central African CFA franc",
+ "XCD": "East Caribbean dollar",
+ "XOF": "West African CFA franc",
+ "XPF": "CFP franc",
+ "YER": "Yemeni rial",
+ "ZAR": "South African rand",
+ "ZMW": "Zambian kwacha"
+ },
+ "default_value": [],
+ "allow_null": 0,
+ "multiple": 0,
+ "ui": 1,
+ "ajax": 0,
+ "return_format": "value",
+ "placeholder": ""
+ },
+ {
+ "key": "field_5bfc4b00ff8ad",
+ "label": "VAT",
+ "name": "_wiaas_country_vat",
+ "type": "text",
+ "instructions": "",
+ "required": 0,
+ "conditional_logic": 0,
+ "wrapper": {
+ "width": "",
+ "class": "",
+ "id": ""
+ },
+ "default_value": "",
+ "placeholder": "",
+ "prepend": "",
+ "append": "",
+ "maxlength": ""
+ }
+ ],
+ "location": [
+ [
+ {
+ "param": "taxonomy",
+ "operator": "==",
+ "value": "product_country"
+ }
+ ]
+ ],
+ "menu_order": 0,
+ "position": "side",
+ "style": "default",
+ "label_placement": "top",
+ "instruction_placement": "label",
+ "hide_on_screen": "",
+ "active": 1,
+ "description": ""
+ }
+]
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-general.php b/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-general.php
index 0a5bd98..0179cf9 100644
--- a/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-general.php
+++ b/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-general.php
@@ -132,4 +132,102 @@ function wiaas_db_update_add_installation_date_delivery_action_form() {
$action_form_id = GFAPI::add_form($action_form_meta);
do_action('gform_forms_post_import', array( GFAPI::get_form($action_form_id) ));
+}
+
+// TODO: Remove after migration has been completed
+function wiaas_db_migration_fix_user_profile_addresses() {
+
+ $users = get_users();
+
+ foreach ($users as $user) {
+
+ $billing_addresses = Wiaas_Customer::get_customer_billing_addresses($user->ID);
+
+ if (! empty($billing_addresses)) {
+
+ foreach ($billing_addresses as $index => $billing_address) {
+
+ switch ($billing_address['id_country_selected']) {
+
+ case 1:
+ $billing_address['country_code'] = 'se';
+ break;
+ case 2:
+ $billing_address['country_code'] = 'dk';
+ break;
+ case 3:
+ $billing_address['country_code'] = 'fi';
+ break;
+ }
+ unset($billing_address['id_country_selected']);
+ $billing_addresses[$index] = $billing_address;
+ }
+
+ update_user_meta( $user->ID, 'billing_addresses', $billing_addresses);
+ }
+
+ $profile_addresses = Wiaas_Customer::get_customer_profile_addresses($user->ID);
+
+ if (! empty($profile_addresses)) {
+
+ foreach ($profile_addresses as $index => $profile_address) {
+
+ switch ($profile_address['id_country_selected']) {
+
+ case 1:
+ $profile_address['country_code'] = 'se';
+ break;
+ case 2:
+ $profile_address['country_code'] = 'dk';
+ break;
+ case 3:
+ $profile_address['country_code'] = 'fi';
+ break;
+ }
+ unset($profile_address['id_country_selected']);
+ $profile_addresses[$index] = $profile_address;
+ }
+
+ update_user_meta( $user->ID, 'profile_addresses', $profile_addresses);
+ }
+
+ }
+}
+
+// TODO: Remove after migration has been completed
+function wiaas_db_migration_fix_countries() {
+
+ $available_country_terms = get_terms(array(
+ 'taxonomy' => 'product_country',
+ 'hide_empty' => false,
+ ));
+
+ foreach($available_country_terms as $country_term) {
+
+ $code = ''; $currency = ''; $vat = '';
+
+ switch ($country_term->name) {
+
+ case 'Sweden':
+ $code = 'se';
+ $currency = 'SEK';
+ $vat = 9;
+ break;
+ case 'Denmark':
+ $code = 'dk';
+ $currency = 'DKK';
+ $vat = 9;
+ break;
+ case 'Finland':
+ $code = 'fi';
+ $currency = 'EUR';
+ $vat = 9;
+ break;
+ }
+
+ update_term_meta($country_term->term_id, '_wiaas_country_code', $code);
+ update_term_meta($country_term->term_id, '_wiaas_country_currency', $currency);
+ update_term_meta($country_term->term_id, '_wiaas_country_vat', $vat);
+ }
+
}
\ No newline at end of file
diff --git a/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-ui-fields.php b/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-ui-fields.php
index cdc5177..f958784 100644
--- a/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-ui-fields.php
+++ b/backend/app/plugins/wiaas/includes/db-updates/wiaas-db-update-ui-fields.php
@@ -45,6 +45,15 @@ function wiaas_db_update_add_product_properties_ui_fields() {
_wiaas_import_field_group($ui_json);
}
+function wiaas_db_update_add_country_settings_ui_fields() {
+
+ $ui_json = file_get_contents( dirname( __FILE__ ) . '/data/wiaas-ui-field-country-settings.json' );
+
+ $ui_json = json_decode( $ui_json, true );
+
+ _wiaas_import_field_group($ui_json);
+}
+
// private helper function
diff --git a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php
index ecf4024..690385e 100644
--- a/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php
+++ b/backend/app/plugins/wiaas/includes/delivery-process/class-wiaas-delivery-process-addon.php
@@ -11,9 +11,9 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
protected $_slug = 'wiaas_delivery_process';
- protected $_title = 'Delivery Process';
+ protected $_title = 'Delivery Settings';
- protected $_short_title = 'Delivery Process';
+ protected $_short_title = 'Delivery Settings';
public static function get_instance() {
@@ -125,7 +125,7 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
$tabs[] = array(
'name' => $this->_slug,
- 'label' => esc_html__( 'Delivery Process', 'wiaas' ),
+ 'label' => esc_html__( 'Delivery Settings', 'wiaas' ),
'query' => array( 'fid' => null )
);
@@ -218,14 +218,16 @@ class Wiaas_Delivery_Process_Addon extends Gravity_Flow_Extension {
return;
}
+ $countries = Wiaas_Countries::get_available_countries();
+
+ $countries_choices = array();
+ foreach ($countries as $country) {
+ $countries_choices[] = array( 'value' => $country['code'] , 'label' => $country['name'] );
+ }
$this->settings_select(array(
'name' => 'delivery_country',
- 'choices' => array(
- array( 'value' => 'se', 'label' => 'Sweden' ),
- array( 'value' => 'dk', 'label' => 'Denmark' ),
- array( 'value' => 'fi', 'label' => 'Finland' )
- ),
+ 'choices' => $countries_choices,
'after_select' => '
Choose country for which this process is defined.
'
));
}
diff --git a/backend/app/plugins/wiaas/includes/user/class-wiaas-customer.php b/backend/app/plugins/wiaas/includes/user/class-wiaas-customer.php
index d3bde33..b8cbf53 100644
--- a/backend/app/plugins/wiaas/includes/user/class-wiaas-customer.php
+++ b/backend/app/plugins/wiaas/includes/user/class-wiaas-customer.php
@@ -133,9 +133,9 @@ class Wiaas_Customer {
if ($new_address->id){
$updated = array(
'id' => $new_address->id,
- 'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
+ 'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
- 'id_country_selected' => $new_address->id_country_selected,
+ 'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
@@ -152,9 +152,9 @@ class Wiaas_Customer {
}else{
$new_billing_address = array(
'id' => time(),
- 'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
+ 'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
- 'id_country_selected' => $new_address->id_country_selected,
+ 'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
@@ -178,9 +178,9 @@ class Wiaas_Customer {
if ($new_address->id){
$updated = array(
'id' => $new_address->id,
- 'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
+ 'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
- 'id_country_selected' => $new_address->id_country_selected,
+ 'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
@@ -197,9 +197,9 @@ class Wiaas_Customer {
}else{
$new_delivery_address = array(
'id' => time(),
- 'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
+ 'country_name' => Wiaas_Countries::get_available_country_name_by_code($new_address->country_code),
'delivery_mail' => $new_address->delivery_mail,
- 'id_country_selected' => $new_address->id_country_selected,
+ 'country_code' => $new_address->country_code,
'city' => $new_address->city,
'detailed_address' => $new_address->detailed_address,
'zip_code' => $new_address->zip_code,
diff --git a/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-user-api.php b/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-user-api.php
index 6f8176a..57704a3 100644
--- a/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-user-api.php
+++ b/backend/app/plugins/wiaas/tests/unit-tests/api/test-wiaas-rest-user-api.php
@@ -102,7 +102,7 @@ class Wiass_REST_User_Api_Test extends Wiaas_Unit_Test_Case {
$country = $data[0];
$this->assertNotNull($country);
$this->assertTrue(is_array($country));
- $this->assertArrayHasKey('country_id', $country);
- $this->assertArrayHasKey('country_name', $country);
+ $this->assertArrayHasKey('code', $country);
+ $this->assertArrayHasKey('name', $country);
}
}
diff --git a/backend/composer.json b/backend/composer.json
index dcb40e3..156fdc4 100644
--- a/backend/composer.json
+++ b/backend/composer.json
@@ -106,6 +106,9 @@
"wp wc update",
"wp wc pb update",
"wp wiaas update-db"
+ ],
+ "timestamp": [
+ "php -r \"print date('YmdHis') . PHP_EOL;\" "
]
}
}
diff --git a/frontend/src/helpers/AddressHelper.js b/frontend/src/helpers/AddressHelper.js
index abd9fac..2f65f03 100644
--- a/frontend/src/helpers/AddressHelper.js
+++ b/frontend/src/helpers/AddressHelper.js
@@ -3,7 +3,7 @@ export const fromWiaasAddress = (address) => {
id: address.id,
countryName: address.country_name,
deliveryMail: address.delivery_mail,
- idCountrySelected: address.id_country_selected,
+ idCountrySelected: address.country_code,
city: address.city,
detailedAddress: address.detailed_address,
zipCode: address.zip_code,
@@ -18,7 +18,7 @@ export const toWiaasAddress = (address) => {
id: address.id,
country_name: address.countryName,
delivery_mail: address.deliveryMail,
- id_country_selected: address.idCountrySelected,
+ country_code: address.idCountrySelected,
city: address.city,
detailed_address: address.detailedAddress,
zip_code: address.zipCode,
diff --git a/frontend/src/helpers/CountryHelper.js b/frontend/src/helpers/CountryHelper.js
index e1c2ca6..7d708c2 100644
--- a/frontend/src/helpers/CountryHelper.js
+++ b/frontend/src/helpers/CountryHelper.js
@@ -1,6 +1,6 @@
export const fromWiaasCountryList = (countryList) => {
return {
- idCountry: countryList.country_id,
- countryName: countryList.country_name
+ idCountry: countryList.code,
+ countryName: countryList.name
}
}
\ No newline at end of file