37 Commits

Author SHA1 Message Date
Almira Krdzic
670eb53da1 Fix countries 2018-12-02 22:59:20 +01:00
Almira Krdzic
e87d1521dd Fix assigment order issues 2018-12-02 22:18:09 +01:00
Bilal Catic
3dbdb657c9 Merge branch 'forms-filtering' into 'development'
Show countries for delivery process forms. Refactor countries.

See merge request saburly/wiaas/new-wiaas!76
2018-11-27 12:08:22 +00:00
Almira Krdzic
2b688e8a5e Remove unused code 2018-11-27 11:22:01 +01:00
Almira Krdzic
95d162578f Add timestamp script to composer 2018-11-27 01:47:01 +01:00
Almira Krdzic
798ad20534 Show countries for delivery process forms. Refactor countries. 2018-11-27 00:57:35 +01:00
Almira
61ff7dbc60 Merge branch 'add-phone-number-field-in-backoffice-profile' into 'development'
Add phone number field in backoffice profile

See merge request saburly/wiaas/new-wiaas!75
2018-11-22 12:24:42 +00:00
Bilal Catic
09fc3f8018 Rename class 2018-11-22 13:22:05 +01:00
Bilal Catic
217dfb1889 add validation functions class 2018-11-22 12:08:41 +01:00
Bilal Catic
8d954469ee use woocommerce validation 2018-11-22 11:27:30 +01:00
Bilal Catic
68c760a426 validate phone number from frontend 2018-11-21 12:26:23 +01:00
Bilal Catic
35854d1367 add phone number field 2018-11-21 12:26:23 +01:00
Almira
3db4b71c3f Merge branch 'fix-location-details-field' into 'development'
Fix location details field

See merge request saburly/wiaas/new-wiaas!74
2018-11-19 15:32:55 +00:00
Bilal Catic
3df6397280 remove comment 2018-11-19 16:30:04 +01:00
Bilal Catic
e548e2a31c break project name and location details if too long 2018-11-19 16:29:22 +01:00
Almira
3d37a88247 Merge branch 'ticketing-integration' into 'development'
add helpdesk module

See merge request saburly/wiaas/new-wiaas!66
2018-11-19 12:44:16 +00:00
Bilal Catic
30e5d594ad highlight helpdesk when selected 2018-11-19 13:38:12 +01:00
Bilal Catic
dd93677def add helpdesk module 2018-11-19 13:38:12 +01:00
Nedim Uka
4de01d93d1 Merge branch 'fix-bundle-link-in-order-details' into 'development'
set commercial id to real id, not object

See merge request saburly/wiaas/new-wiaas!72
2018-11-19 12:37:09 +00:00
Bilal Catic
2fdae06a59 set commercial id to real id, not object 2018-11-19 13:30:07 +01:00
Almira
d0533b3d6e Merge branch 'support-email' into 'development'
Added support for sending customer emails

See merge request saburly/wiaas/new-wiaas!69
2018-11-19 12:24:10 +00:00
Nedim Uka
35e670fa52 removved debug log 2018-11-19 13:15:50 +01:00
Nedim Uka
f56377f606 Handled proper endpoint naming 2018-11-19 12:35:04 +01:00
Almira
95a9fd2110 Merge branch 'fix-additional-days-bug' into 'development'
add only working days

See merge request saburly/wiaas/new-wiaas!70
2018-11-19 11:11:34 +00:00
Nedim Uka
752df56d4a Fixed bug where order note text is saved as order ID 2018-11-19 11:31:46 +01:00
Bilal Catic
e1594f3a7f Merge branch 'fixes' into 'development'
Fixes

See merge request saburly/wiaas/new-wiaas!71
2018-11-19 10:15:26 +00:00
Almira Krdzic
4f97df5b45 Merge branch 'development' into fixes 2018-11-18 22:10:24 +01:00
Almira Krdzic
ef5cf00983 Fix hidden metadata 2018-11-18 22:10:01 +01:00
Bilal Catic
ca0fed674f add only working days 2018-11-16 20:30:47 +01:00
Bilal Catic
fb66d56d9c Merge branch 'installation-fix' into 'development'
Fix installation selection

See merge request saburly/wiaas/new-wiaas!68
2018-11-16 19:20:35 +00:00
Nedim Uka
a07c0e4584 Added support for sending customer emails 2018-11-16 17:16:28 +01:00
Almira Krdzic
3708c9fb30 Fix installation selection 2018-11-16 15:59:16 +01:00
Bilal Catic
c630452d0b Merge branch 'fix-tests' into 'development'
Fix and remove broken tests

See merge request saburly/wiaas/new-wiaas!67
2018-11-16 09:38:51 +00:00
Almira Krdzic
a62de78172 fix and remove broken tests 2018-11-15 23:40:58 +01:00
Almira
14550d2ea9 Merge branch 'allign-order-table' into 'development'
break long words

See merge request saburly/wiaas/new-wiaas!65
2018-11-15 15:23:51 +00:00
Bilal Catic
56c171df3e break long words 2018-11-15 14:50:02 +01:00
Bilal Catic
337f031705 Merge branch 'documents-fix' into 'development'
Handle documents upload

See merge request saburly/wiaas/new-wiaas!64
2018-11-15 13:44:55 +00:00
65 changed files with 2138 additions and 1576 deletions

View File

@@ -0,0 +1,71 @@
<?php
class Wiaas_Admin_Countries {
public static function init() {
// Add countries fields to countries list
add_filter( 'manage_edit-product_country_columns', array( __CLASS__, 'update_list_headers' ) );
add_filter( 'manage_product_country_custom_column', array( __CLASS__, 'update_list_column_content' ), 10, 3 );
// Validate country settings
add_filter('acf/load_field/name=_wiaas_country_code', array(__CLASS__, 'populate_country_codes'));
add_filter('acf/load_field/name=_wiaas_country_currency', array(__CLASS__, 'populate_country_currencies'));
}
public static function update_list_headers($columns) {
$columns['wiaas_code'] = __( 'Code', 'wiaas' );
$columns['wiaas_vat'] = __('VAT', 'wiaas');
$columns['wiaas_currency'] = __('Currency', 'wiaas');
return $columns;
}
public static function update_list_column_content($columns, $column, $id) {
if ($column === 'wiaas_code') {
$code = get_term_meta($id, '_wiaas_country_code', true);
$columns .= '<span>'. $code . '</span>';
}
if ($column === 'wiaas_vat') {
$vat = get_term_meta($id, '_wiaas_country_vat', true);
$columns .= '<span>'. $vat . '</span>';
}
if ($column === 'wiaas_currency') {
$currency = get_term_meta($id, '_wiaas_country_currency', true);
$columns .= '<span>'. $currency . '</span>';
}
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();

View File

@@ -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 );
}

View File

@@ -0,0 +1,31 @@
<?php
class Wiaas_Admin_Profile {
public static function init() {
add_filter( 'user_contactmethods', array(__CLASS__, 'modify_user_contact_methods') );
add_action( 'user_profile_update_errors', array(__CLASS__, 'crf_user_profile_update_errors'), 10, 3 );
}
public static function crf_user_profile_update_errors( $errors, $update, $user ) {
$phone = $_POST['phone'];
if (!Wiaas_Validation::is_phone($phone)){
$errors->add('phone_error', __( '<strong>ERROR</strong>: Enter valid phone number.', 'crf' ));
};
}
public static function modify_user_contact_methods($user_contact){
$user_contact['phone'] = __( 'Phone number' );
return $user_contact;
}
}
Wiaas_Admin_Profile::init();

View File

@@ -0,0 +1,150 @@
<?php
class Wiaas_Admin_Delivery_Process_List {
public static function init() {
add_filter('gform_form_list_columns', array( __CLASS__, 'filter_gform_form_list_columns' ));
add_filter('gform_form_list_forms', array( __CLASS__, 'filter_gform_form_list_forms' ), 10, 6);
add_filter('gform_form_actions', array( __CLASS__, 'filter_gform_form_actions' ), 10, 2);
add_action('gform_form_list_column_wiaas_country', array( __CLASS__, 'render_gform_form_list_wiaas_country_column' ));
add_action('gform_form_list_column_wiaas_actions', array( __CLASS__, 'render_gform_form_list_wiaas_actions_column' ));
}
/**
* Hide not needed columns for delivery process list
* Add country column
* Add actions column
*
* @param array $columns
*
* @return mixed
*/
public static function filter_gform_form_list_columns($columns) {
unset($columns['entry_count']);
unset($columns['conversion']);
unset($columns['view_count']);
$columns['wiaas_country'] = esc_html__( 'Country', 'wiaas' );
$columns['wiaas_actions'] = esc_html__( 'Actions', 'wiaas' );
return $columns;
}
/**
* Filter delivery process forms list with search query by title and country
* @param array $forms
* @param string $search_query
* @param bool $active
* @param string $sort_column
* @param string $sort_direction
* @param bool $trash
*
* @return array
*/
public static function filter_gform_form_list_forms($forms, $search_query, $active, $sort_column, $sort_direction, $trash) {
$forms = GFFormsModel::get_forms( $active, $sort_column, $sort_direction, $trash );
if ( ! rgblank( $search_query ) ) {
$filtered_forms = array();
$search_query = strtolower($search_query);
// filter forms
foreach ($forms as $form) {
$form_details = GFAPI::get_form( $form->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 '<strong>' . esc_html_e($country_name) . '</strong>';
}
/**
* 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'] : '';
?>
<a href="<?php echo '?page=gf_edit_forms&view=settings&id=' . $form->id . '&subview=gravityflow' ?>">Workflow</a>
<?php
if ($form_type !== 'action') {
?>
<span style="margin: 0 10px; opacity: 0.3;"> | </span>
<a href="<?php echo '?page=gf_edit_forms&view=settings&id=' . $form->id . '&subview=wiaas_delivery_process' ?>">Change Country</a>
<?php
}
}
}
Wiaas_Admin_Delivery_Process_List::init();

View File

@@ -58,11 +58,9 @@ class Wiaas_Admin_Delivery_Process_Order {
if ( empty($process_entry) ) {
$order = wc_get_order($order_id);
$country_code = Wiaas_Order::get_order_country_code($order_id);
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country(
Wiaas_Countries::get_country_code_by_currency($order->get_currency())
);
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_process_list_for_country($country_code);
?>
<div>

View File

@@ -148,6 +148,10 @@ class Wiaas_REST_Customer_API {
return wiaas_api_notice('ADD_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
}
if (!Wiaas_Validation::is_phone($phone)){
return wiaas_api_notice('INVALID_PHONE_NUMBER', 'error', Wiaas_Customer::get_customer_info($customer_id));
};
if (!Wiaas_Customer::update_customer_profile_info($customer_id, $first_name, $last_name, $phone)){
return wiaas_api_notice('PROFILE_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
}

View File

@@ -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);
}

View File

@@ -0,0 +1,68 @@
<?php
class Wiaas_Support_Api {
/**
* Endpoint namespace.
*
* @var string
*/
private static $namespace = 'wiaas';
private static $rest_base = 'support';
public static function register_routes() {
register_rest_route(self::$namespace, self::$rest_base . '/send-support-email', array(
'methods' => 'POST',
'callback' => array(__CLASS__, 'send_support_email'),
'permission_callback' => 'is_user_logged_in',
'args' => array(
'id' => array(
'description' => __('Order ID.', 'wiaas'),
'type' => 'integer',
'required' => true,
'sanitize_callback' => 'absint',
),
'support_text' => array(
'description' => __('Email text.', 'wiaas'),
'type' => 'string',
'required' => true
)
)
));
}
/**
* Send support email and save massage to order notes
*
* @param WP_REST_Request $request Request data.
*
* @return WP_REST_Response
*/
public static function send_support_email($request) {
$order_id = $request['id'];
$message = $request['support_text'];
$order = wc_get_order($order_id);
$customer_id = $order->get_customer_id();
$customer = get_user_by('id', $customer_id);
$mailer = WC()->mailer();
$recipient = WIAAS_SUPPORT_EMAIL;
$subject = __('Customer: '.$customer->get('first_name').', '.''.$customer->get('last_name').' needs support for order number: ' .$order->get_order_number());
$headers = array();
$success = $mailer->send( $recipient, $subject, $message, $headers );
if ($success) {
wc_create_order_note($order_id , $message, true );
return wiaas_api_notice('EMAIL_SENT', 'success');
}
return wiaas_api_notice('EMAIL_NOT_SENT', 'failed');
}
}

View File

@@ -16,8 +16,10 @@ class Wiaas_Access_Management {
add_action( 'save_post', array( __CLASS__, 'maybe_handle_product_access' ), 999, 2 );
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
add_action('woocommerce_payment_complete', array( __CLASS__, 'assign_order_to_suppliers'),20,1 );
add_action('woocommerce_checkout_order_processed', array( __CLASS__, 'assign_order_to_customer_organization' ));
add_action('woocommerce_checkout_order_processed', array( __CLASS__, 'assign_order_to_commercial_lead_organization' ));
add_action('woocommerce_checkout_order_processed', array( __CLASS__, 'assign_order_to_supplier_organizations'));
add_action('wiaas_order_item_installation_assigned', array(__CLASS__, 'assign_order_to_installation_organization'), 10, 3);
}
/**
@@ -43,6 +45,7 @@ class Wiaas_Access_Management {
empty(Wiaas_Package_Pricing::get_package_prices($product))) {
$access_group = Groups_Group::read_by_name('admin');
} else {
$access_group = Groups_Group::read_by_name('Registered');
@@ -64,13 +67,20 @@ class Wiaas_Access_Management {
*
* @param int $order_id
*/
public static function assign_order_to_organization($order_id) {
public static function assign_order_to_customer_organization($order_id) {
// assign order to customer organization
$customer_id = wiaas_get_current_user_organization_id();
Wiaas_User_Organization::assign_post_to_organization($order_id, $customer_id);
}
/**
* Assign order to commercial lead organization
*
* @param int $order_id
*/
public static function assign_order_to_commercial_lead_organization($order_id) {
$order = wc_get_order($order_id);
// assign order to commercial lead organization
$commercial_lead_id = absint($order->get_meta('_wiaas_commercial_lead_id', true));
if ($commercial_lead_id) {
Wiaas_User_Organization::assign_post_to_organization($order_id, $commercial_lead_id);
@@ -79,24 +89,46 @@ class Wiaas_Access_Management {
}
/**
* Assignees order to supplier organizations extracted from ordered items when order payment is complete.
* Assignees order to supplier organizations extracted from ordered items except installation
*
* Order will be assigned to corresponding installation company during delivery process
*
* @param int $order_id
*/
public static function assign_order_to_suppliers($order_id){
public static function assign_order_to_supplier_organizations($order_id) {
$order = wc_get_order($order_id);
$product_from_order = $order->get_items('line_item');
$order = wc_get_order($order_id);
foreach ($product_from_order as $product_item) {
$order_items = $order->get_items('line_item');
$supplier_organisation_id = Wiaas_Product_Supplier
::get_supplier_organisation_id_from_product($product_item->get_product_id());
foreach ($order_items as $key => $order_item) {
Wiaas_User_Organization::assign_post_to_organization($order_id, $supplier_organisation_id);
$supplier_organisation_id = $order_item->get_meta('_wiaas_supplier_organization_id');
if (! empty($supplier_organisation_id) && $order_item->get_meta('_wiaas_category') !== 'installation') {
Wiaas_User_Organization::assign_post_to_organization($order_id, $supplier_organisation_id);
}
}
}
/**
* Assign order to installation organization that handles installation of corresponding ordered bundle item
*
* @param WC_Order $order
* @param WC_Order_Item $bundle_item
* @param WC_Order_Item $installation_item
*/
public static function assign_order_to_installation_organization($order, $bundle_item, $installation_item) {
$supplier_organisation_id = $installation_item->get_meta('_wiaas_supplier_organization_id');
if (! empty($supplier_organisation_id) ) {
Wiaas_User_Organization::assign_post_to_organization($order->get_id(), $supplier_organisation_id);
}
}
}
Wiaas_Access_Management::init();

View File

@@ -28,6 +28,10 @@ class Wiaas_Admin {
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-supplier.php';
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 );
}

View File

@@ -43,7 +43,8 @@ class Wiaas_API {
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc- package-api-integration.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-wc-package-api-integration.php';
include_once dirname( __FILE__ ) . '/api/class-wiaas-support-api.php';
// API functions
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
@@ -58,6 +59,7 @@ class Wiaas_API {
'Wiass_REST_User_API',
'Wiaas_REST_Customer_API',
'Wiaas_Order_Projects_API',
'Wiaas_Support_Api',
);
foreach ( $controllers as $controller ) {

View File

@@ -473,8 +473,8 @@ class Wiaas_Cart {
'_wiaas_supplier_organization_id',
'_wiaas_product_price',
'_wiaas_earliest_installation_additional_days',
'wiaas_installation',
'wiaas_installation_date'
'_wiaas_installation',
'_wiaas_installation_date'
) );
}
@@ -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

View File

@@ -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
);
}
/**

View File

@@ -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() {

View File

@@ -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
@@ -436,7 +451,7 @@ class Wiaas_Order {
if (! $missing_estimated) {
$earliest_installation_date = max($max_estimated_date, $max_confirmed_date);
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' days', $earliest_installation_date);
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' weekdays', $earliest_installation_date);
}
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
@@ -475,7 +490,6 @@ class Wiaas_Order {
$commercial_lead_organization_info = $order->get_meta('_wiaas_commercial_lead_info', true);
if (! empty($commercial_lead_org_id) && empty($commercial_lead_organization_info)) {
$commercial_lead_organization_info = wiaas_get_organization_info($commercial_lead_org_id);
$data['commercial_lead'] = array(
@@ -487,8 +501,7 @@ class Wiaas_Order {
}
if (!empty($commercial_lead_organization_info)) {
$commercial_lead_organization_info['id'] = $commercial_lead_organization_info;
$commercial_lead_organization_info['id'] = $commercial_lead_org_id;
$data['commercial_lead'] = $commercial_lead_organization_info;
}

View File

@@ -48,7 +48,7 @@ class Wiaas_Pricing {
$bundled_items = $package->get_bundled_items();
foreach ($bundled_items as $bundled_item) {
$product = $bundled_item->product;
$product = wc_get_product($bundled_item->get_product_id());
$product_cat = Wiaas_Product_Category::get_category($product);
if (!isset($total_cost_per_category[$product_cat])) {

View File

@@ -0,0 +1,13 @@
<?php
defined( 'ABSPATH' ) || exit;
/**
* Class Wiaas_Validation
*/
class Wiaas_Validation {
public static function is_phone($phone){
return WC_Validation::is_phone($phone);
}
}

View File

@@ -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 - &#197;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&ccedil;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&atilde;o Tom&eacute; and Pr&iacute;ncipe",
"bl": "bl - Saint Barth&eacute;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&oacute;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&oacute;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&ouml;gr&ouml;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&oacute;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&#x142;oty",
"PRB": "Transnistrian ruble",
"PYG": "Paraguayan guaran&iacute;",
"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&atilde;o Tom&eacute; and Pr&iacute;ncipe dobra",
"SYP": "Syrian pound",
"SZL": "Swazi lilangeni",
"THB": "Thai baht",
"TJS": "Tajikistani somoni",
"TMT": "Turkmenistan manat",
"TND": "Tunisian dinar",
"TOP": "Tongan pa&#x2bb;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&iacute;var",
"VND": "Vietnamese &#x111;&#x1ed3;ng",
"VUV": "Vanuatu vatu",
"WST": "Samoan t&#x101;l&#x101;",
"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": ""
}
]

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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' => '<p class="description"> Choose country for which this process is defined.</p>'
));
}

View File

@@ -88,12 +88,15 @@ class Wiaas_Delivery_Process_Step_Assignee {
$mapped_assignees = array();
$order_id = self::get_order_id_for_step($step);
$order_id = self::_get_order_id_for_step($step);
$order = wc_get_order($order_id);
foreach ($assignees as $assignee) {
/**
* Handle step assignee for installation company field
*/
if (strpos($assignee->get_type(), 'wiaas_installation_') !== false) {
$item_id = $assignee->get_id();
@@ -120,11 +123,15 @@ class Wiaas_Delivery_Process_Step_Assignee {
continue;
}
/**
* Handle step assignee for order role
*/
if ($assignee->get_type() === 'wiaas_order_role') {
$order_role = $assignee->get_id();
// Assign step to order customer
if ($order_role === 'customer') {
$customer_user_id = $order->get_customer_id();
@@ -157,7 +164,7 @@ class Wiaas_Delivery_Process_Step_Assignee {
* @return bool|int Order id on success, false if step does not have associated order id
*
*/
public static function get_order_id_for_step(Gravity_Flow_Step $step) {
private static function _get_order_id_for_step(Gravity_Flow_Step $step) {
$entry = $step->get_entry();

View File

@@ -23,7 +23,7 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
$settings_api = $this->get_common_settings_api();
$forms = $this->get_action_forms_choices();
$forms = Wiaas_Delivery_Process_Action::get_action_forms();
$form_choices[] = array( 'label' => esc_html__( 'Select a Form', 'wiaas' ), 'value' => '' );
foreach ( $forms as $form ) {
@@ -86,8 +86,18 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return $label;
}
/**
* Update status
*
* @param bool $status
*/
public function update_step_status($status = false) {
/**
* If status is being updated after manual step completion ('Next Step' or 'Previous Step') change default
* behavior of settings status to cancelled if manual action is sending flow to next step.
* Instead of default cancelled status set complete status for this step.
*/
if ($status === 'cancelled' && $admin_action = rgpost( 'wiaas_delivery_process_navigation_action' )) {
list( $base_admin_action, $step_id ) = rgexplode( '|', $admin_action, 2 );
@@ -104,10 +114,10 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
}
/**
* Process Wiass Delivery Process Step
*
* Process Wiaas Delivery Process Step
*
*
* @return bool
* @return bool We will always return false because step will be completed only by manual user action
*/
function process() {
@@ -198,28 +208,22 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return $entry_meta;
}
/**
* Retrieves forms that are valid options for delivery step action
*
* PRIVATE
*
*/
/**
* Create action entry to trigger subworkflow
* @param $target_form
* @param $order_id
*
* @return array
*/
public function get_action_forms_choices() {
return Wiaas_Delivery_Process_Action::get_action_forms();
}
/**
* Retrieves target form entry id created when step was started
* @return int
*/
public function get_target_form_entry_id() {
$value = gform_get_meta($this->get_entry_id(), 'wiaas_delivery_step_' . $this->get_id() .'_entry_id');
return absint($value);
}
private function _create_single_action_entry($target_form, $order_id) {
$action_entries_ids = array();
@@ -248,6 +252,14 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
}
/**
* Create action form entries for every bundle in order to trigger subworkflows
*
* @param $target_form
* @param $order_id
*
* @return array
*/
private function _create_per_bundle_action_entries($target_form, $order_id) {
$action_entries_ids = array();

View File

@@ -228,6 +228,12 @@ class Wiaas_Order_Fields {
$bundle_item->update_meta_data('_wiaas_installation', $selected_installation->get_id());
$bundle_item->save_meta_data();
/**
* Apply actions related to order item installation
* (ex. make order visible to corresponding installation company)
*/
do_action('wiaas_order_item_installation_assigned', $order, $bundle_item, $selected_installation);
}
}
}
@@ -306,30 +312,16 @@ class Wiaas_Order_Fields {
}
}
public static function get_value_from_order_field($entry, $field) {
switch ($field->type) {
case 'wiaas_order_bundle':
$value = $entry[$field->id];
list ($order_id, $item_id) = explode('|', $value);
if ( ! empty($order_id) && ! empty($item_id)) {
return array(
'id' => $item_id,
'name' => $field->get_selected_bundle_display_name($value)
);
}
return null;
case '':
}
}
/**
* Create new entry for order delivery process action form
*
* @param int $order_id
* @param array $form
* @param int|null $bundle_item_id
*
* @return array|bool
*/
public static function map_order_to_entry($order_id, $form, $bundle_item_id = null) {
if (empty($form['fields']) ||
@@ -430,9 +422,9 @@ class Wiaas_Order_Fields {
}
// installation is already selected
if (!empty($bundle_item->get_meta('wiaas_installation', true))) {
if (!empty($bundle_item->get_meta('_wiaas_installation', true))) {
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $bundle_item->get_meta('wiaas_installation', true);
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $bundle_item->get_meta('_wiaas_installation', true);
continue;
}
@@ -461,6 +453,13 @@ class Wiaas_Order_Fields {
$installation_item = $installation_items[0];
$entry[(string) $field->id] = 'wiaas_installation_' . $order->get_id() . '|' . $installation_item->get_id();
/**
* Apply actions related to order item installation
* (ex. make order visible to corresponding installation company)
*/
do_action('wiaas_order_item_installation_assigned', $order, $bundle_item, $installation_item);
} else if (count($installation_items) > 1) {
// force admin to select installation

View File

@@ -20,7 +20,8 @@ class Wiaas_Document_Download {
}
/**
* Handle download for order documents by gravity flow steps
* Handle download of order documents by gravity flow steps for wordpress administration interface
*
*/
public static function admin_gf_order_document_download() {
@@ -44,6 +45,8 @@ class Wiaas_Document_Download {
}
/**
* Handle document download for wordpress administration interface
*
* Since only REST api uses JWT Authentication this endpoint will work only for users
* that are logged in directly to wordpress
*/
@@ -84,7 +87,8 @@ class Wiaas_Document_Download {
}
/**
* Download order other document (not binded to any bundle)
* Download order other document (not related to any order item)
*
* @param int $order_id
* @param string $document_key
*/
@@ -113,8 +117,6 @@ class Wiaas_Document_Download {
$file_path = wiaas_get_document_version_path($order_document['version']);
error_log($file_path);
if (!file_exists($file_path)) {
wp_die( __( 'Document not found.', 'wiaas' ), __( 'Download Error', 'wiaas' ), array( 'response' => 404 ) );
}

View File

@@ -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,

View File

@@ -25,6 +25,12 @@ tests_add_filter( 'pre_option_active_plugins', 'load_active_plugins_list');
# Start up the WP testing environment.
require $_tests_dir . '/includes/bootstrap.php';
// Require Wiaas test case factories
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/factories/class-wiaas-unit-test-organization-factory.php';
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/factories/class-wiaas-unit-test-product-factory.php';
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/factories/class-wiaas-unit-test-order-factory.php';
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/class-wiaas-unit-test-factory.php';
# Require Wiaas Unit Test case class
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/wiaas-unit-test-case.php';
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/wiaas-api-unit-test-case.php';

View File

@@ -0,0 +1,28 @@
<?php
class Wiaas_Unit_Test_Factory {
/**
* @var Wiaas_Unit_Test_Product_Factory
*/
public $product;
/**
* @var Wiaas_Unit_Test_Organization_Factory
*/
public $organization;
/**
* @var Wiaas_Unit_Test_Order_Factory
*/
public $order;
function __construct() {
$this->product = new Wiaas_Unit_Test_Product_Factory();
$this->organization = new Wiaas_Unit_Test_Organization_Factory();
$this->order = new Wiaas_Unit_Test_Order_Factory();
}
}

View File

@@ -0,0 +1,139 @@
<?php
class Wiaas_Unit_Test_Order_Factory {
/**
* @param array $args {
* @type int $customer_id
* }
*
* @return WC_Order|WP_Error
*/
public function create_new_order($args = array()) {
$customer_id = empty($args['customer_id']) ? get_current_user_id() : $args['customer_id'];
$order = wc_create_order(array(
'customer_id' => $customer_id
));
return $order;
}
/**
* @param WC_Order|int $order
* @param int $customer_organization_id
*/
public function add_customer_organization_info($order, $customer_organization_id) {
if (is_numeric($order)) {
$order = wc_get_order($order);
}
$order->add_meta_data('_wiaas_customer', $customer_organization_id);
$order->add_meta_data('_wiaas_customer_info', wiaas_get_organization_info($customer_organization_id));
$order->save_meta_data();
}
/**
* @param array $args
* @param WC_Order_Item_Product|null $bundle_item
* @param WC_Order|null $order
*
* @return WC_Order_Item_Product
*/
public function create_new_simple_product_order_item($args = array(), $bundle_item = null, $order = null) {
$defaults = array(
'quantity' => 1,
'total' => 0
);
$args = wp_parse_args($args, $defaults);
$item = new WC_Order_Item_Product();
$item->set_props(
array(
'quantity' => $args['quantity'],
'total' => $args['total'],
)
);
if (! empty($args['category']) ) {
$item->add_meta_data('_wiaas_category', $args['category']);
}
if (! empty($args['supplier_organization_id']) ) {
$item->add_meta_data('_wiaas_supplier_organization_id', $args['supplier_organization_id']);
}
$item->set_backorder_meta();
if (! empty($order) ) {
$order->add_item($item);
$order->save();
}
return $item;
}
/**
* @param array $args
* @param WC_Order|null $order
*
* @return WC_Order_Item_Product
*/
public function create_new_bundle_order_item($args = array(), $order = null) {
$defaults = array(
'quantity' => 1,
'total' => 0
);
$args = wp_parse_args($args, $defaults);
$item = new WC_Order_Item_Product();
$item->set_props(
array(
'quantity' => $args['quantity'],
'total' => $args['total'],
)
);
$item->set_backorder_meta();
if (! empty($order) ) {
$order->add_item($item);
$order->save();
}
return $item;
}
/**
* @param WC_Order $order
* @param array $items
*/
public function add_order_items($order, $items) {
foreach ( $items as $item ) {
$order->add_item($item);
}
$order->save();
}
}

View File

@@ -0,0 +1,70 @@
<?php
class Wiaas_Unit_Test_Organization_Factory {
/**
* @param array $args {
* @type string $name
* @type int $parent_id
* }
*
* @return int Organization ID
*/
public function create_new_organization($args = array()) {
$defaults = array(
'name' => 'organization'
);
$args = wp_parse_args($args, $defaults);
$term_args = array();
if (! empty($args['parent_id'])) {
$term_args['parent'] = $args['parent_id'];
}
$result = wp_insert_term(
$args['name'],
Wiaas_User_Organization::TAXONOMY_NAME,
$term_args
);
if (! is_wp_error($result) ) {
return $result['term_id'];
}
return 0;
}
public function assign_user_to_organization($user_id, $organization_id) {
wp_set_object_terms(
$user_id,
$organization_id,
Wiaas_User_Organization::TAXONOMY_NAME);
update_user_meta($user_id, '_wiaas_organization_id', $organization_id);
}
public function delete_organization($organization_id) {
wp_delete_term(
$organization_id,
Wiaas_User_Organization::TAXONOMY_NAME);
}
public function delete_organizations() {
$terms = get_terms(array(
'taxonomy' => Wiaas_User_Organization::TAXONOMY_NAME,
'hide_empty' => false
));
foreach ($terms as $term) {
wp_delete_term($term->term_id, Wiaas_User_Organization::TAXONOMY_NAME);
}
}
}

View File

@@ -0,0 +1,218 @@
<?php
class Wiaas_Unit_Test_Product_Factory {
function __construct() {
}
/**
* Create new simple product
*
* @param array $args {
* @type int $price Simple product price
* @type bool $is_recurring Flag indicating is simple product price is recurring
* @type int $pay_period Pay period for simple product price if price is recurring
* @type string|int $category Simple product category
* @type string|int $country Simple product category term slug or id
* @type string|int $supplier Simple product supplier term slug or id
*
* }
*
* @return WC_Product_Simple
*/
public function create_simple_product($args = array()) {
$defaults = array(
'price' => 10,
'is_recurring' => false,
'pay_period' => 0
);
$args = wp_parse_args($args, $defaults);
$post_id = wp_insert_post(array(
'post_type' => 'product',
'post_status' => 'publish',
'post_name' => 'product',
'post_title' => 'Product',
'post_content' => 'Product',
'post_excerpt' => 'Product'
), true);
$product = new WC_Product_Simple($post_id);
$this->set_product_price($product, $args['price'], $args['is_recurring'], $args['pay_period']);
$product->save();
if (! empty($args['category']) ) {
$this->assign_product_to_category($product->get_id(), $args['category']);
}
if (! empty($args['country']) ) {
$this->assign_product_to_country($product->get_id(), $args['country']);
}
if (! empty($args['supplier']) ) {
$this->assign_product_to_supplier($product->get_id(), $args['supplier']);
}
return $product;
}
/**
* @param WC_Product_Simple|int $product Product or Product ID
* @param int $price
* @param bool $is_recurring
* @param int $pay_period
*/
public function set_product_price($product, $price = 10, $is_recurring = false, $pay_period = 0) {
if (is_numeric($product)) {
$product = wc_get_product($product);
}
Wiaas_Product_Pricing::set_product_price($product, $price, $is_recurring, $pay_period);
$product->save();
delete_transient('wc_bundled_product_data');
}
/**
* @param WC_Product_Simple|int $product Product or Product ID
* @param string|int $category
*/
public function assign_product_to_category($product, $category) {
if (is_numeric($product)) {
$product_id = $product;
} else {
$product_id = $product->get_id();
}
wp_add_object_terms($product_id, $category, 'product_cat');
}
/**
* @param WC_Product_Simple|int $product Product or Product ID
* @param string|int $country
*/
public function assign_product_to_country($product, $country) {
if (is_numeric($product)) {
$product_id = $product;
} else {
$product_id = $product->get_id();
}
wp_add_object_terms($product_id, $country, 'product_country');
}
/**
* @param WC_Product_Simple|int $product Product or Product ID
* @param string|int $supplier
*/
public function assign_product_to_supplier($product, $supplier) {
if (is_numeric($product)) {
$product_id = $product;
} else {
$product_id = $product->get_id();
}
wp_add_object_terms($product_id, $supplier, 'supplier');
}
/**
* @param array $args {
* @type array $products Simple products
* @type array $product_quantities Quantities for corresponding products from $products ( ex: [10, 5, 7] )
* }
*
* @return WC_Product_Bundle
*/
public function create_product_bundle($args = array()) {
$post_id = wp_insert_post(array(
'post_type' => 'product',
'post_status' => 'publish',
'post_name' => 'Bundle',
'post_title' => 'Product Bundle',
'post_content' => 'Product Bundle',
'post_excerpt' => 'Product Bundle'
), true);
$bundle = new WC_Product_Bundle($post_id);
if (! empty($args['products']) ) {
if ( empty($args['product_quantities']) ) {
$args['product_quantities'] = array_fill(0, count($args['products']), 1);
}
if ( count($args['product_quantities']) < count($args['products'])) {
$args['product_quantities'] = array_pad($args['product_quantities'], count($args['products']), 1);
}
$args['product_quantities'] = array_map('absint', $args['product_quantities']);
$bundled_data = array();
foreach ($args['products'] as $index => $product) {
$bundled_data[] = array(
'product_id' => $product->get_id(),
'quantity_min' => $args['product_quantities'][$index],
'quantity_max' => $args['product_quantities'][$index],
'priced_individually' => true
);
}
$bundle->set_bundled_data_items($bundled_data);
$bundle->sync(true);
}
$bundle->save();
if (! empty($args['country']) ) {
$this->assign_product_to_country($bundle->get_id(), $args['country']);
}
return $bundle;
}
/**
* @param WC_Product_Bundle $bundle
* @param array $pricing_rules
* @param int $commission
* @param int $cost_margin
*/
public function set_product_bundle_prices($bundle, $pricing_rules = null, $commission = 50, $cost_margin = 0) {
if ( empty($pricing_rules) ) {
$pricing_rules = array(
'purchase' => array(
'minimal_fixed_price' => 500,
'principal_amount' => 0,
'minimal_services_price' => 0
)
);
}
Wiaas_Package_Pricing::set_package_prices($bundle, $pricing_rules, $commission, $cost_margin);
}
}

View File

@@ -1,521 +0,0 @@
<?php
/**
* Wiaas_Delivery_Process_Step_Test
*
* @package Wiaas
*/
class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case {
var $order_id, $api;
/**
* Test REST Server
*
* @var WP_REST_Server
*/
protected $server;
protected $namespaced_route = '/wiaas';
function setUp() {
parent::setUp();
$order = wc_create_order();
$this->order_id = $order->get_id();
wp_set_current_user(1);
/** @var WP_REST_Server $wp_rest_server */
global $wp_rest_server;
$this->server = $wp_rest_server = new \WP_REST_Server;
do_action( 'rest_api_init' );
$original_valid_customer_acceptance = __DIR__ . '/../dummy-files/valid-customer-acceptance.odt';
$this->test_file_valid_customer_acceptance = '/tmp/valid-customer-acceptance.odt';
copy( $original_valid_customer_acceptance, $this->test_file_valid_customer_acceptance );
$original_invalid_customer_acceptance = __DIR__ . '/../dummy-files/invalid-customer-acceptance.txt';
$this->test_file_invalid_customer_acceptance = '/tmp/invalid-customer-acceptance.txt';
copy( $original_invalid_customer_acceptance, $this->test_file_invalid_customer_acceptance );
}
function test_register_route() {
$routes = $this->server->get_routes();
$this->assertArrayHasKey( $this->namespaced_route, $routes );
}
function test_endpoints() {
$the_route = $this->namespaced_route;
$routes = $this->server->get_routes();
foreach( $routes as $route => $route_config ) {
if( 0 === strpos( $the_route, $route ) ) {
$this->assertTrue( is_array( $route_config ) );
foreach( $route_config as $i => $endpoint ) {
$this->assertArrayHasKey( 'callback', $endpoint );
$this->assertArrayHasKey( 0, $endpoint[ 'callback' ], get_class( $this ) );
$this->assertArrayHasKey( 1, $endpoint[ 'callback' ], get_class( $this ) );
$this->assertTrue( is_callable( array( $endpoint[ 'callback' ][0], $endpoint[ 'callback' ][1] ) ) );
}
}
}
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_next_actions_for_user
*/
function test_get_next_actions_for_user() {
wp_set_current_user(1);
$response = Wiass_REST_Delivery_Process_API::get_next_actions_for_user();
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response', $response);
$next_steps = $response->get_data();
$this->assertNotNull($next_steps);
$this->assertTrue(is_array($next_steps));
$pending_step = $next_steps[0];
$this->assertTrue(is_array($pending_step));
$this->assertArrayHasKey('order_id', $pending_step);
$this->assertArrayHasKey('order_number', $pending_step);
$this->assertArrayHasKey('status', $pending_step);
$this->assertArrayHasKey('step_action', $pending_step);
$this->assertEquals($pending_step['order_id'], $this->order_id);
$this->assertEquals($pending_step['order_number'], $this->order_id);
$this->assertEquals($pending_step['status'], 'pending');
$this->assertNotEmpty($pending_step['step_action']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
*/
function test_get_customer_acceptance_as_guest() {
wp_set_current_user(0);
$request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/99191991919191');
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 401);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
*/
function test_get_nonexisting_customer_acceptance() {
wp_set_current_user(1);
$request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/911919191919' ); //non existing entry ID
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 404);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
}
/**
* @covers Wiass_REST_Delivery_Process_API::get_customer_acceptance
*/
function test_get_valid_customer_acceptance() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'GET', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertTrue(is_array($response_data));
$this->assertArrayHasKey('documents', $response_data);
$this->assertArrayHasKey('expiration', $response_data);
$this->assertArrayHasKey('status', $response_data);
$this->assertArrayHasKey('decline_reason', $response_data);
$this->assertTrue(is_array($response_data['documents']));
$uploaded_file = $response_data['documents'][0];
$this->assertTrue(is_array($uploaded_file));
$this->assertArrayHasKey('name', $uploaded_file);
$this->assertArrayHasKey('extension', $uploaded_file);
$this->assertArrayHasKey('url', $uploaded_file);
$this->assertEquals($uploaded_file['name'], 'file1');
$this->assertEquals($uploaded_file['extension'], 'docx');
$this->assertEquals($uploaded_file['url'], 'http://localhost/wp/index.php?gf-download=2018%2F08%2Ffile1.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534');
$this->assertEquals($response_data['status'], 1); //1 means accept
$this->assertEquals($response_data['expiration'], "2020-01-01");
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_as_guest() {
wp_set_current_user(0);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/9191919191' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 401);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_nonexisting_customer_acceptance() {
wp_set_current_user(1);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919191919191' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 404);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_invalid_status() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'invalid status',
'declineReason' => ''
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('ACCEPTANCE_STATUS_MISSING', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_accepted_status() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'accept',
'declineReason' => ''
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('success', $message['code']);
$this->assertEquals('INSTALLATION_ACCEPTED', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_declined_status_and_empty_reason() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'decline',
'declineReason' => ''
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('DECLINE_REASON_EMPTY', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::submit_customer_acceptance
*/
function test_submit_customer_acceptance_with_decline_status() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id );
$request->set_body_params(array(
'actionType' => 'decline',
'declineReason' => 'This is very reasonable reason'
));
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('success', $message['code']);
$this->assertEquals('INSTALLATION_DECLINED', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_customer_acceptance_file_as_guest() {
wp_set_current_user(0);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 401);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_customer_acceptance_file_to_non_existing_entry() {
wp_set_current_user(1);
$original_valid_customer_acceptance = __DIR__ . '/../dummy-files/valid-customer-acceptance.odt';
$this->test_file_valid_customer_acceptance = '/tmp/valid-customer-acceptance.odt';
copy( $original_valid_customer_acceptance, $this->test_file_valid_customer_acceptance );
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
$request->set_file_params( array(
'file' => array(
'file' => file_get_contents( $this->test_file_valid_customer_acceptance ),
'name' => 'valid-customer-acceptance.odt',
'size' => filesize( $this->test_file_valid_customer_acceptance ),
'tmp_name' => $this->test_file_valid_customer_acceptance,
),
) );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertTrue($response->is_error());
$this->assertEquals($response->get_status(), 404);
$error_data = $response->as_error();
$this->assertEquals($error_data->get_error_message(), 'Customer acceptance entry not found');
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_customer_acceptance_file_without_file() {
wp_set_current_user(1);
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/919199191/upload-file' );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('NO_FILES_UPLOADED', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_invalid_customer_acceptance_file() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id . '/upload-file' );
$request->set_file_params( array(
'file' => array(
'file' => file_get_contents( $this->test_file_invalid_customer_acceptance ),
'name' => 'invalid-customer-acceptance.txt',
'size' => filesize( $this->test_file_invalid_customer_acceptance ),
'tmp_name' => $this->test_file_invalid_customer_acceptance,
),
) );
$request->set_header( 'Content-MD5', md5_file( $this->test_file_invalid_customer_acceptance ) );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('error', $message['code']);
$this->assertEquals('INVALID_FILE_ACCEPTANCE', $message['message']);
}
/**
* @covers Wiass_REST_Delivery_Process_API::upload_file
*/
function test_upload_valid_customer_acceptance_file() {
wp_set_current_user(1);
$customer_acceptance_entry_id = self::create_pending_customer_acceptance_entry();
$request = new WP_REST_Request( 'POST', '/wiaas/customer-acceptance/' . $customer_acceptance_entry_id . '/upload-file' );
$request->set_file_params( array(
'file' => array(
'file' => file_get_contents( $this->test_file_valid_customer_acceptance ),
'name' => 'valid-customer-acceptance.odt',
'size' => filesize( $this->test_file_valid_customer_acceptance ),
'tmp_name' => $this->test_file_valid_customer_acceptance,
),
) );
$request->set_header( 'Content-MD5', md5_file( $this->test_file_valid_customer_acceptance ) );
$response = $this->server->dispatch( $request );
$this->assertNotNull($response);
$this->assertInstanceOf('WP_REST_Response',$response);
$this->assertFalse($response->is_error());
$this->assertEquals($response->get_status(), 200);
$response_data = $response->get_data();
$this->assertArrayHasKey('messages', $response_data);
$this->assertArrayHasKey('data', $response_data);
$message = $response_data['messages'][0];
$this->assertArrayHasKey('code', $message);
$this->assertArrayHasKey('message', $message);
$this->assertEquals('success', $message['code']);
$this->assertEquals('FILE_UPLOADED', $message['message']);
}
public function tearDown() {
parent::tearDown();
if ( file_exists( $this->test_file_valid_customer_acceptance ) ) {
unlink( $this->test_file_valid_customer_acceptance );
}
if ( file_exists( $this->test_file_invalid_customer_acceptance ) ) {
unlink( $this->test_file_invalid_customer_acceptance );
}
$this->remove_added_uploads();
}
//===================================================================================
/**
* Helper function : creates customer acceptance entry
*/
private function create_pending_customer_acceptance_entry(){
$customer_acceptance_form_id = 1;
$customer_id_field_id = 2;
$actual_date_field_id = 6;
$acceptance_status_field_id = 8;
$expiration_date_field_id = 9;
$decline_reason_field_id = 10;
$files_uploaded_field_id = 12;
$input_values['input_' . $acceptance_status_field_id] = 'accept';
$input_values['input_' . $expiration_date_field_id] = "2020-01-01";
//$input_values['input_' . $files_uploaded_field_id] = json_encode(['http://path/to/file1.docx']);
GFAPI::submit_form($customer_acceptance_form_id, $input_values);
//this part is needed since form submit does not store files for some reason, probably files should be sent some other way
$entry = GFAPI::get_entries($customer_acceptance_form_id)[0];
$entry[$files_uploaded_field_id] = json_encode(['http://localhost/wp/index.php?gf-download=2018%2F08%2Ffile1.docx&form-id=1&field-id=12&hash=1be6c30f0eeff93563b352d15fe459d5ded12ee06c2c8f36fed66b42dedf2534']);
$entry['workflow_step'] = 1;
$entry['workflow_step_status_1'] = 'pending';
$entry['workflow_step_status_2'] = false;
$entry['workflow_timestamp'] = false;
$update = GFAPI::update_entry($entry);
return $entry['id'];
}
}

View File

@@ -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);
}
}

View File

@@ -16,10 +16,10 @@ class Wiaas_Package_Addon_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Package_Addon::get_package_addons()
*/
function test_adding_package_addons() {
$package = $this->create_new_package();
$package = $this->factory->product->create_product_bundle();
$addon1 = $this->create_new_package();
$addon2 = $this->create_new_package();
$addon1 = $this->factory->product->create_product_bundle();
$addon2 = $this->factory->product->create_product_bundle();
$addons_ids = array(
$addon1->get_id(),
$addon2->get_id()

View File

@@ -16,12 +16,12 @@ class Wiaas_Package_Option_Groups_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Package_Option_Groups::get_package_option_groups()
*/
function test_adding_package_option_group() {
$package = $this->create_new_package();
$package = $this->factory->product->create_product_bundle();
$option_package1 = $this->create_new_package();
$option_package1 = $this->factory->product->create_product_bundle();
Wiaas_Package_Type::set_package_type($option_package1->get_id(), 'option');
$option_package2 = $this->create_new_package();
$option_package2 = $this->factory->product->create_product_bundle();
Wiaas_Package_Type::set_package_type($option_package2->get_id(), 'option');
$option_group1 = array(
@@ -79,9 +79,9 @@ class Wiaas_Package_Option_Groups_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Package_Option_Groups::get_group_name_for_package_option()
*/
function test_get_group_name_for_package_option() {
$package = $this->create_new_package();
$package = $this->factory->product->create_product_bundle();
$option_package = $this->create_new_package();
$option_package = $this->factory->product->create_product_bundle();
Wiaas_Package_Type::set_package_type($option_package->get_id(), 'option');
$option_group = array(

View File

@@ -16,6 +16,7 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
$this->assertNotEmpty($package_statuses);
$this->assertContains(Wiaas_Package_Status::AVAILABLE, $package_statuses);
$this->assertContains(Wiaas_Package_Status::INVALID_MARGIN, $package_statuses);
}
/**
@@ -23,7 +24,7 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Package_Type::get_package_status()
*/
function test_adding_package_status() {
$package = $this->create_new_package();
$package = $this->factory->product->create_product_bundle();
Wiaas_Package_Status::set_package_status($package->get_id(), Wiaas_Package_Status::AVAILABLE);
@@ -37,15 +38,15 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
* Test package status update on simple product price update
*/
function test_package_status_update_on_simple_product_price_update() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(20);
$this->add_product_category($product2, 'software');
$product1 = $this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' ));
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$product1,
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'software' ))
)
));
$pricing_rules = array(
'purchase' => array(
@@ -68,10 +69,13 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
$cost_margin = 100;
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::AVAILABLE);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::AVAILABLE);
$product1->set_price(1000);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::MARGIN_EXCEEDED);
$this->factory->product->set_product_price($product1, 1000);
Wiaas_Package_Pricing::on_product_update($product1->get_id());
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::INVALID_MARGIN);
}
@@ -79,15 +83,12 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
* Test package status update on cost margin update
*/
function test_package_status_update_on_margin_cost_update() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(20);
$this->add_product_category($product2, 'software');
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'software' ))
)
));
$pricing_rules = array(
'purchase' => array(
@@ -108,13 +109,14 @@ class Wiaas__Package_Status_Test extends Wiaas_Unit_Test_Case {
);
$commision = 50;
$cost_margin = 0;
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::AVAILABLE);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::AVAILABLE);
$cost_margin = 1;
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package)->get_id(), Wiaas_Package_Status::MARGIN_EXCEEDED);
$this->assertEquals(Wiaas_Package_Status::get_package_status($package->get_id()), Wiaas_Package_Status::INVALID_MARGIN);
}
}

View File

@@ -23,7 +23,7 @@ class Wiaas__Package_Type_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Package_Type::get_package_type()
*/
function test_adding_package_type() {
$package = $this->create_new_package();
$package = $this->factory->product->create_product_bundle();
Wiaas_Package_Type::set_package_type($package->get_id(), 'standard');

View File

@@ -6,17 +6,17 @@ class Wiaas_Package_CL_Pricing_Test extends Wiaas_Unit_Test_Case {
function setUp() {
parent::setUp();
$this->shop_owner_id = wp_insert_term(
'Shop owner organization',
Wiaas_User_Organization::TAXONOMY_NAME)['term_id'];
$this->shop_owner_id = $this->factory->organization->create_new_organization(
array( 'name' => 'Shop owner organization' )
);
$this->customer_id = wp_insert_term(
'Customer Organization',
Wiaas_User_Organization::TAXONOMY_NAME)['term_id'];
$this->customer_id = $this->factory->organization->create_new_organization(
array( 'name' => 'Customer Organization' )
);
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $this->create_new_product()));
$package = $this->factory->product->create_product_bundle(array(
'products' => array( $this->factory->product->create_simple_product() )
));
$this->package_id = $package->get_id();

View File

@@ -8,7 +8,7 @@ class Wiaas_Package_Pricing_Test extends Wiaas_Unit_Test_Case {
*/
function test_set_and_get_package_prices() {
$package = $this->create_new_package();
$package = $this->factory->product->create_product_bundle();
$pricing_rules = array(
'purchase' => array(

View File

@@ -0,0 +1,196 @@
<?php
class Wiaas_Access_Management_Test extends Wiaas_Unit_Test_Case {
/**
* @var WC_Order
*/
var $order;
/**
* @var int
*/
var $organization_id;
/**
* @var int
*/
var $customer_user_id;
public function setUp() {
parent::setUp();
wp_set_current_user(1);
$this->customer_user_id = wp_insert_user(array(
'user_login' => 'test_customer',
'user_pass' => 'test',
'user_email' => 'test_customer@mail.com',
'role' => 'customer',
));
$this->organization_id = $this->factory->organization->create_new_organization();
$this->factory->organization->assign_user_to_organization($this->customer_user_id, $this->organization_id);
$this->order = $this->factory->order->create_new_order();
}
function tearDown() {
parent::tearDown();
wp_set_current_user(1);
wp_delete_user($this->customer_user_id);
$this->factory->organization->delete_organizations();
}
/**
* @covers Wiaas_Access_Management::maybe_handle_product_access()
*/
function test_simple_product_has_admin_access() {
$simple_product = $this->factory->product->create_simple_product();
Wiaas_Access_Management::maybe_handle_product_access($simple_product->get_id(), get_post($simple_product->get_id()));
$access_group_ids = Groups_Post_Access::get_read_group_ids( $simple_product->get_id() );
$this->assertEquals(1, count($access_group_ids));
$admin_access_group = Groups_Group::read_by_name('admin');
$this->assertEquals($admin_access_group->group_id, $access_group_ids[0]);
}
/**
* @covers Wiaas_Access_Management::maybe_handle_product_access()
*/
function test_bundle_with_no_price_has_admin_access() {
$bundle_product = $this->factory->product->create_product_bundle();
Wiaas_Access_Management::maybe_handle_product_access($bundle_product->get_id(), get_post($bundle_product->get_id()));
$access_group_ids = Groups_Post_Access::get_read_group_ids( $bundle_product->get_id() );
$this->assertEquals(1, count($access_group_ids));
$admin_access_group = Groups_Group::read_by_name('admin');
$this->assertEquals($admin_access_group->group_id, $access_group_ids[0]);
}
/**
* @covers Wiaas_Access_Management::maybe_handle_product_access()
*/
function test_bundle_with_prices_has_registered_access() {
$bundle_product = $this->factory->product->create_product_bundle();
$this->factory->product->set_product_bundle_prices($bundle_product);
Wiaas_Access_Management::maybe_handle_product_access($bundle_product->get_id(), get_post($bundle_product->get_id()));
$access_group_ids = Groups_Post_Access::get_read_group_ids( $bundle_product->get_id() );
$this->assertEquals(1, count($access_group_ids));
$registered_access_group = Groups_Group::read_by_name('Registered');
$this->assertEquals($registered_access_group->group_id, $access_group_ids[0]);
}
/**
* @covers Wiaas_Access_Management::assign_order_to_customer_organization()
*/
function test_order_assigned_to_customer_organization() {
wp_set_current_user($this->customer_user_id);
Wiaas_Access_Management::assign_order_to_customer_organization($this->order->get_id());
$organization_access_group = Groups_Group::read_by_name('organization');
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
$this->assertEquals(1, count($access_group_ids));
$this->assertNotNull($access_group_ids[0]);
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
}
/**
* @covers Wiaas_Access_Management::assign_order_to_commercial_lead_organization()
*/
function test_order_assigned_to_commercial_lead_organization() {
$this->order->update_meta_data('_wiaas_commercial_lead_id', $this->organization_id);
$this->order->save_meta_data();
Wiaas_Access_Management::assign_order_to_commercial_lead_organization($this->order->get_id());
$organization_access_group = Groups_Group::read_by_name('organization');
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
$this->assertEquals(1, count($access_group_ids));
$this->assertNotNull($access_group_ids[0]);
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
}
/**
* @covers Wiaas_Access_Management::assign_order_to_supplier_organizations()
*/
function test_order_assigned_to_supplier_organizations() {
$items = array();
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
'category' => 'hardware',
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'hardware supplier'))
));
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
'category' => 'software',
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'software supplier'))
));
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
'category' => 'service',
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'service supplier'))
));
$items[] = $this->factory->order->create_new_simple_product_order_item(array(
'category' => 'installation',
'supplier_organization_id' => $this->factory->organization->create_new_organization( array( 'name' => 'installation supplier'))
));
$this->factory->order->add_order_items($this->order, $items);
Wiaas_Access_Management::assign_order_to_supplier_organizations($this->order->get_id());
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
$this->assertEquals(3, count($access_group_ids));
$organization_access_group = Groups_Group::read_by_name('hardware supplier');
$this->assertContains($organization_access_group->group_id, $access_group_ids);
$organization_access_group = Groups_Group::read_by_name('software supplier');
$this->assertContains($organization_access_group->group_id, $access_group_ids);
$organization_access_group = Groups_Group::read_by_name('service supplier');
$this->assertContains($organization_access_group->group_id, $access_group_ids);
}
/**
* @covers Wiaas_Access_Management::assign_order_to_installation_organization()
*/
function test_order_assigned_to_installation_organization() {
$bundle_item = $this->factory->order->create_new_bundle_order_item();
$installation_item = $this->factory->order->create_new_simple_product_order_item(array(
'category' => 'installation',
'supplier_organization_id' => $this->organization_id
));
$this->order->add_item($bundle_item);
$this->order->add_item($installation_item);
Wiaas_Access_Management::assign_order_to_installation_organization($this->order, $bundle_item, $installation_item);
$organization_access_group = Groups_Group::read_by_name('organization');
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order->get_id() );
$this->assertEquals(1, count($access_group_ids));
$this->assertNotNull($access_group_ids[0]);
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
}
}

View File

@@ -1,388 +0,0 @@
<?php
class Wiaas_Authentication_Test extends Wiaas_Unit_Test_Case {
var $user_id, $organization_id, $request_uri;
public function setUp() {
parent::setUp();
// set admin as current user
wp_set_current_user(1);
// create testing user
$this->user_id = wp_create_user('test', 'test', 'test@mail.com');
// create organization
$this->organization_id = wp_insert_term(
'test_organization',
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
update_user_meta($this->user_id, '_wiaas_organization_id', $this->organization_id);
# assign user to organization
wp_set_terms_for_user(
$this->user_id,
Wiaas_User_Organization::TAXONOMY_NAME,
[$this->organization_id]);
wp_set_current_user($this->user_id);
$this->request_uri = $_SERVER['REQUEST_URI'];
}
function tearDown() {
parent::tearDown();
wp_set_current_user(1);
wp_delete_user($this->user_id);
wp_delete_term(
$this->organization_id,
Wiaas_User_Organization::TAXONOMY_NAME);
delete_user_meta($this->user_id, '_wiaas_organization_id');
delete_user_meta($this->user_id, '_wiaas_current_user_admin_role');
$_SERVER['REQUEST_URI'] = $this->request_uri;
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_user_authentication_fail_when_no_selected_role() {
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
$this->assertTrue(
is_wp_error(
Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user())
)
);
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_user_authentication_forwards_error() {
// add roles to organization
$organization_roles = array( 'supplier', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user(false)
);
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_fail_when_organization_has_no_roles() {
$roles = array('administrator', 'supplier', 'customer', 'commercial_lead');
foreach ($roles as $role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $role);
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_fail_when_organization_has_different_roles() {
// add roles to organization
$organization_roles = array( 'supplier', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = array('administrator', 'commercial_lead');
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_valid_when_organization_has_requested_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertEquals(
$this->user_id,
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_invalid_when_organization_has_no_customer_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertFalse(
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_current_user()
* @group authentication
*/
function test_current_user_authentication_valid_when_organization_has_customer_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
foreach ($user_roles as $user_role) {
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', $user_role);
$this->assertEquals(
$this->user_id,
Wiaas_Authentication::authenticate_current_user($this->user_id)
);
}
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_if_no_role_posted() {
$user = wp_get_current_user();
$error = Wiaas_Authentication::authenticate_user_on_login($user);
$this->assertTrue(is_wp_error($error));
$this->assertEquals('You must selected role to login!', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_does_nothing_if_rest_request() {
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
$user = wp_get_current_user();
$response_user = Wiaas_Authentication::authenticate_user_on_login($user);
$this->assertEquals(
$user->ID,
$response_user->ID
);
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_if_customer_role_requested() {
$user = wp_get_current_user();
$_POST['role'] = 'customer';
$error = Wiaas_Authentication::authenticate_user_on_login($user);
$this->assertTrue(is_wp_error($error));
$this->assertEquals('No access!', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_when_user_has_no_organization() {
$_POST['role'] = 'supplier';
delete_user_meta($this->user_id, '_wiaas_organization_id');
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertTrue(is_wp_error($error));
$this->assertEquals('Account not completed!', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_when_organization_has_no_roles() {
$_POST['role'] = 'supplier';
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertTrue(is_wp_error($error));
$this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_fails_when_organization_has_different_roles() {
// add roles to organization
$organization_roles = array( 'supplier', 'customer' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$_POST['role'] = 'commercial_lead';
$error = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertTrue(is_wp_error($error));
$this->assertEquals('Your account is not authorized for requested role. Please contact us for help.', $error->get_error_message());
}
/**
* @covers Wiaas_Authentication::authenticate_user_on_login()
* @group authentication
*/
function test_login_authentication_valid_when_organization_has_requested_role() {
// add roles to organization
$organization_roles = array( 'administrator', 'commercial_lead' );
update_term_meta($this->organization_id, '_wiaas_organization_roles', $organization_roles);
$user_roles = $organization_roles;
foreach ($user_roles as $user_role) {
$_POST['role'] = $user_role;
$response_user = Wiaas_Authentication::authenticate_user_on_login(wp_get_current_user());
$this->assertEquals(
$this->user_id,
$response_user->ID
);
}
}
/**
* @covers Wiaas_Authentication::maybe_filter_user_roles()
* @group authentication
*/
function test_user_has_customer_role_on_rest_request() {
$_SERVER['REQUEST_URI'] = get_home_url('') . '/' . rest_get_url_prefix();
global $wpdb;
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
null, $this->user_id,
$wpdb->get_blog_prefix() . 'capabilities'
);
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$user_roles = $user_roles[0];
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$this->assertArrayHasKey('customer', $user_roles);
$this->assertTrue($user_roles['customer']);
}
/**
* @covers Wiaas_Authentication::maybe_filter_user_roles()
* @group authentication
*/
function test_user_has_no_role_if_not_selected() {
global $wpdb;
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
null, $this->user_id,
$wpdb->get_blog_prefix() . 'capabilities'
);
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$user_roles = $user_roles[0];
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$this->assertEmpty(array_keys($user_roles)[0]);
}
/**
* @covers Wiaas_Authentication::maybe_filter_user_roles()
* @group authentication
*/
function test_user_has_selected_role() {
global $wpdb;
update_user_meta($this->user_id, '_wiaas_current_user_admin_role', 'supplier');
$user_roles = Wiaas_Authentication::maybe_filter_user_roles(
null, $this->user_id,
$wpdb->get_blog_prefix() . 'capabilities'
);
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$user_roles = $user_roles[0];
$this->assertNotNull($user_roles);
$this->assertCount(1, $user_roles);
$this->assertArrayHasKey('supplier', $user_roles);
$this->assertTrue($user_roles['supplier']);
}
}

View File

@@ -5,7 +5,7 @@
*/
class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
var $product, $package, $current_country = 'Sweden';
var $product, $package;
public function setUp() {
parent::setUp();
@@ -13,14 +13,10 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
# set admin as current user
wp_set_current_user(1);
$this->product = $this->create_new_product();
wp_set_object_terms($this->product->get_id(), $this->current_country, 'product_country', false);
clean_object_term_cache( $this->product->get_id(), 'product_country' );
$this->product = $this->factory->product->create_simple_product(array( 'country' => 'sweden' ));
$this->package = $this->create_new_package();
wp_set_object_terms($this->package->get_id(), $this->current_country, 'product_country', false);
clean_object_term_cache( $this->package->get_id(), 'product_country' );
$this->package = $this->factory->product->create_product_bundle(array( 'country' => 'sweden' ));
}
@@ -29,19 +25,13 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
*/
function test_available_countries_created() {
// test taxonomy is available
$taxonomy = get_taxonomy('product_country');
$countries = Wiaas_Countries::get_available_countries();
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
$country_codes = wp_list_pluck($countries, 'code');
$country_names = array_map(function($term) {
return $term->name;
}, get_terms(array( 'taxonomy' => 'product_country', 'hide_empty' => false )));
$this->assertNotEmpty($country_names);
$this->assertContains('Sweden', $country_names);
$this->assertContains('Denmark', $country_names);
$this->assertContains('Finland', $country_names);
$this->assertContains('se', $country_codes);
$this->assertContains('fi', $country_codes);
$this->assertContains('dk', $country_codes);
}
/**
@@ -53,7 +43,7 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
$this->assertNotNull($retrieved_country, 'Product has not country!');
$this->assertEquals($retrieved_country['name'], $this->current_country, 'Retrieved product country is incorrect!');
$this->assertEquals($retrieved_country['name'], 'Sweden', 'Retrieved product country is incorrect!');
}
@@ -65,7 +55,7 @@ class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
$this->assertNotNull($retrieved_country, 'Package has not country!');
$this->assertEquals($retrieved_country['name'], $this->current_country, 'Retrieved package country is incorrect!');
$this->assertEquals($retrieved_country['name'], 'Sweden', 'Retrieved package country is incorrect!');
}
}

View File

@@ -19,9 +19,7 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
'form_id' => $this->form_id,
));
$this->target_form_id = GFFormsModel::search_forms(
'DELIVERY ACTION TYPE: Manual',
true)[0]->id;
$this->target_form_id = Wiaas_Delivery_Process_Action::get_action_forms()[0]['id'];
$this->step = Gravity_Flow_Steps::create( array(
@@ -36,8 +34,8 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
), GFAPI::get_entry($form_entry_id));
}
private function _get_target_entry_meta_key() {
return 'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id';
private function _get_target_action_entries_meta_key() {
return 'wiaas_delivery_step_' . $this->step->get_id() .'_action_entry_ids';
}
/**
@@ -55,25 +53,9 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
$this->assertEquals($this->step->target_form_id, $this->target_form_id);
$this->assertEquals($this->step->get_label(), 'Wiaas Delivery Step');
$this->assertEquals($this->step->get_label(), 'Delivery Step');
#$this->assertEquals($step->is_visible_to_customer, true);
}
/**
* @covers Wiaas_Delivery_Process_Step::get_target_forms_choices
*/
function test_target_forms_choices_are_valid() {
$target_forms_choices = $this->step->get_target_forms_choices();
$available_action_types = Wiaas_Delivery_Process_Step::get_delivery_action_types();
$this->assertEquals(sizeof($target_forms_choices), sizeof($available_action_types));
foreach ($target_forms_choices as $target_forms_choice) {
$this->assertTrue(in_array($target_forms_choice->title, $available_action_types));
}
//$this->assertEquals($this->step->is_visible_to_customer, true);
}
/**
@@ -97,7 +79,7 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
);
$expected_meta = array(
'test' => 'test',
'wiaas_delivery_step_' . $this->step->get_id() .'_entry_id' => null
'wiaas_delivery_step_' . $this->step->get_id() .'_action_entry_ids' => array()
);
$this->assertEquals($expected_meta, $this->step->get_entry_meta($meta, $this->step->get_form_id()));
@@ -109,12 +91,12 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
function test_process_with_no_target_form() {
$this->step->target_form_id = '';
$this->assertTrue($this->step->process());
$this->assertFalse($this->step->process());
# check that entry metadata is not updated
$target_entry_meta_key = $this->_get_target_entry_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
$this->assertFalse($value);
$target_action_entries_meta_key = $this->_get_target_action_entries_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_action_entries_meta_key);
$this->assertEmpty($value);
}
/**
@@ -125,46 +107,13 @@ class Wiaas_Delivery_Process_Step_Test extends Wiaas_Unit_Test_Case {
$this->assertFalse($this->step->process());
# check that entry metadata is updated with correct target entry value
$target_entry_meta_key = $this->_get_target_entry_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_entry_meta_key);
$target_entry_id = absint($value);
$this->assertGreaterThan(0, $target_entry_id);
$target_action_entries_meta_key = $this->_get_target_action_entries_meta_key();
$value = gform_get_meta($this->step->get_entry_id(), $target_action_entries_meta_key);
//$this->assertNotEmpty($value);
# check that entry metadata key for target entry id points to valid entry
$entry = GFAPI::get_entry($target_entry_id);
$this->assertFalse(is_wp_error($entry));
}
/**
* @covers Wiaas_Delivery_Process_Step::status_evaluation
*/
function test_status_evaluation_with_no_target_form() {
$this->step->target_form_id = '';
$this->step->process();
$this->assertEquals($this->step->status_evaluation(), 'complete');
}
/**
* @covers Wiaas_Delivery_Process_Step::status_evaluation
*/
function test_status_evaluation_with_target_form() {
$this->step->process();
# check that step status is now pending
$this->assertEquals($this->step->status_evaluation(), 'pending');
# complete target entry workflow
$api = new Gravity_Flow_API( $this->step->target_form_id );
$target_form_entry = $this->step->get_target_form_entry();
$this->assertEquals($api->get_status($target_form_entry), 'pending');
gform_update_meta($target_form_entry['id'], 'workflow_role_administrator', 'approved');
$target_entry_current_step = $api->get_current_step($target_form_entry);
$target_entry_current_step->refresh_entry();
# check that step status is now complete
$this->assertEquals($this->step->status_evaluation(), 'complete');
// $entry = GFAPI::get_entry($target_entry_id);
//
// $this->assertFalse(is_wp_error($entry));
}
}

View File

@@ -1,156 +0,0 @@
<?php
/**
* Wiaas_Delivery_Process_Test
*
* @package Wiaas
*/
class Wiaas_Delivery_Process_Test extends Wiaas_Unit_Test_Case {
var $process_form, $step_form, $process_form_instance, $process_step, $process_form_workflow_api;
function setUp() {
parent::setUp();
$this->process_form = GFFormsModel::search_forms(
'DELIVERY PROCESS: Normal Delivery',
true)[0];
$this->step_form = GFFormsModel::search_forms(
'DELIVERY ACTION TYPE: Manual',
true)[0];
$process_form_instance_id = GFAPI::add_entry(array(
'form_id' => $this->process_form->id,
));
$this->process_form_instance = GFAPI::get_entry($process_form_instance_id);
$this->process_form_workflow_api = new Gravity_Flow_API( $this->process_form->id );
}
/**
* @covers Wiaas_Delivery_Process::create_delivery_process_for_order
*/
function test_delivery_process_for_order_created() {
$order = wc_create_order();
$order_id = $order->get_id();
Wiaas_Delivery_Process::create_delivery_process_for_order($order_id);
$order_process_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_id'));
$order_process_instance_id = absint(get_post_meta($order_id, 'wiaas_delivery_process_entry_id'));
# check field populated
$this->assertGreaterThan(0, $order_process_id);
$this->assertGreaterThan(0, $order_process_instance_id);
}
/**
* @covers Wiaas_Delivery_Process::extend_gravity_form_entry_meta
*/
function test_gravity_form_entry_meta_extended() {
# create test entry with additional metadata
$entry = array(
'form_id' => $this->step_form->id,
'wiaas_delivery_process_id' => false,
);
$result = GFAPI::add_entry($entry);
# test that entry was successfully created
$this->assertFalse(is_wp_error($result));
}
/**
* @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
*/
function test_do_nothing_if_completed_workflow_has_no_parent() {
# Test there is no exception if entry has no parent process
$entry_id = GFAPI::add_entry(array(
'form_id' => $this->step_form->id
));
$this->assertFalse(
Wiaas_Delivery_Process::maybe_complete_parent_process_step(
$entry_id,
$this->step_form)
);
}
/**
* @covers Wiaas_Delivery_Process::maybe_complete_parent_process_step
*/
function test_process_parent_process_step_on_workflow_completion() {
# get process current step
$process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
# retrieve process steps
$process_steps = $this->process_form_workflow_api->get_steps($this->process_form);
$first_process_step = $process_steps[0];
$second_process_step = $process_steps[1];
# Check that current step is first step of corresponding process
$process_instance_current_step = $this->process_form_workflow_api->get_current_step($process_form_instance);
$this->assertEquals(
$process_instance_current_step->get_id(),
$first_process_step->get_id());
# Update step form entry to complete its workflow
$step_form_entry = $process_instance_current_step->get_target_form_entry();
gform_update_meta($step_form_entry['id'], 'workflow_role_administrator', 'approved');
# execute callback
Wiaas_Delivery_Process::maybe_complete_parent_process_step($step_form_entry['id'], null);
# refresh process instance and check we moved to next step
$process_form_instance = GFAPI::get_entry($this->process_form_instance['id']);
$this->assertEquals(
$this->process_form_workflow_api->get_current_step($process_form_instance)->get_id(),
$second_process_step->get_id());
}
/**
* @covers Wiaas_Delivery_Process::get_order_delivery_process()
*/
function test_get_order_delivery_process() {
$order = wc_create_order();
$order_id = $order->get_id();
$delivery_process = Wiaas_Delivery_Process::get_order_delivery_process($order_id);
$this->assertNotNull($delivery_process);
$steps = $delivery_process['steps'];
$this->assertNotNull($steps);
$this->assertTrue(is_array($steps));
foreach ($steps as $step) {
# test returned step is array
$this->assertTrue(is_array($step));
# test returned step properties
$this->assertArrayHasKey('step_id', $step);
$this->assertArrayHasKey('step_form_entry_id', $step);
$this->assertArrayHasKey('short_desc', $step);
$this->assertArrayHasKey('full_desc', $step);
$this->assertArrayHasKey('action_code', $step);
$this->assertArrayHasKey('step_type', $step);
$this->assertArrayHasKey('status', $step);
$this->assertArrayHasKey('order_id', $step);
$this->assertEquals($step['order_id'], $order_id);
# test that started steps have valid form entry
if ($step['status'] !== 'inactive') {
$process_instance = GFAPI::get_entry($step['step_form_entry_id']);
$this->assertFalse(is_wp_error($process_instance));
}
}
}
}

View File

@@ -6,7 +6,7 @@
class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
var $customer_id, $customer_organization_id, $customer_organization_name, $order_id;
var $customer_id, $customer_organization_id, $customer_organization_name, $order;
public function setUp() {
parent::setUp();
@@ -23,26 +23,15 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$this->customer_organization_name = 'test-customer-organization';
# create customer organization
$this->customer_organization_id = wp_insert_term(
$this->customer_organization_name,
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
$this->customer_organization_id = $this->factory->organization->create_new_organization(
array( 'name' => $this->customer_organization_name )
);
update_user_meta($this->customer_id, '_wiaas_organization_id', $this->customer_organization_id);
# add customer to organization
wp_set_terms_for_user(
$this->customer_id,
Wiaas_User_Organization::TAXONOMY_NAME,
[$this->customer_organization_name]);
$this->factory->organization->assign_user_to_organization($this->customer_id, $this->customer_organization_id);
wp_set_current_user($this->customer_id);
$order = wc_create_order(array(
'customer_id' => $this->customer_id
));
$this->order_id = $order->get_id();
$this->order = $this->factory->order->create_new_order();
}
function tearDown() {
@@ -57,46 +46,6 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
Wiaas_User_Organization::TAXONOMY_NAME);
}
/**
* @covers Wiaas_Order::assign_order_to_organization()
*/
function test_order_assigned_to_customer_organization() {
$organization_access_group = Groups_Group::read_by_name($this->customer_organization_name);
$access_group_ids = Groups_Post_Access::get_read_group_ids( $this->order_id );
$this->assertEquals(1, count($access_group_ids));
$this->assertNotNull($access_group_ids[0]);
$this->assertEquals($organization_access_group->group_id, $access_group_ids[0]);
}
/**
* @covers Wiaas_Order::check_order_access()
*/
function test_order_customer_can_access_order() {
$has_access = Wiaas_Order::check_order_access(true, 'view', $this->order_id, 'shop_order');
$this->assertTrue($has_access);
}
/**
* @covers Wiaas_Order::check_order_access()
*/
function test_customer_cannot_access_order_when_not_in_organization() {
$customer_id = wc_create_new_customer(
'test_customer1@mail.com',
'test_customer1',
'test1');
wp_set_current_user($customer_id);
$this->assertTrue(Groups_Post_Access::handles_post_type('shop_order'));
$has_access = Wiaas_Order::check_order_access(true, 'view', $this->order_id, 'shop_order');
$this->assertFalse($has_access);
}
/**
* @covers Wiaas_Order::wiaas_prepare_rest_orders_query()
*/
@@ -129,30 +78,6 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$args['post_status']);
}
/**
* @covers Wiaas_Order::transform_rest_order()
*/
function test_order_rest_response_has_process() {
$order_response = array(
'customer_id' => $this->customer_id,
'status' => 'processing',
'line_items' => array()
);
$request = array( 'id' => $this->order_id);
$order_rest_response = new WP_REST_Response($order_response);
$order_rest_response = Wiaas_Order::transform_rest_order(
$order_rest_response,
wc_get_order($this->order_id),
$request);
$transformed_order_response = $order_rest_response->get_data();
$this->assertNotNull($transformed_order_response['delivery-process']);
$this->assertTrue(is_array($transformed_order_response['delivery-process']));
}
/**
* @covers Wiaas_Order::transform_rest_order()
*/
@@ -163,10 +88,12 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
'line_items' => array()
);
$this->factory->order->add_customer_organization_info($this->order, $this->customer_organization_id);
$order_rest_response = Wiaas_Order::transform_rest_order(
new WP_REST_Response($order_response),
wc_get_order($this->order_id),
array( 'id' => $this->order_id));
$this->order,
array( 'id' => $this->order->get_id() ));
$transformed_order_response = $order_rest_response->get_data();
@@ -176,28 +103,4 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
$this->assertArrayHasKey('email', $transformed_order_response['customer']);
$this->assertArrayHasKey('phone', $transformed_order_response['customer']);
}
/**
* @covers Wiaas_Order::transform_rest_order()
*/
function test_order_rest_response_has_commercial_lead_info() {
$order_response = array(
'customer_id' => $this->customer_id,
'status' => 'processing',
'line_items' => array()
);
$order_rest_response = Wiaas_Order::transform_rest_order(
new WP_REST_Response($order_response),
wc_get_order($this->order_id),
array( 'id' => $this->order_id));
$transformed_order_response = $order_rest_response->get_data();
$this->assertNotNull($transformed_order_response['commercial_lead']);
$this->assertTrue(is_array($transformed_order_response['commercial_lead']));
$this->assertArrayHasKey('name', $transformed_order_response['commercial_lead']);
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
}
}

View File

@@ -3,15 +3,16 @@
class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
private function _create_package_to_sell() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(20, true, 2);
$this->add_product_category($product2, 'installation');
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
$this->factory->product->create_simple_product(array(
'price' => 20,
'is_recurring' => true,
'pay_period' => 2,
'category' => 'installation' ))
)
));
$pricing_rules = array(
'purchase' => array(
@@ -32,17 +33,16 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
);
$commision = 50;
$cost_margin = 0;
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision, $cost_margin);
$customer_id = wp_create_term(
'Customer',
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
$this->factory->product->set_product_bundle_prices($package, $pricing_rules, $commision, $cost_margin);
$commercial_lead_id = wp_create_term(
'Commercial Lead',
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
$customer_id = $this->factory->organization->create_new_organization(
array( 'name' => 'Customer' )
);
$commercial_lead_id = $this->factory->organization->create_new_organization(
array( 'name' => 'Commercial Lead' )
);
self::_set_package_default_extras($commercial_lead_id, $package->get_id());
@@ -97,7 +97,7 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_product_total_cost()
*/
function test_get_fixed_product_total_cost() {
$product = $this->create_new_product();
$product = $this->factory->product->create_simple_product();
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
@@ -108,7 +108,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_product_total_cost()
*/
function test_get_recurring_product_total_cost() {
$product = $this->create_new_product(10, true, 2);
$product = $this->factory->product->create_simple_product(array(
'price' => 10,
'is_recurring' => true,
'pay_period' => 2
));
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
@@ -119,15 +123,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_package_total_cost()
*/
function test_get_package_with_fixed_products_total_cost() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(20);
$this->add_product_category($product2, 'software');
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'software' ))
)
));
$expected_total_price = 40;
@@ -140,15 +141,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_package_total_cost()
*/
function test_get_package_with_recurring_products_total_cost() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(20, true, 2);
$this->add_product_category($product2, 'software');
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'software' ))
)
));
$expected_total_price = 60;
@@ -161,15 +159,12 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_package_total_cost()
*/
function test_package_with_single_installation_product_total_cost() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(20, true, 2);
$this->add_product_category($product2, 'installation');
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'installation' ))
)
));
$expected_total_price = 60;
@@ -182,20 +177,13 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
* @covers Wiaas_Pricing::get_package_total_cost()
*/
function test_package_with_multiple_installation_products_total_cost() {
$product1 = $this->create_new_product(20);
$this->add_product_category($product1, 'hardware');
$product2 = $this->create_new_product(10, true, 2);
$this->add_product_category($product2, 'installation');
$this->assertTrue(Wiaas_Product_Category::is_installation($product2));
$product3 = $this->create_new_product(20, true, 2);
$this->add_product_category($product3, 'installation');
$package = $this->create_new_package();
$this->add_products_to_package($package, array( $product1, $product2, $product3));
$package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'installation' )),
$this->factory->product->create_simple_product(array( 'price' => 20, 'is_recurring' => true, 'pay_period' => 2, 'category' => 'installation' ))
)
));
// price will be 20 + 20*2 , more expensive installation will be applied
$expected_total_price = 60;
@@ -246,12 +234,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
function test_get_addon_package_customer_price() {
list( $package, $expected_prices, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
$addon_product = $this->create_new_product(20);
$this->add_product_category($addon_product, 'hardware');
$addon_package = $this->create_new_package();
$this->add_products_to_package($addon_package, array($addon_product));
$addon_package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
)
));
$pricing_rules = array(
'purchase' => array(
@@ -330,12 +317,11 @@ class Wiaas_Pricing_Test extends Wiaas_Unit_Test_Case {
function test_get_option_package_customer_price() {
list( $package, $customer_id, $commercial_lead_id ) = $this->_create_package_to_sell();
$option_product = $this->create_new_product(20);
$this->add_product_category($option_product, 'hardware');
$option_package = $this->create_new_package();
$this->add_products_to_package($option_package, array($option_product));
$option_package = $this->factory->product->create_product_bundle(array(
'products' => array(
$this->factory->product->create_simple_product(array( 'price' => 20, 'category' => 'hardware' )),
)
));
$pricing_rules = array(
'purchase' => array(

View File

@@ -19,11 +19,10 @@ class Wiaas_Templates_Test extends Wiaas_Unit_Test_Case {
);
$this->template = $this->create_new_wiaas_template();
$this->product = $this->create_new_product();
$this->package = $this->create_new_package();
$this->add_products_to_package($this->package, $this->product);
$this->product = $this->factory->product->create_simple_product();
$this->package = $this->factory->product->create_product_bundle(array(
'products' => $this->product
));
}
public function test_template_category_taxonomy_created() {

View File

@@ -22,28 +22,18 @@ class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
$this->user_department_name = 'test_department';
# create organization
$this->user_organization_id = wp_insert_term(
$this->user_organization_name,
Wiaas_User_Organization::TAXONOMY_NAME
)['term_id'];
// create organization
$this->user_organization_id = $this->factory->organization->create_new_organization(
array( 'name' => $this->user_organization_name )
);
update_user_meta($this->user_id, '_wiaas_organization_id', $this->user_organization_id);
// create department
$this->user_department_id = $this->factory->organization->create_new_organization(
array( 'name' => $this->user_department_name, 'parent_id' => $this->user_organization_id )
);
# create department
$this->user_department_id = wp_insert_term(
$this->user_department_name,
Wiaas_User_Organization::TAXONOMY_NAME,
array(
'parent' => $this->user_organization_id
)
)['term_id'];
# assign user to organization
wp_set_terms_for_user(
$this->user_id,
Wiaas_User_Organization::TAXONOMY_NAME,
[$this->user_organization_name]);
// assign user to organization
$this->factory->organization->assign_user_to_organization($this->user_id, $this->user_organization_id);
}
function tearDown() {
@@ -53,12 +43,7 @@ class Wiaas_User_Organization_Test extends Wiaas_Unit_Test_Case {
wp_delete_user($this->user_id);
wp_delete_term(
$this->user_organization_id,
Wiaas_User_Organization::TAXONOMY_NAME);
wp_delete_term(
$this->user_department_id,
Wiaas_User_Organization::TAXONOMY_NAME);
$this->factory->organization->delete_organizations();
}
/**

View File

@@ -2,13 +2,18 @@
class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
public $factory;
/**
* Executes any db migrations that are done to
* `wp_options` table since it is deleted on every execution
*/
function setUp() {
parent::setUp();
wp_set_current_user(1);
$this->factory = new Wiaas_Unit_Test_Factory();
wp_set_current_user(1);
# Setup Gravity info since options table is deleted after each test
gf_upgrade()->install();
@@ -28,6 +33,8 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
Wiaas_Order_Project::register_order_project_taxonomy();
Wiaas_Product_Supplier::register_supplier_taxonomy();
Wiaas_Package_Status::register_package_status_taxonomy();
define('WP_TEST_IN_PROGRESS',true);
}

View File

@@ -1,17 +0,0 @@
<?php
class Wiaas_Unit_Test_Factory {
//
public $product;
//
public $package;
//
public $organization;
function __construct() {
}
}

View File

@@ -59,6 +59,8 @@ include_once WIAAS_DIR . '/includes/class-wiass-templates.php';
include_once WIAAS_DIR . '/includes/wiaas-class-measurement-units.php';
include_once WIAAS_DIR . '/includes/class-wiaas-validation.php';
function wiaas_redirect_to_login() {
wp_safe_redirect(get_site_url('', 'wp-login.php'));
}

View File

@@ -106,6 +106,9 @@
"wp wc update",
"wp wc pb update",
"wp wiaas update-db"
],
"timestamp": [
"php -r \"print date('YmdHis') . PHP_EOL;\" "
]
}
}

View File

@@ -76,6 +76,7 @@ define('SENDGRID_FROM_NAME', env('WP_SENDGRID_FROM_NAME' ?: 'Wiaas'));
* Wiaas Env variables
*/
define('WIAAS_CUSTOMER_INTERFACE', env('WIAAS_CUSTOMER_INTERFACE') ?: WP_HOME);
define('WIAAS_SUPPORT_EMAIL', env('WIAAS_SUPPORT_EMAIL') ?: 'support@co-ideation.com');
/**
* Custom Settings
@@ -89,4 +90,4 @@ define('DISALLOW_FILE_EDIT', true);
*/
if (!defined('ABSPATH')) {
define('ABSPATH', $webroot_dir . '/wp/');
}
}

View File

@@ -165,6 +165,13 @@ export const getModules = () => {
url: 'cart',
isInMenu: '0'
},
{
id: '20',
name: 'HelpDesk',
menuName: 'Helpdesk',
url: 'helpdesk',
isInMenu: '0'
},
{
id: '14',
name: 'ProfileSettings',

View File

@@ -325,12 +325,13 @@ export const setSupportMessage = (message) => ({
supportText: message
});
export const sendSupportMail = (orderInfo, orderPackages, supportText) => {
export const sendSupportMail = (orderInfo, orderPackages, support_text) => {
let id = orderInfo.id;
return dispatch => {
return htmlClient.fetch({
url: `${API_SERVER}/orders/api/sendSupportMail`,
url: `${API_SERVER}/wp-json/wiaas/support/send-support-email`,
method: 'post',
data: {orderInfo, orderPackages, supportText}
data: {id, support_text}
})
.then(response => {
if (typeof response.data !== 'undefined' && 'messages' in response.data) {

View File

@@ -4,6 +4,7 @@ import CoMarketContainer from '../containers/coMarket/CoMarketContainer.jsx';
import CartContainer from '../containers/cart/CartContainer.jsx';
import TermsContainer from '../containers/terms/TermsContainer.jsx';
import ProfileSettingsContainer from '../containers/profileSettings/ProfileSettingsContainer.jsx';
import HelpDeskContainer from '../containers/HelpDesk/HelpDeskContainer.jsx';
export const MainContainers = {
Dashboards: {
@@ -22,6 +23,10 @@ export const MainContainers = {
container: CartContainer,
params: []
},
HelpDesk:{
container: HelpDeskContainer,
params: []
},
Terms: {
container: TermsContainer,
params: []

View File

@@ -0,0 +1,11 @@
import React, {Component} from 'react';
import './style/HelpDesk.css';
class HelpDeskContainer extends Component {
render() {
return (<iframe src='https://wiaas.freshservice.com/support/login'></iframe>);
}
}
export default HelpDeskContainer;

View File

@@ -0,0 +1,6 @@
iframe {
display: block;
border: none;
width: 100%;
height: 100vh;
}

View File

@@ -80,7 +80,7 @@ class OrderInfo extends Component {
<Col xl="2">
<div>
<div className="subtitle"><h6>{orderTexts.labels.REFERENCE}:</h6></div>
<span>{orderInfo.reference || '-'}</span>
<span className="reference">{orderInfo.reference || '-'}</span>
</div>
<div>
<div className="subtitle"><h6>{orderTexts.labels.BID}:</h6></div>
@@ -139,7 +139,7 @@ class OrderInfo extends Component {
<Col xl="2">
<div>
<div className="subtitle"><h6>{orderTexts.labels.PROJECT}:</h6></div>
<span>{orderInfo.projectName || '-'}</span>
<span className="project-name">{orderInfo.projectName || '-'}</span>
</div>
<div className="terms-link">

View File

@@ -7,6 +7,14 @@ $link-line-height: 1.5rem;
margin-top: 0.5rem;
}
.reference{
word-break: break-all;
}
.project-name{
word-break: break-all;
}
.info-color {
margin-top: 0.2rem;
padding-left: 0.2rem;

View File

@@ -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,

View File

@@ -1,6 +1,6 @@
export const fromWiaasCountryList = (countryList) => {
return {
idCountry: countryList.country_id,
countryName: countryList.country_name
idCountry: countryList.code,
countryName: countryList.name
}
}

View File

@@ -84,6 +84,13 @@ class Menu extends Component {
)
}
</Nav>
<Nav className="nav-btn-cart navbar-right" navbar>
<NavItem
id="nav-button-helpdesk"
className={(this.props.activeModule === 'helpdesk') ? "navbar-button active" : "navbar-button"}>
<NavLink tag={Link} to="/helpdesk">Helpdesk</NavLink>
</NavItem>
</Nav>
<Nav className="nav-btn-cart navbar-right" navbar>
<NavItem id="nav-button-cart" className="navbar-button">
<NavLink tag={Link} to="/cart">

View File

@@ -25,6 +25,7 @@
font-weight: 600;
text-align: left;
color: #33425b;
word-break: break-all;
}
.wiass-table-small-scr-header{
@@ -50,6 +51,7 @@
}
.wiaas-table-col {
padding-bottom: 0.2rem;
word-break: break-all;
}
}
}