Compare commits
65 Commits
templates
...
backoffice
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ed0f512273 | ||
|
|
0e6f5bdab6 | ||
|
|
0e8816abc0 | ||
|
|
451f9fb2eb | ||
|
|
ea9a47fd39 | ||
|
|
925896c469 | ||
|
|
2cd4a77a34 | ||
|
|
174517a161 | ||
|
|
dc1311340f | ||
|
|
6afffc7eca | ||
|
|
5f744f016e | ||
|
|
0e59272689 | ||
|
|
aa8aa42164 | ||
|
|
415c5d8747 | ||
|
|
12805678b1 | ||
|
|
e1a1b4dc49 | ||
|
|
4ecadc8bcc | ||
|
|
eab040b13d | ||
|
|
fdc01b974e | ||
|
|
11c26aeee1 | ||
|
|
9c4539acfe | ||
|
|
8cc2a7c8bc | ||
|
|
c13983d6df | ||
|
|
0065b25fef | ||
|
|
d8c38ec089 | ||
|
|
cbf1de3403 | ||
|
|
41e92e2390 | ||
|
|
5da2353d04 | ||
|
|
4159f12854 | ||
|
|
3fa75daafd | ||
|
|
c637880245 | ||
|
|
fa2b691996 | ||
|
|
393158808a | ||
|
|
0787cf834f | ||
|
|
522417ca28 | ||
|
|
498f5526a9 | ||
|
|
31115b7c6a | ||
|
|
af2da3eed0 | ||
|
|
d36398f2ab | ||
|
|
32379f7f47 | ||
|
|
82e4579e88 | ||
|
|
b93aed107b | ||
|
|
5d91576fb7 | ||
|
|
c322c8ac78 | ||
|
|
90402d3e1d | ||
|
|
84916a01ed | ||
|
|
b98f3c979c | ||
|
|
a901da55fc | ||
|
|
8a9af7ed8c | ||
|
|
39cb851a55 | ||
|
|
e6e487f312 | ||
|
|
d26569a8be | ||
|
|
aae23e4ea3 | ||
|
|
a79ef1044c | ||
|
|
b974eab225 | ||
|
|
b3cff5d095 | ||
|
|
4ce7b86ea9 | ||
|
|
bc61e2e706 | ||
|
|
9da31990fd | ||
|
|
f63e118579 | ||
|
|
cf92f62703 | ||
|
|
6e5f2af5a3 | ||
|
|
7c2a77b75d | ||
|
|
85deb1d9f8 | ||
|
|
cae148ebce |
@@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Admin_Order_Projects {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
// Add admin page and subpage since woocommerce orders have custom menu page
|
||||||
|
// so this will not be automatic
|
||||||
|
add_filter('admin_menu', array(__CLASS__, 'add_admin_page'));
|
||||||
|
add_action( 'parent_file', array(__CLASS__, 'highlight_order_projects_parent_menu') );
|
||||||
|
|
||||||
|
// Add is available fields to create and edit forms
|
||||||
|
add_action( 'shop_order_project_add_form_fields', array( __CLASS__, 'add_is_available_field' ) );
|
||||||
|
add_action( 'shop_order_project_edit_form_fields', array( __CLASS__, 'edit_is_available_field' ) );
|
||||||
|
|
||||||
|
// Add is available column
|
||||||
|
add_filter( 'manage_edit-shop_order_project_columns', array( __CLASS__, 'update_table_headers' ) );
|
||||||
|
add_filter( 'manage_shop_order_project_custom_column', array( __CLASS__, 'update_table_column_content' ), 10, 3 );
|
||||||
|
|
||||||
|
// Save is available field when creating and editing
|
||||||
|
add_action( 'created_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
|
||||||
|
add_action( 'edit_term', array( __CLASS__, 'save_is_available_field' ), 10, 3 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add admin submenu page for order projects
|
||||||
|
*/
|
||||||
|
public static function add_admin_page() {
|
||||||
|
add_submenu_page( 'woocommerce',
|
||||||
|
esc_html__( 'Order projects', 'wiaas' ),
|
||||||
|
esc_html__( 'Order projects', 'wiaas' ),
|
||||||
|
'manage_woocommerce',
|
||||||
|
'edit-tags.php?taxonomy=shop_order_project'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Correctly highlight parent menu page when order projects submenu is selected
|
||||||
|
* @param $parent_file
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function highlight_order_projects_parent_menu($parent_file) {
|
||||||
|
if ( get_current_screen()->taxonomy == 'shop_order_project' ) {
|
||||||
|
$parent_file = 'woocommerce';
|
||||||
|
}
|
||||||
|
return $parent_file;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add is available field to order project creation form
|
||||||
|
*/
|
||||||
|
public static function add_is_available_field() {
|
||||||
|
?>
|
||||||
|
<div class="form-field form-required">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="postform"
|
||||||
|
style="float:left; margin-top: 4px; margin-right: 10px;"
|
||||||
|
id="is_available"
|
||||||
|
name="is_available"
|
||||||
|
/>
|
||||||
|
<label for="is_available"><?php _e( 'Is Available?', 'wiaas' ); ?></label>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add is available field to order project edit form
|
||||||
|
* @param $order_project
|
||||||
|
*/
|
||||||
|
public static function edit_is_available_field($order_project) {
|
||||||
|
?>
|
||||||
|
<tr class="form-field">
|
||||||
|
<th scope="row" valign="top"><label><?php _e( 'Is Available?', 'wiaas' ); ?></label></th>
|
||||||
|
<td>
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
class="checkbox"
|
||||||
|
id="is_available"
|
||||||
|
name="is_available"
|
||||||
|
<?php
|
||||||
|
checked( true, Wiaas_Order_Project::is_order_project_available($order_project), true )
|
||||||
|
?>
|
||||||
|
/>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update table headers for order projects
|
||||||
|
* Will add `is available` and `wiaas count` columns and remove default count column
|
||||||
|
*
|
||||||
|
* @param array $columns Available order project table headers
|
||||||
|
*
|
||||||
|
* @return array Edited order project table headers
|
||||||
|
*/
|
||||||
|
public static function update_table_headers($columns) {
|
||||||
|
$columns['wiaas_is_available'] = __( 'Is Available?', 'wiaas' );
|
||||||
|
|
||||||
|
$columns['wiaas_count'] = __('Count', 'wiaas');
|
||||||
|
|
||||||
|
unset($columns['posts']);
|
||||||
|
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Render content for order project table column
|
||||||
|
* Will add content for `is available` and `wiaas count` columns
|
||||||
|
*
|
||||||
|
* @param string $columns Row content for order projects table
|
||||||
|
* @param string $column Current column header
|
||||||
|
* @param int $id Order project id
|
||||||
|
*
|
||||||
|
* @return string Edited row content with appended is available info
|
||||||
|
*/
|
||||||
|
public static function update_table_column_content($columns, $column, $id) {
|
||||||
|
if ($column === 'wiaas_is_available') {
|
||||||
|
$is_available = Wiaas_Order_Project::is_order_project_available($id);
|
||||||
|
$columns .= $is_available ? 'Yes' : 'No';
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($column === 'wiaas_count') {
|
||||||
|
$term = get_term($id, 'shop_order_project');
|
||||||
|
$args = array(
|
||||||
|
'shop_order_project' => $term->slug,
|
||||||
|
'post_type' => 'shop_order'
|
||||||
|
);
|
||||||
|
$columns .= "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$term->count</a>";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Save posted is available field for created or edited order project
|
||||||
|
* @param $term_id
|
||||||
|
* @param string $tt_id
|
||||||
|
* @param string $taxonomy
|
||||||
|
*/
|
||||||
|
public static function save_is_available_field($term_id, $tt_id = '', $taxonomy = '') {
|
||||||
|
if ( 'shop_order_project' === $taxonomy ) {
|
||||||
|
Wiaas_Order_Project::set_is_order_project_available($term_id, $_POST['is_available'] === 'on');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Admin_Order_Projects::init();
|
||||||
@@ -58,6 +58,7 @@ class Wiaas_Admin_Package_Pricing {
|
|||||||
$package = wc_get_product( $post->ID );
|
$package = wc_get_product( $post->ID );
|
||||||
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
$pricing_rules = Wiaas_Package_Pricing::get_package_prices($package);
|
||||||
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
|
$commission = Wiaas_Package_Pricing::get_package_pricing_commission($package);
|
||||||
|
$minimum_cost_margin = Wiaas_Package_Pricing::get_package_minimum_cost_margin($package);
|
||||||
|
|
||||||
include 'views/html-package-pricing.php';
|
include 'views/html-package-pricing.php';
|
||||||
}
|
}
|
||||||
@@ -71,7 +72,8 @@ class Wiaas_Admin_Package_Pricing {
|
|||||||
Wiaas_Package_Pricing::set_package_prices(
|
Wiaas_Package_Pricing::set_package_prices(
|
||||||
wc_get_product( $post_id ),
|
wc_get_product( $post_id ),
|
||||||
$_POST['wiaas_pricing_rules'],
|
$_POST['wiaas_pricing_rules'],
|
||||||
$_POST['wiaas_pricing_rules_commision']);
|
$_POST['wiaas_pricing_rules_commision'],
|
||||||
|
$_POST['wiaas_minimum_cost_margin']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -144,6 +144,20 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<div class="options_group">
|
||||||
|
<?php
|
||||||
|
woocommerce_wp_text_input(
|
||||||
|
array(
|
||||||
|
'id' => '_wiaas_minimum_cost_margin',
|
||||||
|
'name' => 'wiaas_minimum_cost_margin',
|
||||||
|
'value' => $minimum_cost_margin,
|
||||||
|
'label' => __( 'Minimum cost margin:', 'wiaas' ),
|
||||||
|
'type' => 'number',
|
||||||
|
)
|
||||||
|
);
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="options_group">
|
<div class="options_group">
|
||||||
<?php
|
<?php
|
||||||
woocommerce_wp_text_input(
|
woocommerce_wp_text_input(
|
||||||
|
|||||||
@@ -6,348 +6,224 @@ class Wiaas_Cart_API {
|
|||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
private static $namespace = 'wiaas/cart';
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
|
private static $rest_base = 'cart';
|
||||||
|
|
||||||
public static function register_routes() {
|
public static function register_routes() {
|
||||||
register_rest_route( self::$namespace, 'count', array(
|
register_rest_route( self::$namespace, '/' . self::$rest_base . '/count', array(
|
||||||
'methods' => 'GET',
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'callback' => array(__CLASS__, 'get_cart_count'),
|
'callback' => array(__CLASS__, 'get_cart_count'),
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
'permission_callback' => 'is_user_logged_in',
|
||||||
) );
|
) );
|
||||||
|
|
||||||
register_rest_route( self::$namespace, 'items', array(
|
register_rest_route( self::$namespace, '/' . self::$rest_base . '/items', array(
|
||||||
'methods' => 'GET',
|
array(
|
||||||
'callback' => array(__CLASS__, 'get_cart_items'),
|
'methods' => WP_REST_Server::READABLE,
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
'callback' => array(__CLASS__, 'get_cart_items'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array(__CLASS__, 'add_package_to_cart'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(
|
||||||
|
'package_id' => array(
|
||||||
|
'description' => __( 'Wiaas package ID.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
|
),
|
||||||
|
'price_id' => array(
|
||||||
|
'description' => __( 'Selected price ID for Wiaas package.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'enum' => array_keys(Wiaas_Package_Pricing::get_available_pay_types()),
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
|
),
|
||||||
|
'options_ids' => array(
|
||||||
|
'description' => __( 'Wiaas package options IDs.', 'wiaas' ),
|
||||||
|
'type' => 'array',
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
|
)
|
||||||
|
),
|
||||||
|
'addons_ids' => array(
|
||||||
|
'description' => __( 'Wiaas package addons IDs.', 'wiaas' ),
|
||||||
|
'type' => 'array',
|
||||||
|
'items' => array(
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
register_rest_route( self::$namespace, 'documents', array(
|
register_rest_route( self::$namespace, '/' . self::$rest_base . '/items/(?P<key>[\w-]+)', array(
|
||||||
'methods' => 'GET',
|
'args' => array(
|
||||||
'callback' => array(__CLASS__, 'get_cart_documents'),
|
'key' => array(
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
'description' => __( 'Unique key identifier for cart package item.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::DELETABLE,
|
||||||
|
'callback' => array(__CLASS__, 'remove_package_from_cart'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::EDITABLE,
|
||||||
|
'callback' => array(__CLASS__, 'update_package_quantity'),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(
|
||||||
|
'quantity' => array(
|
||||||
|
'description' => __( 'New quantity cart package item.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
'validate_callback' => 'rest_validate_request_arg',
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
) );
|
) );
|
||||||
|
|
||||||
register_rest_route( self::$namespace, 'add', array(
|
register_rest_route( self::$namespace, '/' . self::$rest_base . '/checkout', array(
|
||||||
'methods' => 'post',
|
'methods' => WP_REST_Server::CREATABLE,
|
||||||
'callback' => array(__CLASS__, 'add_package_to_cart'),
|
'callback' => array(__CLASS__, 'checkout'),
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(
|
||||||
|
'vat' => array(
|
||||||
|
'description' => __( 'Vat Code for new order.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'required' => true,
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
),
|
||||||
|
'company' => array(
|
||||||
|
'description' => __( 'Company name for new order.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'required' => true,
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
),
|
||||||
|
'reference' => array(
|
||||||
|
'description' => __( 'Location details for new order.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
),
|
||||||
|
'tender' => array(
|
||||||
|
'description' => __( 'Invoice reference for new order.', 'wiaas' ),
|
||||||
|
'type' => 'string',
|
||||||
|
'sanitize_callback' => 'sanitize_key',
|
||||||
|
),
|
||||||
|
'project_id' => array(
|
||||||
|
'description' => __( 'Order project ID for new order.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
),
|
||||||
|
'delivery_address_id' => array(
|
||||||
|
'description' => __( 'ID of delivery address for new order.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'required' => true,
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
),
|
||||||
|
'billing_address_id' => array(
|
||||||
|
'description' => __( 'ID of billing address for new order.', 'wiaas' ),
|
||||||
|
'type' => 'integer',
|
||||||
|
'required' => true,
|
||||||
|
'sanitize_callback' => 'absint',
|
||||||
|
),
|
||||||
|
)
|
||||||
) );
|
) );
|
||||||
|
|
||||||
register_rest_route( self::$namespace, 'remove', array(
|
|
||||||
'methods' => 'post',
|
|
||||||
'callback' => array(__CLASS__, 'remove_package_from_cart'),
|
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
|
||||||
) );
|
|
||||||
|
|
||||||
register_rest_route( self::$namespace, 'update-quantity', array(
|
|
||||||
'methods' => 'post',
|
|
||||||
'callback' => array(__CLASS__, 'update_package_quantity'),
|
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
|
||||||
) );
|
|
||||||
|
|
||||||
register_rest_route( self::$namespace, 'place-order', array(
|
|
||||||
'methods' => 'post',
|
|
||||||
'callback' => array(__CLASS__, 'place_order'),
|
|
||||||
'permission_callback' => array( __CLASS__, 'permission_check' ),
|
|
||||||
) );
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function permission_check() {
|
|
||||||
if (!is_user_logged_in()) {
|
|
||||||
return new WP_Error( 'wiaas_rest_authorization_required',
|
|
||||||
__( 'Sorry, only authorized users can access!', 'wiaas' ),
|
|
||||||
array( 'status' => rest_authorization_required_code() ) );
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cart count
|
* Get cart count
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function get_cart_count() {
|
public static function get_cart_count() {
|
||||||
$items = WC()->cart->get_cart_contents();
|
return rest_ensure_response(array(
|
||||||
|
'count' => Wiaas_Cart::get_cart_packages_count(),
|
||||||
$count = 0;
|
|
||||||
|
|
||||||
foreach ($items as $key => $item) {
|
|
||||||
if (isset($item['_wiaas_standard_package'])) {
|
|
||||||
$count++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WP_REST_Response(array(
|
|
||||||
'count' => $count,
|
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cart items
|
* Get cart items
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
*
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function get_cart_items() {
|
public static function get_cart_items() {
|
||||||
$items = WC()->cart->get_cart_contents();
|
return rest_ensure_response(array(
|
||||||
|
'items' => Wiaas_Cart::get_cart_packages(),
|
||||||
$result = array();
|
));
|
||||||
|
}
|
||||||
foreach ($items as $key => $item) {
|
|
||||||
if (!isset($item['_wiaas_standard_package'])) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
$package = wc_get_product($item['product_id']);
|
|
||||||
|
|
||||||
// Retrieve package addons
|
|
||||||
$addon_cart_items = wiaas_get_cart_item_addons($item);
|
|
||||||
$additional_packages = array();
|
|
||||||
|
|
||||||
foreach ($addon_cart_items as $addon_cart_item) {
|
|
||||||
$additional_package = wc_get_product($addon_cart_item['product_id']);
|
|
||||||
$additional_packages[] = array(
|
|
||||||
'idAdditionalPackage' => $additional_package->get_id(),
|
|
||||||
'packageName' => $additional_package->get_title(),
|
|
||||||
'prices' => array(
|
|
||||||
'fixedExtra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
|
|
||||||
'recurrentExtra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
|
|
||||||
'servicesExtra' => $addon_cart_item['_wiaas_payment']['services_extra'],
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Retrieve package options
|
|
||||||
$option_cart_items = wiaas_get_cart_item_options($item);
|
|
||||||
$package_options = array();
|
|
||||||
foreach ($option_cart_items as $option_cart_item) {
|
|
||||||
$option_package = wc_get_product($option_cart_item['product_id']);
|
|
||||||
$package_options[] = array(
|
|
||||||
'idOptionPackage' => $option_package->get_id(),
|
|
||||||
'groupName' => $option_cart_item['_wiaas_option_group_name'],
|
|
||||||
'packageName' => $option_package->get_title(),
|
|
||||||
'prices' => array(
|
|
||||||
'fixedExtra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
|
|
||||||
'recurrentExtra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
|
|
||||||
'servicesExtra' => $option_cart_item['_wiaas_payment']['services_extra'],
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$totalPrices = Wiaas_Cart::get_cart_item_total($item);
|
|
||||||
|
|
||||||
$country = Wiaas_Countries::get_package_country($package);
|
|
||||||
|
|
||||||
|
|
||||||
$result[] = array(
|
/**
|
||||||
'idPackage' => $item['product_id'],
|
* @param WP_REST_Request $request Request data.
|
||||||
'key' => $item['key'],
|
*
|
||||||
'packageName' => $package->get_title(),
|
* @return WP_REST_Response
|
||||||
'additionalPackages' => $additional_packages,
|
*/
|
||||||
'areAdditionalAvailable' => true,
|
public static function add_package_to_cart($request) {
|
||||||
'areOptionsAvailable' => true,
|
|
||||||
'bids' => array(),
|
|
||||||
'commercialLead' => 'Coor Service Management',
|
|
||||||
'country' => array(
|
|
||||||
'currency' => $country['currency']
|
|
||||||
),
|
|
||||||
'options' => $package_options,
|
|
||||||
'quantity' => $item['quantity'],
|
|
||||||
|
|
||||||
'idPayType' => $item['_wiaas_payment']['id'],
|
$success = Wiaas_Cart::add_package_to_cart(
|
||||||
'payType' => $item['_wiaas_payment']['payment_type'],
|
$request['package_id'],
|
||||||
'periodUnit' => $item['_wiaas_payment']['period_unit'],
|
$request['price_id'],
|
||||||
'idPrice' => $item['_wiaas_payment']['id'],
|
$request['addons_ids'],
|
||||||
'fixedPrice' => $item['_wiaas_payment']['fixed_extra'],
|
$request['options_ids']
|
||||||
'recurrentPrice' => $item['_wiaas_payment']['recurrent_extra'],
|
|
||||||
'servicesPrice' => $item['_wiaas_payment']['services_extra'],
|
|
||||||
|
|
||||||
'totalPrices' => array(
|
|
||||||
'fixedPrice' => $totalPrices['fixed_extra'],
|
|
||||||
'recurrentPrice' => $totalPrices['recurrent_extra'],
|
|
||||||
'servicesPrice' => $totalPrices['services_extra'],
|
|
||||||
),
|
|
||||||
|
|
||||||
'status' => 'available',
|
|
||||||
'idCommercialLead' => 14,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return new WP_REST_Response(
|
|
||||||
array(
|
|
||||||
'cartItems' => $result,
|
|
||||||
'items' => $items,
|
|
||||||
'totalPrice' => ''
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($success) {
|
||||||
|
return wiaas_api_notice('PACKAGE_ADDED', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('PACKAGE_ALREADY_IN_CART', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get cart documents
|
* @param WP_REST_Request $request Request data.
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
*
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function get_cart_documents() {
|
public static function remove_package_from_cart($request) {
|
||||||
return new WP_REST_Response(array(
|
|
||||||
'areFilesUploaded' => true,
|
|
||||||
'templates' => array(),
|
|
||||||
'uploaded' => array()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$success = Wiaas_Cart::remove_package_from_cart($request['key']);
|
||||||
* Add package to cart
|
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
|
||||||
* @return WP_REST_Response
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
public static function add_package_to_cart() {
|
|
||||||
$package_id = $_POST['package_id'];
|
|
||||||
|
|
||||||
$success = WC()->cart->add_to_cart($package_id, 1, 0, array(), array(
|
|
||||||
'_wiaas_standard_package' => true
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($success) {
|
if ($success) {
|
||||||
return new WP_REST_Response(array(
|
return wiaas_api_notice('PACKAGE_REMOVED_FROM_CART', 'success');
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'success',
|
|
||||||
'message' => 'PACKAGE_ADDED'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_REST_Response(array(
|
return wiaas_api_notice('INVALID_PACKAGE_FOR_REMOVE', 'error');
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'error',
|
|
||||||
'message' => 'PACKAGE_ALREADY_IN_CART'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Remove package from cart
|
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
|
||||||
*/
|
|
||||||
public static function remove_package_from_cart() {
|
|
||||||
$package_cart_key = $_POST['package_item_key'];
|
|
||||||
|
|
||||||
$success = WC()->cart->remove_cart_item($package_cart_key);
|
|
||||||
|
|
||||||
if ($success) {
|
|
||||||
return new WP_REST_Response(array(
|
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'success',
|
|
||||||
'message' => 'PACKAGE_REMOVED_FROM_CART'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return new WP_REST_Response(array(
|
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'error',
|
|
||||||
'message' => 'INVALID_PACKAGE_FOR_REMOVE'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update package quantity in cart
|
* Update package quantity in cart
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
*/
|
*/
|
||||||
public static function update_package_quantity() {
|
public static function update_package_quantity($request) {
|
||||||
$package_item_key = $_POST['package_item_key'];
|
|
||||||
$new_quantity = $_POST['quantity'];
|
|
||||||
|
|
||||||
$success = WC()->cart->set_quantity($package_item_key, $new_quantity, true);
|
$success = Wiaas_Cart::update_package_quantity($request['key'], $request['quantity']);
|
||||||
|
|
||||||
if ($success) {
|
if ($success) {
|
||||||
return new WP_REST_Response(array(
|
return wiaas_api_notice('QUANTITY_UPDATED', 'success');
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'success',
|
|
||||||
'message' => 'QUANTITY_UPDATED'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new WP_REST_Response(array(
|
return wiaas_api_notice('QUANTITY_NOT_UPDATED', 'error');
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'error',
|
|
||||||
'message' => 'QUANTITY_NOT_UPDATED'
|
|
||||||
)
|
|
||||||
)
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Placing order as part of checkout process
|
* @param WP_REST_Request $request Request data.
|
||||||
* TODO: This implementation is temporary to enable flow trough basic checkout process and should be changed
|
*
|
||||||
* @return WP_REST_Response
|
* @return WP_REST_Response
|
||||||
* @throws Exception
|
|
||||||
*/
|
*/
|
||||||
public static function place_order() {
|
public static function checkout($request) {
|
||||||
|
|
||||||
$details = $_POST['details'];
|
Wiaas_Checkout::process_checkout($request->get_body_params());
|
||||||
$vat_code = $_POST['vat'];
|
|
||||||
$company_name = $_POST['companyName'];
|
|
||||||
$delivery_address = $_POST['delivery'];
|
|
||||||
$billing_address = $_POST['billing'];
|
|
||||||
|
|
||||||
$order_id = WC()->checkout()->create_order(array());
|
return wiaas_api_notice('ORDER_PLACED', 'success');
|
||||||
$order = wc_get_order( $order_id );
|
|
||||||
|
|
||||||
// set order currency
|
|
||||||
$line_items = $order->get_items();
|
|
||||||
foreach ($line_items as $line_item) {
|
|
||||||
if (isset($line_item['wiaas_currency'])) {
|
|
||||||
$order->set_currency($line_item['wiaas_currency']);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$order->set_shipping_city($delivery_address['city']);
|
|
||||||
$order->set_shipping_country($delivery_address['countryName']);
|
|
||||||
$order->set_shipping_address_1($delivery_address['detailedAddress']);
|
|
||||||
$order->set_shipping_postcode($delivery_address['zipCode']);
|
|
||||||
|
|
||||||
$order->set_billing_city($billing_address['city']);
|
|
||||||
$order->set_billing_country($billing_address['countryName']);
|
|
||||||
$order->set_billing_address_1($billing_address['detailedAddress']);
|
|
||||||
$order->set_billing_postcode($billing_address['zipCode']);
|
|
||||||
$order->set_billing_first_name($billing_address['firstName']);
|
|
||||||
$order->set_billing_last_name($billing_address['lastName']);
|
|
||||||
|
|
||||||
$order->payment_complete();
|
|
||||||
|
|
||||||
|
|
||||||
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
|
|
||||||
add_post_meta($order_id, '_wiaas_company_name', $company_name);
|
|
||||||
add_post_meta($order_id, '_wiaas_project_id', $details['idProject']);
|
|
||||||
add_post_meta($order_id, '_wiaas_reference', $details['reference']);
|
|
||||||
add_post_meta($order_id, '_wiaas_tender', $details['tender']);
|
|
||||||
|
|
||||||
// $order->get_li
|
|
||||||
|
|
||||||
WC()->cart->empty_cart( true );
|
|
||||||
|
|
||||||
return new WP_REST_Response(array(
|
|
||||||
'messages' => array(
|
|
||||||
array(
|
|
||||||
'code' => 'success',
|
|
||||||
'message' => 'ORDER_PLACED'
|
|
||||||
)
|
|
||||||
),
|
|
||||||
'details' => $details
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Order_Projects_API {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
|
private static $rest_base = 'order-projects';
|
||||||
|
|
||||||
|
public static function register_routes() {
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, '/' . self::$rest_base, array(
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::READABLE,
|
||||||
|
'callback' => array( __CLASS__, 'get_order_projects' ),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(),
|
||||||
|
),
|
||||||
|
array(
|
||||||
|
'methods' => WP_REST_Server::CREATABLE,
|
||||||
|
'callback' => array( __CLASS__, 'create_order_project' ),
|
||||||
|
'permission_callback' => 'is_user_logged_in',
|
||||||
|
'args' => array(
|
||||||
|
'name' => array(
|
||||||
|
'type' => 'string',
|
||||||
|
'description' => __( 'Order project name.', 'wiaas' ),
|
||||||
|
'required' => true,
|
||||||
|
'sanitize_callback' => 'sanitize_text_field',
|
||||||
|
'validate_callback' => function($param, $request, $key) {
|
||||||
|
if ($param === '') {
|
||||||
|
return new WP_Error(
|
||||||
|
'rest_invalid_param',
|
||||||
|
'Order project name cannot be empty!'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (strlen($param) > 100) {
|
||||||
|
return new WP_Error(
|
||||||
|
'rest_invalid_param',
|
||||||
|
'Order project name cannot be longer than 100 characters!'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves available order projects
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response
|
||||||
|
*/
|
||||||
|
public static function get_order_projects() {
|
||||||
|
$projects = Wiaas_Order_Project::get_available_order_projects();
|
||||||
|
|
||||||
|
return rest_ensure_response($projects);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new available order project
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Request data.
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response
|
||||||
|
*/
|
||||||
|
public static function create_order_project($request) {
|
||||||
|
$name = $request['name'];
|
||||||
|
|
||||||
|
$success = Wiaas_Order_Project::add_order_project($name);
|
||||||
|
if ($success) {
|
||||||
|
return wiaas_api_notice('PROJECT_ADDED', 'success');
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('INVALID_DATA', 'error');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_REST_Customer_API {
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
include_once dirname( __FILE__ ) . '/../user/class-wiaas-customer.php';
|
||||||
|
include_once dirname( __FILE__ ) . '/helper/class-rest-helper-functions.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function register_routes() {
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses', array(
|
||||||
|
'methods' => 'PUT',
|
||||||
|
'callback' => array(__CLASS__, 'update_customer_profile_addresses'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/profile-addresses/(?P<address_id>\d+)', array(
|
||||||
|
'methods' => 'DELETE',
|
||||||
|
'callback' => array(__CLASS__, 'delete_customer_profile_address'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/billing-addresses', array(
|
||||||
|
'methods' => 'PUT',
|
||||||
|
'callback' => array(__CLASS__, 'update_customer_billing_addresses'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/billing-addresses/(?P<address_id>\d+)', array(
|
||||||
|
'methods' => 'DELETE',
|
||||||
|
'callback' => array(__CLASS__, 'delete_customer_billing_addresses'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/personal-info', array(
|
||||||
|
'methods' => 'PUT',
|
||||||
|
'callback' => array(__CLASS__, 'update_customer_personal_info'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'customer/(?P<id>\d+)/company-info', array(
|
||||||
|
'methods' => 'PUT',
|
||||||
|
'callback' => array(__CLASS__, 'update_customer_company_info'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static function update_customer_profile_addresses(WP_REST_Request $request){
|
||||||
|
$customer_id = $request['id'];
|
||||||
|
$params = $request->get_body_params();
|
||||||
|
$new_address = json_decode($params['profile_address']);
|
||||||
|
|
||||||
|
if (!Wiaas_Customer::update_customer_profile_addresses($customer_id, $new_address)){
|
||||||
|
return wiaas_api_notice('PROFILE_ADDRESS_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('PROFILE_ADDRESS_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete_customer_profile_address(WP_REST_Request $request){
|
||||||
|
$customer_id = $request['id'];
|
||||||
|
$address_id = $request['address_id'];
|
||||||
|
|
||||||
|
if (!Wiaas_Customer::delete_customer_profile_address($customer_id, $address_id)){
|
||||||
|
return wiaas_api_notice('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('ADDRESS_REMOVED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_billing_addresses(WP_REST_Request $request){
|
||||||
|
$customer_id = $request['id'];
|
||||||
|
$params = $request->get_body_params();
|
||||||
|
$new_address = json_decode($params['billing_address']);
|
||||||
|
|
||||||
|
if (!Wiaas_Customer::update_customer_billing_addresses($customer_id, $new_address)){
|
||||||
|
return wiaas_api_notice('BILLING_ADDRESS_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('BILLING_ADDRESS_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete_customer_billing_addresses(WP_REST_Request $request){
|
||||||
|
$customer_id = $request['id'];
|
||||||
|
$address_id = $request['address_id'];
|
||||||
|
|
||||||
|
if (!Wiaas_Customer::delete_customer_billing_address($customer_id, $address_id)){
|
||||||
|
return wiaas_api_notice('ADDRESS_ERROR', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('ADDRESS_REMOVED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_personal_info(WP_REST_Request $request){
|
||||||
|
$customer_id = $request['id'];
|
||||||
|
$params = $request->get_body_params();
|
||||||
|
|
||||||
|
$first_name = $params['first_name'];
|
||||||
|
$last_name = $params['last_name'];
|
||||||
|
$phone = $params['phone'];
|
||||||
|
$name = $first_name . ' ' . $last_name;
|
||||||
|
|
||||||
|
if (!is_string($name) || strlen($name) === 1){
|
||||||
|
return wiaas_api_notice('ADD_NAME', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_string($phone) || strlen($phone) < 1){
|
||||||
|
return wiaas_api_notice('ADD_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));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('PROFILE_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_company_info(WP_REST_Request $request){
|
||||||
|
$customer_id = $request['id'];
|
||||||
|
$params = $request->get_body_params();
|
||||||
|
|
||||||
|
$company_name = $params['company_name'];
|
||||||
|
$vat_code = $params['vat_code'];
|
||||||
|
|
||||||
|
|
||||||
|
if (!is_string($company_name) || strlen($company_name) < 1){
|
||||||
|
return wiaas_api_notice('ADD_COMPANY_NAME', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is_string($vat_code) || strlen($vat_code) < 1){
|
||||||
|
return wiaas_api_notice('ADD_VAT', 'error', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!Wiaas_Customer::update_customer_company_info($customer_id, $company_name, $vat_code)){
|
||||||
|
return wiaas_api_notice('COMPANY_NOT_CHANGED', 'warning', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
return wiaas_api_notice('COMPANY_UPDATED', 'success', Wiaas_Customer::get_customer_info($customer_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -93,15 +93,13 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$response = new WP_REST_Response( $data );
|
return rest_ensure_response($data);
|
||||||
|
|
||||||
return $response;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_customer_acceptance(WP_REST_Request $request){
|
public static function get_customer_acceptance(WP_REST_Request $request){
|
||||||
$entry = GFAPI::get_entry($request['entry_id']);
|
$entry = GFAPI::get_entry($request['entry_id']);
|
||||||
if (is_wp_error($entry)){
|
if (is_wp_error($entry)){
|
||||||
return self::generate_error('Customer acceptance entry not found', 404);
|
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$acceptance_documents = array();
|
$acceptance_documents = array();
|
||||||
@@ -130,27 +128,25 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
$acceptance_status = ($entry[self::ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1;
|
$acceptance_status = ($entry[self::ACCEPTANCE_STATUS_FIELD_ID] === 'accept') ? 1 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = array(
|
return rest_ensure_response(array(
|
||||||
'documents' => $acceptance_documents,
|
'documents' => $acceptance_documents,
|
||||||
'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
|
'expiration' => $entry[self::EXPIRATION_DATE_FIELD_ID],
|
||||||
'status' => $acceptance_status,
|
'status' => $acceptance_status,
|
||||||
'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
|
'decline_reason' => $entry[self::DECLINE_REASON_FIELD_ID]
|
||||||
);
|
));
|
||||||
|
|
||||||
return new WP_REST_Response($result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function submit_customer_acceptance(WP_REST_Request $request){
|
public static function submit_customer_acceptance(WP_REST_Request $request){
|
||||||
$entry = GFAPI::get_entry($request['entry_id']);
|
$entry = GFAPI::get_entry($request['entry_id']);
|
||||||
if (is_wp_error($entry)){
|
if (is_wp_error($entry)){
|
||||||
return self::generate_error('Customer acceptance entry not found', 404);
|
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = $request['actionType'];
|
$status = $request['actionType'];
|
||||||
$reason = $request['declineReason'];
|
$reason = $request['declineReason'];
|
||||||
|
|
||||||
if (!in_array($status, self::ACCEPTABLE_STATUS)){
|
if (!in_array($status, self::ACCEPTABLE_STATUS)){
|
||||||
return self::generate_wiaas_response('ACCEPTANCE_STATUS_MISSING', 'error');
|
return wiaas_api_notice('ACCEPTANCE_STATUS_MISSING', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
$installation_declined = ($status === self::DECLINE_STATUS_LABEL);
|
$installation_declined = ($status === self::DECLINE_STATUS_LABEL);
|
||||||
@@ -158,25 +154,25 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
|
$uploaded_files = json_decode($entry[self::UPLOADED_FILES_FIELD_ID]);
|
||||||
|
|
||||||
if ($installation_declined && $reason === ''){
|
if ($installation_declined && $reason === ''){
|
||||||
return self::generate_wiaas_response('DECLINE_REASON_EMPTY', 'error');
|
return wiaas_api_notice('DECLINE_REASON_EMPTY', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$installation_declined && (count($uploaded_files)===0)){
|
if (!$installation_declined && (count($uploaded_files)===0)){
|
||||||
return self::generate_wiaas_response('ACCEPTANCE_NOT_UPLOADED', 'error');
|
return wiaas_api_notice('ACCEPTANCE_NOT_UPLOADED', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry[self::DECLINE_REASON_FIELD_ID] = $reason;
|
$entry[self::DECLINE_REASON_FIELD_ID] = $reason;
|
||||||
$entry[self::ACCEPTANCE_STATUS_FIELD_ID] = $status;
|
$entry[self::ACCEPTANCE_STATUS_FIELD_ID] = $status;
|
||||||
|
|
||||||
if (!GFAPI::update_entry( $entry )){
|
if (!GFAPI::update_entry( $entry )){
|
||||||
return self::generate_wiaas_response('INTERNAL_SERVER_ERROR', 'error');
|
return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if step is already completed, to not submit again
|
//Check if step is already completed, to not submit again
|
||||||
$gf_api = new Gravity_Flow_API($entry['form_id']);
|
$gf_api = new Gravity_Flow_API($entry['form_id']);
|
||||||
$current_step = $gf_api->get_current_step($entry);
|
$current_step = $gf_api->get_current_step($entry);
|
||||||
if ($current_step->get_name() !== self::USER_INPUT_STEP_NAME){
|
if ($current_step->get_name() !== self::USER_INPUT_STEP_NAME){
|
||||||
return self::generate_wiaas_response('ACCEPTANCE_STATUS_UPDATED', 'success');
|
return wiaas_api_notice('ACCEPTANCE_STATUS_UPDATED', 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $current_step ) {
|
if ( $current_step ) {
|
||||||
@@ -195,20 +191,20 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
|
|
||||||
|
|
||||||
if ($installation_declined){
|
if ($installation_declined){
|
||||||
return self::generate_wiaas_response('INSTALLATION_DECLINED', 'success');
|
return wiaas_api_notice('INSTALLATION_DECLINED', 'success');
|
||||||
}
|
}
|
||||||
return self::generate_wiaas_response('INSTALLATION_ACCEPTED', 'success');
|
return wiaas_api_notice('INSTALLATION_ACCEPTED', 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function upload_file(WP_REST_Request $request){
|
public static function upload_file(WP_REST_Request $request){
|
||||||
$files = $request->get_file_params();
|
$files = $request->get_file_params();
|
||||||
if (!$files[self::FILE_KEY_NAME]){
|
if (!$files[self::FILE_KEY_NAME]){
|
||||||
return self::generate_wiaas_response('NO_FILES_UPLOADED', 'error');
|
return wiaas_api_notice('NO_FILES_UPLOADED', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
$entry = GFAPI::get_entry($request['entry_id']);
|
$entry = GFAPI::get_entry($request['entry_id']);
|
||||||
if (is_wp_error($entry)){
|
if (is_wp_error($entry)){
|
||||||
return self::generate_error('Customer acceptance entry not found', 404);
|
return wiaas_api_generate_error('Customer acceptance entry not found', 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$form = GFAPI::get_form($entry['form_id']);
|
$form = GFAPI::get_form($entry['form_id']);
|
||||||
@@ -223,12 +219,12 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
$file_path_details = pathinfo($file_name);
|
$file_path_details = pathinfo($file_name);
|
||||||
|
|
||||||
if ( GFCommon::file_name_has_disallowed_extension( $file_name ) ) {
|
if ( GFCommon::file_name_has_disallowed_extension( $file_name ) ) {
|
||||||
return self::generate_wiaas_response('INVALID_FILE_ACCEPTANCE', 'error');
|
return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
|
||||||
}
|
}
|
||||||
$allowed_extensions = ! empty( $upload_file_field->allowedExtensions ) ? GFCommon::clean_extensions( explode( ',', strtolower( $upload_file_field->allowedExtensions ) ) ) : array();
|
$allowed_extensions = ! empty( $upload_file_field->allowedExtensions ) ? GFCommon::clean_extensions( explode( ',', strtolower( $upload_file_field->allowedExtensions ) ) ) : array();
|
||||||
if ( ! empty( $allowed_extensions ) ) {
|
if ( ! empty( $allowed_extensions ) ) {
|
||||||
if ( ! GFCommon::match_file_extension( $file_name, $allowed_extensions ) ) {
|
if ( ! GFCommon::match_file_extension( $file_name, $allowed_extensions ) ) {
|
||||||
return self::generate_wiaas_response('INVALID_FILE_ACCEPTANCE', 'error');
|
return wiaas_api_notice('INVALID_FILE_ACCEPTANCE', 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -236,13 +232,13 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
|
|
||||||
// Bypasses security checks when running unit tests.
|
// Bypasses security checks when running unit tests.
|
||||||
if ( defined( 'WP_TEST_IN_PROGRESS' ) && WP_TEST_IN_PROGRESS ) {
|
if ( defined( 'WP_TEST_IN_PROGRESS' ) && WP_TEST_IN_PROGRESS ) {
|
||||||
return self::generate_wiaas_response('FILE_UPLOADED', 'success');
|
return wiaas_api_notice('FILE_UPLOADED', 'success');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( move_uploaded_file($files[self::FILE_KEY_NAME]['tmp_name'], $target_path . $new_file_name ) ) {
|
if ( move_uploaded_file($files[self::FILE_KEY_NAME]['tmp_name'], $target_path . $new_file_name ) ) {
|
||||||
GFFormsModel::set_permissions( $target_path . $new_file_name );
|
GFFormsModel::set_permissions( $target_path . $new_file_name );
|
||||||
} else {
|
} else {
|
||||||
return self::generate_wiaas_response('INTERNAL_SERVER_ERROR', 'error');
|
return wiaas_api_notice('INTERNAL_SERVER_ERROR', 'error');
|
||||||
}
|
}
|
||||||
|
|
||||||
//Extract path relative to the root
|
//Extract path relative to the root
|
||||||
@@ -269,35 +265,9 @@ class Wiass_REST_Delivery_Process_API {
|
|||||||
$entry[self::UPLOADED_FILES_FIELD_ID] = json_encode($uploaded_files);
|
$entry[self::UPLOADED_FILES_FIELD_ID] = json_encode($uploaded_files);
|
||||||
|
|
||||||
if (GFAPI::update_entry( $entry )) {
|
if (GFAPI::update_entry( $entry )) {
|
||||||
return self::generate_wiaas_response('FILE_UPLOADED','success');
|
return wiaas_api_notice('FILE_UPLOADED','success');
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::generate_wiaas_response('NOT_UPLOADED', 'error');
|
return wiaas_api_notice('NOT_UPLOADED', 'error');
|
||||||
}
|
|
||||||
|
|
||||||
//Helper function
|
|
||||||
private static function generate_error($message, $code = 500){
|
|
||||||
$error = array(
|
|
||||||
'status' => $code,
|
|
||||||
'message' => $message,
|
|
||||||
);
|
|
||||||
|
|
||||||
$result = new WP_REST_Response($error);
|
|
||||||
$result->set_status($code);
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static function generate_wiaas_response($message, $code, $data = NULL){
|
|
||||||
$response = array(
|
|
||||||
'messages' => [
|
|
||||||
array(
|
|
||||||
'code' => $code,
|
|
||||||
'message' => $message
|
|
||||||
)
|
|
||||||
],
|
|
||||||
'data' => $data
|
|
||||||
);
|
|
||||||
|
|
||||||
return new WP_REST_Response($response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiass_REST_User_API {
|
||||||
|
/**
|
||||||
|
* Endpoint namespace.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
private static $namespace = 'wiaas';
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
include_once dirname( __FILE__ ) . '/../class-wiaas-countries.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function register_routes() {
|
||||||
|
register_rest_route( self::$namespace, 'user/validate-token', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => array(__CLASS__, 'validate_token'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
|
||||||
|
register_rest_route( self::$namespace, 'user/get-countries', array(
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => array(__CLASS__, 'get_countries'),
|
||||||
|
'permission_callback' => 'is_user_logged_in'
|
||||||
|
) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static function validate_token() {
|
||||||
|
$user = wp_get_current_user();
|
||||||
|
|
||||||
|
return rest_ensure_response(array(
|
||||||
|
'userInfo' => array(
|
||||||
|
'wiaas_id_user' => $user->ID,
|
||||||
|
'wiaas_is_company_admin' => 1, //TODO: don't hardcode this
|
||||||
|
'wiaas_user_full_name' => $user->first_name . ' ' . $user->last_name,
|
||||||
|
'wiaas_user_type' => $user->roles,
|
||||||
|
'wiaas_username' => $user->data->user_login
|
||||||
|
)
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_countries(){
|
||||||
|
$countries = Wiaas_Countries::get_list_of_countries();
|
||||||
|
|
||||||
|
return rest_ensure_response($countries);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates REST API notice response
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param string $code
|
||||||
|
* @param array|null $data
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response
|
||||||
|
*/
|
||||||
|
function wiaas_api_notice($message, $code, $data = null) {
|
||||||
|
return rest_ensure_response(array(
|
||||||
|
'messages' => [
|
||||||
|
array(
|
||||||
|
'code' => $code,
|
||||||
|
'message' => $message
|
||||||
|
)
|
||||||
|
],
|
||||||
|
'data' => $data
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate REST API error
|
||||||
|
*
|
||||||
|
* @param string $message
|
||||||
|
* @param int $code
|
||||||
|
*
|
||||||
|
* @return WP_REST_Response
|
||||||
|
*/
|
||||||
|
function wiaas_api_generate_error($message, $code = 500) {
|
||||||
|
$response = rest_ensure_response(array(
|
||||||
|
'status' => $code,
|
||||||
|
'message' => $message,
|
||||||
|
));
|
||||||
|
$response->set_status($code);
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
@@ -12,6 +12,9 @@ class Wiaas_Admin {
|
|||||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-admin-template-selection.php';
|
require_once dirname(__FILE__) . '/admin/template/class-wiaas-admin-template-selection.php';
|
||||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-products.php';
|
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-products.php';
|
||||||
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-admin-ajax.php';
|
require_once dirname(__FILE__) . '/admin/template/class-wiaas-template-admin-ajax.php';
|
||||||
|
|
||||||
|
// Admin order projects interface
|
||||||
|
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-projects.php';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,13 +34,28 @@ class Wiaas_API {
|
|||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-delivery-process-api.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-delivery-process-api.php';
|
||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-cart-api.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-cart-api.php';
|
||||||
include_once dirname( __FILE__ ) . '/api/class-wiaas-document-api.php';
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-document-api.php';
|
||||||
|
|
||||||
|
#User controller
|
||||||
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-user-api.php';
|
||||||
|
|
||||||
|
#Customer controller
|
||||||
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-rest-customer.php';
|
||||||
|
|
||||||
|
include_once dirname( __FILE__ ) . '/api/class-wiaas-order-projects-api.php';
|
||||||
|
|
||||||
|
// API functions
|
||||||
|
include_once dirname( __FILE__ ) . '/api/wiaas-api-functions.php';
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function register_rest_routes() {
|
public static function register_rest_routes() {
|
||||||
$controllers = array(
|
$controllers = array(
|
||||||
'Wiass_REST_Delivery_Process_API',
|
'Wiass_REST_Delivery_Process_API',
|
||||||
'Wiaas_Cart_API',
|
'Wiaas_Cart_API',
|
||||||
'Wiaas_Document_API'
|
'Wiaas_Document_API',
|
||||||
|
'Wiass_REST_User_API',
|
||||||
|
'Wiaas_REST_Customer_API',
|
||||||
|
'Wiaas_Order_Projects_API'
|
||||||
);
|
);
|
||||||
|
|
||||||
foreach ( $controllers as $controller ) {
|
foreach ( $controllers as $controller ) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: This implementation is temporary and will probably be changed during implementation of currently pending cart task
|
* Handles Wiaas Cart specific tasks
|
||||||
*
|
*
|
||||||
* Class Wiaas_Cart
|
* Class Wiaas_Cart
|
||||||
*/
|
*/
|
||||||
@@ -18,109 +18,140 @@ class Wiaas_Cart {
|
|||||||
|
|
||||||
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
add_filter( 'woocommerce_hidden_order_itemmeta', array( __CLASS__, 'hidden_order_item_meta' ) );
|
||||||
|
|
||||||
add_filter( 'woocommerce_add_cart_item_data', array( __CLASS__, 'add_cart_item_data' ), 10, 2 );
|
|
||||||
|
|
||||||
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
add_action( 'woocommerce_before_calculate_totals', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||||
|
|
||||||
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
add_action( 'woocommerce_cart_loaded_from_session', array( __CLASS__, 'on_calculate_totals' ), 99, 1);
|
||||||
|
|
||||||
// Add options and addons to cart.
|
|
||||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Handles adding standard wiaas package to cart along with selected addons and options
|
||||||
|
*
|
||||||
* Extend cart item data with wiaas package payment info and addons and options
|
* Extend cart item data with wiaas package payment info and addons and options
|
||||||
*
|
*
|
||||||
* Every package cart item will be extended with its payment info but only standard package type
|
* Every package cart item will be extended with its payment info but only standard package type
|
||||||
* will be extended with addons and options arrays
|
* will be extended with addons and options arrays
|
||||||
*
|
*
|
||||||
* @param $cart_item_data
|
* @param int $package_id Package ID of selected package
|
||||||
* @param $package_id
|
* @param string $price_id Price ID of selected package payment
|
||||||
|
* @param array $addons_ids Array of selected additional packages IDs
|
||||||
|
* @param array $options_ids Array of selected option packages IDs
|
||||||
*
|
*
|
||||||
* @return array
|
* @return bool TRUE if all packages are succesfully added to cart, FALSE otherwise
|
||||||
*/
|
*/
|
||||||
public static function add_cart_item_data($cart_item_data, $package_id) {
|
public static function add_package_to_cart($package_id, $price_id, $addons_ids, $options_ids) {
|
||||||
|
// try adding package to cart
|
||||||
|
try {
|
||||||
|
//Check if package exists
|
||||||
|
$package = wc_get_product( $package_id );
|
||||||
|
if (!$package) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
$is_valid = isset( $_POST[ 'price_id' ]) &&
|
// Retrieve package country
|
||||||
WC_Product_Factory::get_product_type( $package_id ) === 'bundle';
|
$country = Wiaas_Countries::get_package_country($package);
|
||||||
|
|
||||||
if (!$is_valid) {
|
// Retrieve package price
|
||||||
return $cart_item_data;
|
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||||
|
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||||
|
|
||||||
|
// Initialize additional cart item data for wiaas packages
|
||||||
|
$wiaas_cart_item_data = array(
|
||||||
|
'_wiaas_standard_package' => true,
|
||||||
|
'_wiaas_addon_items' => array(),
|
||||||
|
'_wiaas_option_items' => array(),
|
||||||
|
'_wiaas_currency' => isset($country) ? $country['currency'] : get_woocommerce_currency(),
|
||||||
|
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null
|
||||||
|
);
|
||||||
|
|
||||||
|
$cart_item_key = WC()->cart->add_to_cart($package_id, 1, 0, array(), $wiaas_cart_item_data);
|
||||||
|
|
||||||
|
if (!$cart_item_key) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add selected additional packages and options
|
||||||
|
self::_add_additional_packages_to_cart($cart_item_key, $price_id, $addons_ids, $options_ids);
|
||||||
|
|
||||||
|
// Trigger calculation of total prices after additional packages are added
|
||||||
|
WC()->cart->calculate_totals();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch( Exception $e) {
|
||||||
|
|
||||||
|
error_log($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Remove given package item key from cart
|
||||||
|
*
|
||||||
|
* @param string $package_cart_item_key
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function remove_package_from_cart($package_cart_item_key) {
|
||||||
|
|
||||||
|
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||||
|
|
||||||
|
if (!$cart_item) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$package_type = Wiaas_Package_Type::get_package_type($package_id);
|
$package_addon_item_keys = $cart_item['_wiaas_addon_items'];
|
||||||
|
$package_option_item_keys = $cart_item['_wiaas_option_items'];
|
||||||
|
|
||||||
$package = wc_get_product( $package_id );
|
$success = WC()->cart->remove_cart_item($package_cart_item_key);
|
||||||
|
|
||||||
switch ($package_type) {
|
if ($success) {
|
||||||
case 'standard':
|
foreach ($package_addon_item_keys as $package_addon_item_key) {
|
||||||
|
WC()->cart->remove_cart_item($package_addon_item_key);
|
||||||
|
}
|
||||||
|
|
||||||
$cart_item['_wiaas_standard_package'] = true;
|
foreach ($package_option_item_keys as $package_option_item_key) {
|
||||||
|
WC()->cart->remove_cart_item($package_option_item_key);
|
||||||
// Prepare addons additional data for later use.
|
}
|
||||||
if ( ! isset( $cart_item_data['_wiaas_addon_items'] ) ) {
|
|
||||||
$cart_item_data['_wiaas_addon_items' ] = array();
|
|
||||||
}
|
|
||||||
// Prepare options additional data for later use.
|
|
||||||
if ( ! isset( $cart_item_data['_wiaas_option_items'] ) ) {
|
|
||||||
$cart_item_data['_wiaas_option_items' ] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$country = Wiaas_Countries::get_package_country($package);
|
|
||||||
if (isset($country)) {
|
|
||||||
$cart_item_data['_wiaas_currency'] = $country['currency'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$package_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
|
||||||
break;
|
|
||||||
case 'add_on':
|
|
||||||
$parent_key = $cart_item_data['_wiaas_addon_for'];
|
|
||||||
$parent_item = WC()->cart->get_cart_item($parent_key);
|
|
||||||
|
|
||||||
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($package, $parent_item['data']);
|
|
||||||
break;
|
|
||||||
case 'option':
|
|
||||||
$parent_key = $cart_item_data['_wiaas_option_for'];
|
|
||||||
$parent_item = WC()->cart->get_cart_item($parent_key);
|
|
||||||
|
|
||||||
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $package);
|
|
||||||
$cart_item_data['_wiaas_option_group_name' ] = $option_group_name;
|
|
||||||
|
|
||||||
$package_prices = Wiaas_Pricing::get_option_package_customer_price($package, $parent_item['data']);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$selected_price_index = array_search($_POST['price_id'], array_column($package_prices, 'id'));
|
return $success;
|
||||||
|
|
||||||
if (is_numeric($selected_price_index) && isset($package_prices[$selected_price_index])) {
|
|
||||||
$cart_item_data['_wiaas_payment'] = $package_prices[$selected_price_index];
|
|
||||||
}
|
|
||||||
|
|
||||||
return $cart_item_data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add selected package options and addons after parent standard package is added to cart
|
* Update quantity of package in cart
|
||||||
|
* @param string $package_cart_item_key
|
||||||
|
* @param int $new_quantity
|
||||||
*
|
*
|
||||||
* @param $cart_item_key
|
* @return bool
|
||||||
* @param $package_id
|
|
||||||
* @param $quantity
|
|
||||||
* @param $variation_id
|
|
||||||
* @param $variation
|
|
||||||
* @param $cart_item_data
|
|
||||||
*/
|
*/
|
||||||
public static function add_additional_packages_to_cart($cart_item_key, $package_id, $quantity, $variation_id, $variation, $cart_item_data) {
|
public static function update_package_quantity($package_cart_item_key, $new_quantity) {
|
||||||
|
$cart_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||||
|
|
||||||
remove_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ));
|
if (!$cart_item) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
self::_add_options_to_cart($cart_item_key, $package_id, $cart_item_data);
|
$package_addon_item_keys = $cart_item['_wiaas_addon_items'];
|
||||||
|
$package_option_item_keys = $cart_item['_wiaas_option_items'];
|
||||||
|
|
||||||
self::_add_addons_to_cart($cart_item_key, $package_id, $cart_item_data);
|
$success = WC()->cart->set_quantity($package_cart_item_key, $new_quantity, true);
|
||||||
|
|
||||||
add_action( 'woocommerce_add_to_cart', array( __CLASS__, 'add_additional_packages_to_cart' ), 10, 6 );
|
if ($success) {
|
||||||
|
foreach ($package_addon_item_keys as $package_addon_item_key) {
|
||||||
|
WC()->cart->set_quantity($package_addon_item_key, $new_quantity, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($package_option_item_keys as $package_option_item_key) {
|
||||||
|
WC()->cart->set_quantity($package_option_item_key, $new_quantity, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update package cart item with `minimal_fixed_price` as its price
|
* Update package cart item with `minimal_fixed_price` as its price
|
||||||
* so resulting totals would be sum of these prices
|
* so resulting totals would be sum of these prices
|
||||||
@@ -264,72 +295,201 @@ class Wiaas_Cart {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves count of wiaas standard packages in cart
|
||||||
|
*
|
||||||
|
* @return int Number of wiaas standard packages in cart
|
||||||
|
*/
|
||||||
|
public static function get_cart_packages_count() {
|
||||||
|
$items = WC()->cart->get_cart_contents();
|
||||||
|
|
||||||
|
return array_reduce($items, function($count, $item) {
|
||||||
|
if (isset($item['_wiaas_standard_package'])) {
|
||||||
|
$count++;
|
||||||
|
}
|
||||||
|
return $count;
|
||||||
|
}, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves packages data from cart
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function get_cart_packages() {
|
||||||
|
$items = WC()->cart->get_cart_contents();
|
||||||
|
|
||||||
|
$package_items = array();
|
||||||
|
|
||||||
|
foreach ($items as $key => $item) {
|
||||||
|
if (!isset($item['_wiaas_standard_package'])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$package = wc_get_product($item['product_id']);
|
||||||
|
|
||||||
|
// Collect additional packages
|
||||||
|
$additional_packages = array_map(
|
||||||
|
function($addon_cart_item) {
|
||||||
|
$additional_package = wc_get_product($addon_cart_item['product_id']);
|
||||||
|
return array(
|
||||||
|
'package_id' => $additional_package->get_id(),
|
||||||
|
'package_name' => $additional_package->get_title(),
|
||||||
|
'prices' => array(
|
||||||
|
'fixed_extra' => $addon_cart_item['_wiaas_payment']['fixed_extra'],
|
||||||
|
'recurrent_extra' => $addon_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||||
|
'services_extra' => $addon_cart_item['_wiaas_payment']['services_extra'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
wiaas_get_cart_item_addons($item));
|
||||||
|
|
||||||
|
|
||||||
|
// Collect package options
|
||||||
|
$package_options = array_map(
|
||||||
|
function($option_cart_item) {
|
||||||
|
$option_package = wc_get_product($option_cart_item['product_id']);
|
||||||
|
return array(
|
||||||
|
'package_id' => $option_package->get_id(),
|
||||||
|
'group_name' => $option_cart_item['_wiaas_option_group_name'],
|
||||||
|
'package_name' => $option_package->get_title(),
|
||||||
|
'prices' => array(
|
||||||
|
'fixed_extra' => $option_cart_item['_wiaas_payment']['fixed_extra'],
|
||||||
|
'recurrent_extra' => $option_cart_item['_wiaas_payment']['recurrent_extra'],
|
||||||
|
'services_extra' => $option_cart_item['_wiaas_payment']['services_extra'],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
wiaas_get_cart_item_options($item));
|
||||||
|
|
||||||
|
$package_items[] = array(
|
||||||
|
'package_id' => $item['product_id'],
|
||||||
|
'key' => $item['key'],
|
||||||
|
'package_name' => $package->get_title(),
|
||||||
|
'quantity' => $item['quantity'],
|
||||||
|
|
||||||
|
'commercial_lead_id' => 14,
|
||||||
|
'commercial_lead' => 'Coor Service Management',
|
||||||
|
'country' => Wiaas_Countries::get_package_country($package),
|
||||||
|
|
||||||
|
'are_additional_available' => true,
|
||||||
|
'additional_packages' => $additional_packages,
|
||||||
|
|
||||||
|
'are_options_available' => true,
|
||||||
|
'options' => $package_options,
|
||||||
|
|
||||||
|
'bids' => array(),
|
||||||
|
|
||||||
|
'payment_info' => array(
|
||||||
|
'id' => $item['_wiaas_payment']['id'],
|
||||||
|
'type' => $item['_wiaas_payment']['payment_type'],
|
||||||
|
'period_unit' => $item['_wiaas_payment']['period_unit'],
|
||||||
|
'fixed_extra' => $item['_wiaas_payment']['fixed_extra'],
|
||||||
|
'recurrent_extra' => $item['_wiaas_payment']['recurrent_extra'],
|
||||||
|
'services_extra' => $item['_wiaas_payment']['services_extra'],
|
||||||
|
),
|
||||||
|
|
||||||
|
'total_prices' => Wiaas_Cart::get_cart_item_total($item),
|
||||||
|
|
||||||
|
'status' => 'available',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $package_items;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//PRIVATE
|
//PRIVATE
|
||||||
|
|
||||||
/**
|
|
||||||
* Add selected package options to cart
|
|
||||||
* @param $cart_item_key
|
|
||||||
* @param $package_id
|
|
||||||
* @param $cart_item_data
|
|
||||||
*
|
|
||||||
* @throws Exception
|
|
||||||
*/
|
|
||||||
private static function _add_options_to_cart($cart_item_key, $package_id, $cart_item_data) {
|
|
||||||
$is_option_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_option_items']);
|
|
||||||
$has_selected_options = isset($_POST['options']) && is_array($_POST['options']);
|
|
||||||
|
|
||||||
if ($is_option_parent && $has_selected_options) {
|
|
||||||
|
|
||||||
$options_ids = $_POST['options'];
|
|
||||||
|
|
||||||
foreach ($options_ids as $option_id) {
|
|
||||||
$option_package = wc_get_product($option_id);
|
|
||||||
if (is_object($option_package)) {
|
|
||||||
|
|
||||||
$option_cart_item_key = WC()->cart->add_to_cart($option_id, 1, 0, array(), array(
|
|
||||||
'_wiaas_option_for' => $cart_item_key
|
|
||||||
));
|
|
||||||
|
|
||||||
if ($option_cart_item_key) {
|
|
||||||
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_option_items'][] = $option_cart_item_key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add selected package addons to cart
|
* Add selected package options and addons after parent standard package is added to cart
|
||||||
*
|
*
|
||||||
* @param $cart_item_key
|
* @param string $package_cart_item_key
|
||||||
* @param $package_id
|
* @param int $price_id
|
||||||
* @param $cart_item_data
|
* @param array $addons_ids
|
||||||
|
* @param array $options_ids
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception if any of the addons or options cannot be added to cart
|
||||||
*/
|
*/
|
||||||
private static function _add_addons_to_cart($cart_item_key, $package_id, $cart_item_data) {
|
private static function _add_additional_packages_to_cart($package_cart_item_key, $price_id, $addons_ids, $options_ids) {
|
||||||
|
|
||||||
$is_addon_parent = $_POST['package_id'] = $package_id && isset($cart_item_data['_wiaas_addon_items']);
|
$parent_item = WC()->cart->get_cart_item($package_cart_item_key);
|
||||||
$has_selected_addons = isset($_POST['addons']) && is_array($_POST['addons']);
|
|
||||||
|
|
||||||
if ($is_addon_parent && $has_selected_addons) {
|
$addon_items_keys = array();
|
||||||
$addons_ids = $_POST['addons'];
|
$option_items_keys = array();
|
||||||
|
|
||||||
foreach ($addons_ids as $addon_id) {
|
// Try adding package addons to cart
|
||||||
$addon_package = wc_get_product($addon_id);
|
foreach ($addons_ids as $addon_id) {
|
||||||
if (is_object($addon_package)) {
|
//Check if addon package exists
|
||||||
|
$addon_package = wc_get_product($addon_id);
|
||||||
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id, 1, 0, array(), array(
|
if (!$addon_package) {
|
||||||
'_wiaas_addon_for' => $cart_item_key
|
throw new Exception( __( 'Sorry, additional package does not exist.', 'wiaas' ) );
|
||||||
));
|
|
||||||
|
|
||||||
if ($addon_cart_item_key) {
|
|
||||||
WC()->cart->cart_contents[ $cart_item_key ]['_wiaas_addon_items'][] = $addon_cart_item_key;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Retrieve addon package price
|
||||||
|
$package_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $parent_item['data']);
|
||||||
|
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||||
|
|
||||||
|
// Initialize additional cart item data for wiaas addon packages
|
||||||
|
$wiaas_addon_cart_item_data = array(
|
||||||
|
'_wiaas_addon_for' => $package_cart_item_key,
|
||||||
|
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null
|
||||||
|
);
|
||||||
|
|
||||||
|
$addon_cart_item_key = WC()->cart->add_to_cart($addon_id,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
array(),
|
||||||
|
$wiaas_addon_cart_item_data
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$addon_cart_item_key) {
|
||||||
|
throw new Exception( __( 'Sorry, additional package could not be added to cart.', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$addon_items_keys[] = $addon_cart_item_key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try adding package options to cart
|
||||||
|
foreach ($options_ids as $option_id) {
|
||||||
|
//Check if option package exists
|
||||||
|
$option_package = wc_get_product($option_id);
|
||||||
|
if (!$option_package) {
|
||||||
|
throw new Exception( __( 'Sorry, option package does not exist.', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retrieve option package price
|
||||||
|
$package_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $parent_item['data']);
|
||||||
|
$selected_price_index = array_search($price_id, array_column($package_prices, 'id'));
|
||||||
|
|
||||||
|
// Retrieve option package group name
|
||||||
|
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($parent_item['data'], $option_package);
|
||||||
|
|
||||||
|
|
||||||
|
// Initialize additional cart item data for wiaas option packages
|
||||||
|
$wiaas_option_cart_item_data = array(
|
||||||
|
'_wiaas_option_for' => $package_cart_item_key,
|
||||||
|
'_wiaas_payment' => $package_prices[$selected_price_index] ? $package_prices[$selected_price_index] : null,
|
||||||
|
'_wiaas_option_group_name' => $option_group_name,
|
||||||
|
);
|
||||||
|
|
||||||
|
$option_cart_item_key = WC()->cart->add_to_cart($option_id,
|
||||||
|
1,
|
||||||
|
0,
|
||||||
|
array(),
|
||||||
|
$wiaas_option_cart_item_data
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!$option_cart_item_key) {
|
||||||
|
throw new Exception( __( 'Sorry, package option could not be added to cart.', 'wiaas' ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
$option_items_keys[] = $option_cart_item_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_addon_items'] = $addon_items_keys;
|
||||||
|
WC()->cart->cart_contents[ $package_cart_item_key ]['_wiaas_option_items'] = $option_items_keys;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
69
backend/app/plugins/wiaas/includes/class-wiaas-checkout.php
Normal file
69
backend/app/plugins/wiaas/includes/class-wiaas-checkout.php
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Checkout {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process the order checkout.
|
||||||
|
*
|
||||||
|
* @param array $data Posted data.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public static function process_checkout($data) {
|
||||||
|
try {
|
||||||
|
|
||||||
|
$customer = wp_get_current_user();
|
||||||
|
|
||||||
|
$order_id = WC()->checkout()->create_order(array());
|
||||||
|
$order = wc_get_order( $order_id );
|
||||||
|
|
||||||
|
// set order currency
|
||||||
|
$line_items = $order->get_items();
|
||||||
|
foreach ($line_items as $line_item) {
|
||||||
|
if (isset($line_item['wiaas_currency'])) {
|
||||||
|
$order->set_currency($line_item['wiaas_currency']);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$delivery_address = Wiaas_Customer::get_customer_profile_address($customer->ID, $data['delivery_address_id']);
|
||||||
|
$billing_address = Wiaas_Customer::get_customer_billing_address($customer->ID, $data['billing_address_id']);
|
||||||
|
|
||||||
|
if (isset($delivery_address)) {
|
||||||
|
$order->set_shipping_city($delivery_address['city']);
|
||||||
|
$order->set_shipping_country($delivery_address['country_name']);
|
||||||
|
$order->set_shipping_address_1($delivery_address['detailed_address']);
|
||||||
|
$order->set_shipping_postcode($delivery_address['zip_code']);
|
||||||
|
$order->set_shipping_first_name($delivery_address['first_name']);
|
||||||
|
$order->set_shipping_last_name($delivery_address['last_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($billing_address)) {
|
||||||
|
$order->set_billing_city($billing_address['city']);
|
||||||
|
$order->set_billing_country($billing_address['country_name']);
|
||||||
|
$order->set_billing_address_1($billing_address['detailed_address']);
|
||||||
|
$order->set_billing_postcode($billing_address['zip_code']);
|
||||||
|
$order->set_billing_first_name($billing_address['first_name']);
|
||||||
|
$order->set_billing_last_name($billing_address['last_name']);
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Order::set_order_vat($order_id, $data['vat']);
|
||||||
|
Wiaas_Order::set_order_company($order_id, $data['company_name']);
|
||||||
|
Wiaas_Order::set_order_reference($order_id, $data['reference']);
|
||||||
|
Wiaas_Order::set_order_tender($order_id, $data['tender']);
|
||||||
|
|
||||||
|
if (isset($data['project_id'])) {
|
||||||
|
Wiaas_Order_Project::set_project_for_order($order_id, $data['project_id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$order->payment_complete();
|
||||||
|
|
||||||
|
WC()->cart->empty_cart( true );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
|
||||||
|
} catch (Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,18 +17,21 @@ class Wiaas_Countries {
|
|||||||
*/
|
*/
|
||||||
private static $available_countries = array(
|
private static $available_countries = array(
|
||||||
'Sweden' => array(
|
'Sweden' => array(
|
||||||
|
'id' => 1,
|
||||||
'name' => 'Sweden',
|
'name' => 'Sweden',
|
||||||
'code' => 'se',
|
'code' => 'se',
|
||||||
'vat' => 9 ,
|
'vat' => 9 ,
|
||||||
'currency' => 'SEK'
|
'currency' => 'SEK'
|
||||||
),
|
),
|
||||||
'Denmark' => array(
|
'Denmark' => array(
|
||||||
|
'id' => 2,
|
||||||
'name' => 'Denmark',
|
'name' => 'Denmark',
|
||||||
'code' => 'dk',
|
'code' => 'dk',
|
||||||
'vat' => 9 ,
|
'vat' => 9 ,
|
||||||
'currency' => 'DKK'
|
'currency' => 'DKK'
|
||||||
),
|
),
|
||||||
'Finland' => array(
|
'Finland' => array(
|
||||||
|
'id' => 3,
|
||||||
'name' => 'Finland',
|
'name' => 'Finland',
|
||||||
'code' => 'fi',
|
'code' => 'fi',
|
||||||
'vat' => 9 ,
|
'vat' => 9 ,
|
||||||
@@ -41,6 +44,24 @@ class Wiaas_Countries {
|
|||||||
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
|
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_product_countries_taxonomy'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_list_of_countries(){
|
||||||
|
$result = [];
|
||||||
|
foreach(self::$available_countries as $country){
|
||||||
|
array_push($result, array(
|
||||||
|
'country_id' => $country['id'],
|
||||||
|
'country_name' => $country['name']
|
||||||
|
));
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_country_name_by_id($id){
|
||||||
|
foreach(self::$available_countries as $country){
|
||||||
|
if ($country['id'] == $id) return $country['name'];
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Registers product taxonomy for avaiable countries
|
* Registers product taxonomy for avaiable countries
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ class Wiaas_Order {
|
|||||||
private static $object_order_type = 'shop_order';
|
private static $object_order_type = 'shop_order';
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
|
||||||
|
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
||||||
|
|
||||||
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
add_action('woocommerce_new_order', array( __CLASS__, 'assign_order_to_organization' ));
|
||||||
|
|
||||||
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
add_filter('woocommerce_rest_check_permissions', array( __CLASS__, 'check_order_access'), 10, 4);
|
||||||
@@ -115,6 +118,8 @@ class Wiaas_Order {
|
|||||||
$data = self::_append_order_process($data, $order, $request);
|
$data = self::_append_order_process($data, $order, $request);
|
||||||
|
|
||||||
$data = self::_append_order_comments($data, $order, $request);
|
$data = self::_append_order_comments($data, $order, $request);
|
||||||
|
|
||||||
|
$data = self::_append_documents($data, $order, $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
$response->set_data($data);
|
$response->set_data($data);
|
||||||
@@ -122,6 +127,38 @@ class Wiaas_Order {
|
|||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function set_order_vat($order_id, $vat_code) {
|
||||||
|
add_post_meta($order_id, '_wiaas_vat_code', $vat_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_order_vat($order_id) {
|
||||||
|
return get_post_meta($order_id, '_wiaas_vat_code', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function set_order_company($order_id, $company_name) {
|
||||||
|
add_post_meta($order_id, '_wiaas_company_name', $company_name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_order_company($order_id) {
|
||||||
|
return get_post_meta($order_id, '_wiaas_company_name', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function set_order_reference($order_id, $reference) {
|
||||||
|
add_post_meta($order_id, '_wiaas_reference', $reference);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_order_reference($order_id) {
|
||||||
|
return get_post_meta($order_id, '_wiaas_reference', true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function set_order_tender($order_id, $tender) {
|
||||||
|
add_post_meta($order_id, '_wiaas_tender', $tender);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_order_tender($order_id) {
|
||||||
|
return get_post_meta($order_id, '_wiaas_tender', true);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PRIVATE
|
* PRIVATE
|
||||||
*/
|
*/
|
||||||
@@ -133,7 +170,12 @@ class Wiaas_Order {
|
|||||||
* @param $request
|
* @param $request
|
||||||
*/
|
*/
|
||||||
private static function _append_wiaas_order_details($data, $order, $request) {
|
private static function _append_wiaas_order_details($data, $order, $request) {
|
||||||
$data['reference'] = get_post_meta($order->get_id(), '_wiaas_reference', true);
|
$data['reference'] = self::get_order_reference($order->get_id());
|
||||||
|
$data['tender'] = self::get_order_tender($order->get_id());
|
||||||
|
$data['vat'] = self::get_order_vat($order->get_id());
|
||||||
|
$data['company_name'] = self::get_order_company($order->get_id());
|
||||||
|
|
||||||
|
$data['project_name'] = Wiaas_Order_Project::get_project_name_for_order($order->get_id());
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
@@ -311,6 +353,45 @@ class Wiaas_Order {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Append downloadable documents from order products if single order is requested
|
||||||
|
* @param $data
|
||||||
|
* @param $order
|
||||||
|
* @param $request
|
||||||
|
*/
|
||||||
|
private static function _append_documents($data, $order, $request) {
|
||||||
|
if (isset($request['id'])) {
|
||||||
|
$data['documents'] = array();
|
||||||
|
|
||||||
|
//This requires _append_packages to be called before this method
|
||||||
|
|
||||||
|
foreach($data['line_items'] as $item){
|
||||||
|
$product = wc_get_product($item['product_id']);
|
||||||
|
|
||||||
|
$product_documents = array();
|
||||||
|
foreach ( $product->get_downloads() as $file_id => $file ) {
|
||||||
|
$product_documents[] = array(
|
||||||
|
'id' => $file_id,
|
||||||
|
'name' => $file->get_name(),
|
||||||
|
'extension' => $file->get_file_extension()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count($product_documents)){
|
||||||
|
$data['documents'][] = array(
|
||||||
|
'package' => array(
|
||||||
|
'id' => $product->get_id(),
|
||||||
|
'name' => $product->get_name()
|
||||||
|
),
|
||||||
|
'documents' => $product_documents
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -59,7 +59,7 @@ class Wiaas_Pricing {
|
|||||||
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
$total_item_cost = self::get_product_total_cost($product) * $bundled_item->get_quantity();
|
||||||
|
|
||||||
if (Wiaas_Product_Category::is_installation($product)) {
|
if (Wiaas_Product_Category::is_installation($product)) {
|
||||||
$total_cost_per_category[$product_cat] += $total_cost_per_category[$product_cat] < $total_item_cost ?
|
$total_cost_per_category[$product_cat] = $total_cost_per_category[$product_cat] < $total_item_cost ?
|
||||||
$total_item_cost :
|
$total_item_cost :
|
||||||
$total_cost_per_category[$product_cat];
|
$total_cost_per_category[$product_cat];
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -8,8 +8,14 @@ defined( 'ABSPATH' ) || exit;
|
|||||||
class Wiaas_User {
|
class Wiaas_User {
|
||||||
|
|
||||||
public static function init() {
|
public static function init() {
|
||||||
|
include_once dirname( __FILE__ ) . '/class-wiaas-countries.php';
|
||||||
|
include_once dirname( __FILE__ ) . '/user/class-wiaas-customer.php';
|
||||||
|
|
||||||
add_action('init', array(__CLASS__, 'load_user_organization'));
|
add_action('init', array(__CLASS__, 'load_user_organization'));
|
||||||
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
|
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
|
||||||
|
|
||||||
|
add_filter('woocommerce_rest_prepare_customer', array(__CLASS__, 'transform_rest_customer'), 10, 3);
|
||||||
|
add_filter('jwt_auth_token_before_dispatch', array(__CLASS__, 'transform_jwt_token_response'), 10, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function load_user_organization() {
|
public static function load_user_organization() {
|
||||||
@@ -24,6 +30,47 @@ class Wiaas_User {
|
|||||||
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
|
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
|
||||||
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
|
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply wiaas custom transformation on retrieved JSON customer object
|
||||||
|
*
|
||||||
|
* @param $response
|
||||||
|
* @param $order
|
||||||
|
* @param $request
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function transform_rest_customer($response, $order, $request) {
|
||||||
|
$data = $response->get_data();
|
||||||
|
$user_id = $data['id'];
|
||||||
|
$customer_info = Wiaas_Customer::get_customer_info($user_id);
|
||||||
|
|
||||||
|
return new WP_REST_Response($customer_info);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Apply wiaas custom transformation on JWT token response
|
||||||
|
*
|
||||||
|
* @param $data
|
||||||
|
* @param $user
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public static function transform_jwt_token_response($data, $user) {
|
||||||
|
return new WP_REST_Response(array(
|
||||||
|
'token' => $data['token'],
|
||||||
|
'userInfo' => array(
|
||||||
|
'wiaas_id_user' => $user->ID,
|
||||||
|
'wiaas_is_company_admin' => 1, //TODO: don't hardcode this
|
||||||
|
'wiaas_user_full_name' => $user->first_name . ' ' . $user->last_name,
|
||||||
|
'wiaas_user_type' => $user->roles,
|
||||||
|
'wiaas_username' => $user->data->user_login
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_User::init();
|
Wiaas_User::init();
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Order_Project {
|
||||||
|
|
||||||
|
public static function init() {
|
||||||
|
add_action('woocommerce_after_register_taxonomy', array(__CLASS__, 'register_order_project_taxonomy'));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Register order project taxonomy
|
||||||
|
*/
|
||||||
|
public static function register_order_project_taxonomy() {
|
||||||
|
$labels = array(
|
||||||
|
'name' => _x( 'Project', 'taxonomy general name', 'wiaas' ),
|
||||||
|
'singular_name' => _x( 'Project', 'taxonomy singular name', 'wiaas' ),
|
||||||
|
'search_items' => __( 'Search Order Projects', 'wiaas' ),
|
||||||
|
'all_items' => __( 'All Order Projects', 'wiaas' ),
|
||||||
|
'parent_item' => __( 'Parent Order Project', 'wiaas' ),
|
||||||
|
'parent_item_colon' => __( 'Parent Order Project:', 'wiaas' ),
|
||||||
|
'edit_item' => __( 'Edit Order Project', 'wiaas' ),
|
||||||
|
'update_item' => __( 'Update Order Project', 'wiaas' ),
|
||||||
|
'add_new_item' => __( 'Add New Order Project', 'wiaas' ),
|
||||||
|
'new_item_name' => __( 'New Order Project Name', 'wiaas' ),
|
||||||
|
'menu_name' => __( 'Order Project', 'wiaas' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
$args = array(
|
||||||
|
'hierarchical' => false,
|
||||||
|
'labels' => $labels,
|
||||||
|
'show_ui' => true,
|
||||||
|
'show_admin_column' => true,
|
||||||
|
'query_var' => true,
|
||||||
|
'rewrite' => array( 'slug' => 'shop_order_project' ),
|
||||||
|
'update_count_callback' => array(__CLASS__, 'update_count_callback')
|
||||||
|
);
|
||||||
|
|
||||||
|
register_taxonomy( 'shop_order_project', array( 'shop_order' ), $args );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback to handle counting of number of orders inside every project
|
||||||
|
* This does not work out of the box for orders since they are marked as private post type
|
||||||
|
*
|
||||||
|
* @param array $project_ids
|
||||||
|
*/
|
||||||
|
public static function update_count_callback($project_ids) {
|
||||||
|
// Update counts
|
||||||
|
_update_generic_term_count( $project_ids, get_taxonomy('shop_order_project') );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves available order projects
|
||||||
|
* @return array List of available order projects
|
||||||
|
*/
|
||||||
|
public static function get_available_order_projects() {
|
||||||
|
$all_terms = get_terms(array(
|
||||||
|
'taxonomy' => 'shop_order_project',
|
||||||
|
'hide_empty' => false
|
||||||
|
));
|
||||||
|
|
||||||
|
if (is_wp_error($all_terms)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($all_terms as $term) {
|
||||||
|
if (self::is_order_project_available($term->term_id)) {
|
||||||
|
$available_terms[] = array(
|
||||||
|
'id' => $term->term_id,
|
||||||
|
'name' => $term->name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $available_terms;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves order project name
|
||||||
|
* @param int $order_id
|
||||||
|
*
|
||||||
|
* @return string|null Project name if order is assigned to project, null otherwise
|
||||||
|
*/
|
||||||
|
public static function get_project_name_for_order($order_id) {
|
||||||
|
$terms = wp_get_object_terms($order_id, 'shop_order_project');
|
||||||
|
return isset($terms[0]) ? $terms[0]->name : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Assigns giver order to given project
|
||||||
|
* @param int $order_id
|
||||||
|
* @param int $project_id
|
||||||
|
*/
|
||||||
|
public static function set_project_for_order($order_id, $project_id) {
|
||||||
|
wp_set_object_terms($order_id, $project_id, 'shop_order_project', false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds new order project
|
||||||
|
* @param string $name Order Project name
|
||||||
|
* @param bool $is_available Flag indicating is order project available
|
||||||
|
*
|
||||||
|
* @return bool True on success, False on failure.
|
||||||
|
*/
|
||||||
|
public static function add_order_project($name, $is_available = true) {
|
||||||
|
$result = wp_create_term($name, 'shop_order_project');
|
||||||
|
|
||||||
|
if (is_wp_error($result)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// save is term available
|
||||||
|
$id = is_numeric($result) ? $result : $result['term_id'];
|
||||||
|
self::_save_available_field($id, $is_available);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int|WP_Term $project Order project or order project id
|
||||||
|
* @param bool $is_available
|
||||||
|
*/
|
||||||
|
public static function set_is_order_project_available($project, $is_available) {
|
||||||
|
$project_id = is_numeric($project) ? $project : $project->term_id;
|
||||||
|
self::_save_available_field($project_id, $is_available);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves if order project is available
|
||||||
|
* @param int|WP_Term $project Order project objects or id of order project
|
||||||
|
*
|
||||||
|
* @return bool TRUE if available, FALSE if not available
|
||||||
|
*/
|
||||||
|
public static function is_order_project_available($project) {
|
||||||
|
$project_id = is_numeric($project) ? $project : $project->term_id;
|
||||||
|
return get_term_meta($project_id, '_wiaas_is_available', true) === 'yes';
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRIVATE
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param int $id Order project id
|
||||||
|
* @param bool $is_available
|
||||||
|
*/
|
||||||
|
private static function _save_available_field($id, $is_available) {
|
||||||
|
update_term_meta($id, '_wiaas_is_available', $is_available ? 'yes' : 'no');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Wiaas_Order_Project::init();
|
||||||
@@ -101,15 +101,20 @@ class Wiaas_Package_Pricing {
|
|||||||
return self::_get_package_pricing_commision($package);
|
return self::_get_package_pricing_commision($package);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function get_package_minimum_cost_margin($package){
|
||||||
|
return self::_get_package_minimum_cost_margin($package);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Persist payment prices configuration for package
|
* Persist payment prices configuration for package
|
||||||
* @param $package
|
* @param $package
|
||||||
* @param $pricing_rules
|
* @param $pricing_rules
|
||||||
*/
|
*/
|
||||||
public static function set_package_prices($package, $pricing_rules, $commision) {
|
public static function set_package_prices($package, $pricing_rules, $commision, $minimum_cost_margin) {
|
||||||
if ( isset( $pricing_rules ) ) {
|
if ( isset( $pricing_rules ) ) {
|
||||||
$package->update_meta_data( '_wiaas_pricing_rules', $pricing_rules );
|
$package->update_meta_data( '_wiaas_pricing_rules', $pricing_rules );
|
||||||
$package->update_meta_data('_package_pricing_commision', $commision, true);
|
$package->update_meta_data('_package_pricing_commision', $commision, true);
|
||||||
|
$package->update_meta_data('_package_minimum_cost_margin', $minimum_cost_margin, true);
|
||||||
} else {
|
} else {
|
||||||
$package->delete_meta_data( '_wiaas_pricing_rules' );
|
$package->delete_meta_data( '_wiaas_pricing_rules' );
|
||||||
}
|
}
|
||||||
@@ -154,6 +159,16 @@ class Wiaas_Package_Pricing {
|
|||||||
|
|
||||||
return (float) $commision;
|
return (float) $commision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static function _get_package_minimum_cost_margin($package) {
|
||||||
|
$minimum_cost_margin = $package->get_meta( '_package_minimum_cost_margin', true);
|
||||||
|
|
||||||
|
if (!isset($minimum_cost_margin) || $minimum_cost_margin === '') {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (float) $minimum_cost_margin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Wiaas_Package_Pricing::init();
|
Wiaas_Package_Pricing::init();
|
||||||
@@ -11,7 +11,7 @@ class Wiaas_Product_Pricing {
|
|||||||
|
|
||||||
add_filter('woocommerce_get_price_html', array(__CLASS__, 'get_product_price_html'), 10, 2);
|
add_filter('woocommerce_get_price_html', array(__CLASS__, 'get_product_price_html'), 10, 2);
|
||||||
|
|
||||||
add_filter('woocommerce_bundled_item_price', array(__CLASS__, 'get_bundled_product_fixed_price'), 10, 4);
|
add_filter('woocommerce_bundled_item_price', array(__CLASS__, 'get_product_fixed_price'), 10, 2);
|
||||||
|
|
||||||
add_filter('woocommerce_bundled_item_is_priced_individually', array(__CLASS__, 'is_bundled_product_price_fixed'), 10, 2);
|
add_filter('woocommerce_bundled_item_is_priced_individually', array(__CLASS__, 'is_bundled_product_price_fixed'), 10, 2);
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class Wiaas_Product_Pricing {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if bunded product has fixed price
|
* Checks if bundled product has fixed price
|
||||||
* @param $is_priced_individually
|
* @param $is_priced_individually
|
||||||
* @param $bundled_item
|
* @param $bundled_item
|
||||||
*
|
*
|
||||||
@@ -51,12 +51,10 @@ class Wiaas_Product_Pricing {
|
|||||||
* Retrives fixed price for bundled product
|
* Retrives fixed price for bundled product
|
||||||
* @param $price
|
* @param $price
|
||||||
* @param $product
|
* @param $product
|
||||||
* @param $discount
|
|
||||||
* @param $bundled_item
|
|
||||||
*
|
*
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function get_bundled_product_fixed_price($price, $product, $discount, $bundled_item) {
|
public static function get_product_fixed_price($price, $product) {
|
||||||
if (self::_get_is_product_price_recurring($product)) {
|
if (self::_get_is_product_price_recurring($product)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -108,6 +106,8 @@ class Wiaas_Product_Pricing {
|
|||||||
*/
|
*/
|
||||||
public static function set_product_price($product, $price, $is_recurring = false, $pay_period = 0) {
|
public static function set_product_price($product, $price, $is_recurring = false, $pay_period = 0) {
|
||||||
$product->set_price($price);
|
$product->set_price($price);
|
||||||
|
$product->set_regular_price($price);
|
||||||
|
|
||||||
self::_set_is_product_price_recurring($product, $is_recurring);
|
self::_set_is_product_price_recurring($product, $is_recurring);
|
||||||
self::_set_product_price_pay_period($product, $pay_period);
|
self::_set_product_price_pay_period($product, $pay_period);
|
||||||
|
|
||||||
|
|||||||
252
backend/app/plugins/wiaas/includes/user/class-wiaas-customer.php
Normal file
252
backend/app/plugins/wiaas/includes/user/class-wiaas-customer.php
Normal file
@@ -0,0 +1,252 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
defined( 'ABSPATH' ) || exit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_Customer
|
||||||
|
*/
|
||||||
|
class Wiaas_Customer {
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
include_once dirname( __FILE__ ) . '/../class-wiaas-countries.php';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_info($customer_id){
|
||||||
|
$user = get_userdata($customer_id);
|
||||||
|
$result = array(
|
||||||
|
'id' => $customer_id,
|
||||||
|
'company_id' => self::get_customer_company_id($customer_id),
|
||||||
|
'is_company_admin' => self::get_customer_company_admin_status($customer_id),
|
||||||
|
'mail' => $user->user_email,
|
||||||
|
'name' => $user->first_name . ' ' . $user->last_name,
|
||||||
|
'phone' => self::get_customer_phone_number($customer_id),
|
||||||
|
'company_name' => self::get_customer_company_name($customer_id),
|
||||||
|
'vat_code' => self::get_customer_vat_code($customer_id),
|
||||||
|
'billing_addresses' => self::get_customer_billing_addresses($customer_id),
|
||||||
|
'profile_addresses' => self::get_customer_profile_addresses($customer_id),
|
||||||
|
'user_type' => $user->roles
|
||||||
|
);
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_profile_addresses($customer_id){
|
||||||
|
return get_user_meta($customer_id, 'profile_addresses', true) ?: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get customer profile address by id
|
||||||
|
*
|
||||||
|
* @param int $customer_id
|
||||||
|
* @param int $address_id
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public static function get_customer_profile_address($customer_id, $address_id) {
|
||||||
|
$profile_addresses = self::get_customer_profile_addresses($customer_id);
|
||||||
|
$index = array_search($address_id, array_column($profile_addresses, 'id'));
|
||||||
|
if (is_numeric($index)) {
|
||||||
|
return $profile_addresses[$index];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_billing_addresses($customer_id){
|
||||||
|
return get_user_meta($customer_id, 'billing_addresses', true) ?: [];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get customer billing address by id
|
||||||
|
*
|
||||||
|
* @param int $customer_id
|
||||||
|
* @param int $address_id
|
||||||
|
*
|
||||||
|
* @return array|null
|
||||||
|
*/
|
||||||
|
public static function get_customer_billing_address($customer_id, $address_id) {
|
||||||
|
$billing_addresses = self::get_customer_billing_addresses($customer_id);
|
||||||
|
$index = array_search($address_id, array_column($billing_addresses, 'id'));
|
||||||
|
if (is_numeric($index)) {
|
||||||
|
return $billing_addresses[$index];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_vat_code($customer_id){
|
||||||
|
return get_user_meta($customer_id, 'vat_code', true) ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_company_name($customer_id){
|
||||||
|
return get_user_meta($customer_id, 'company_name', true) ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_company_id($customer_id){
|
||||||
|
return 0; //TODO: don't hardocde this
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_company_admin_status($customer_id){
|
||||||
|
return 1; //TODO: don't hardcode this
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get_customer_phone_number($customer_id){
|
||||||
|
return get_user_meta($customer_id, 'phone', true) ?: '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_profile_info($customer_id, $first_name, $last_name, $phone){
|
||||||
|
$user = array(
|
||||||
|
'ID' => $customer_id,
|
||||||
|
'first_name' => $first_name,
|
||||||
|
'last_name' => $last_name
|
||||||
|
);
|
||||||
|
|
||||||
|
if (is_wp_error(wp_update_user($user))){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
update_user_meta( $customer_id, 'phone', $phone);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_company_info($customer_id, $company_name, $vat_code){
|
||||||
|
$result1 = update_user_meta( $customer_id, 'company_name', $company_name);
|
||||||
|
$result2 = update_user_meta( $customer_id, 'vat_code', $vat_code );
|
||||||
|
return $result1 || $result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_billing_addresses($customer_id, $new_address){
|
||||||
|
if (!self::validate_address($new_address)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$billing_addresses = self::get_customer_billing_addresses($customer_id);
|
||||||
|
|
||||||
|
if ($new_address->id){
|
||||||
|
$updated = array(
|
||||||
|
'id' => $new_address->id,
|
||||||
|
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
|
||||||
|
'delivery_mail' => $new_address->delivery_mail,
|
||||||
|
'id_country_selected' => $new_address->id_country_selected,
|
||||||
|
'city' => $new_address->city,
|
||||||
|
'detailed_address' => $new_address->detailed_address,
|
||||||
|
'zip_code' => $new_address->zip_code,
|
||||||
|
'first_name' => $new_address->first_name,
|
||||||
|
'last_name' => $new_address->last_name,
|
||||||
|
'invoice_mail' => $new_address->invoice_mail
|
||||||
|
);
|
||||||
|
foreach($billing_addresses as $key => $address){
|
||||||
|
if ($address['id'] === $new_address->id){
|
||||||
|
$billing_addresses[$key] = $updated;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$new_billing_address = array(
|
||||||
|
'id' => time(),
|
||||||
|
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
|
||||||
|
'delivery_mail' => $new_address->delivery_mail,
|
||||||
|
'id_country_selected' => $new_address->id_country_selected,
|
||||||
|
'city' => $new_address->city,
|
||||||
|
'detailed_address' => $new_address->detailed_address,
|
||||||
|
'zip_code' => $new_address->zip_code,
|
||||||
|
'first_name' => $new_address->first_name,
|
||||||
|
'last_name' => $new_address->last_name,
|
||||||
|
'invoice_mail' => $new_address->invoice_mail
|
||||||
|
);
|
||||||
|
|
||||||
|
array_push($billing_addresses, $new_billing_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
return update_user_meta( $customer_id, 'billing_addresses', $billing_addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update_customer_profile_addresses($customer_id, $new_address){
|
||||||
|
if (!self::validate_address($new_address)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$profile_addresses = self::get_customer_profile_addresses($customer_id);
|
||||||
|
|
||||||
|
if ($new_address->id){
|
||||||
|
$updated = array(
|
||||||
|
'id' => $new_address->id,
|
||||||
|
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
|
||||||
|
'delivery_mail' => $new_address->delivery_mail,
|
||||||
|
'id_country_selected' => $new_address->id_country_selected,
|
||||||
|
'city' => $new_address->city,
|
||||||
|
'detailed_address' => $new_address->detailed_address,
|
||||||
|
'zip_code' => $new_address->zip_code,
|
||||||
|
'first_name' => $new_address->first_name,
|
||||||
|
'last_name' => $new_address->last_name,
|
||||||
|
'invoice_mail' => $new_address->invoice_mail
|
||||||
|
);
|
||||||
|
foreach($profile_addresses as $key => $address){
|
||||||
|
if ($address['id'] === $new_address->id){
|
||||||
|
$profile_addresses[$key] = $updated;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$new_delivery_address = array(
|
||||||
|
'id' => time(),
|
||||||
|
'country_name' => Wiaas_Countries::get_country_name_by_id($new_address->id_country_selected),
|
||||||
|
'delivery_mail' => $new_address->delivery_mail,
|
||||||
|
'id_country_selected' => $new_address->id_country_selected,
|
||||||
|
'city' => $new_address->city,
|
||||||
|
'detailed_address' => $new_address->detailed_address,
|
||||||
|
'zip_code' => $new_address->zip_code,
|
||||||
|
'first_name' => $new_address->first_name,
|
||||||
|
'last_name' => $new_address->last_name,
|
||||||
|
'invoice_mail' => $new_address->invoice_mail
|
||||||
|
);
|
||||||
|
|
||||||
|
array_push($profile_addresses, $new_delivery_address);
|
||||||
|
}
|
||||||
|
|
||||||
|
return update_user_meta( $customer_id, 'profile_addresses', $profile_addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete_customer_profile_address($customer_id, $address_id){
|
||||||
|
$profile_addresses = self::get_customer_profile_addresses($customer_id);
|
||||||
|
$counter = 0;
|
||||||
|
foreach($profile_addresses as $key => $address){
|
||||||
|
if ($address['id'] == $address_id){
|
||||||
|
array_splice($profile_addresses, $counter, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
return update_user_meta( $customer_id, 'profile_addresses', $profile_addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function delete_customer_billing_address($customer_id, $address_id){
|
||||||
|
$billing_addresses = self::get_customer_billing_addresses($customer_id);
|
||||||
|
$counter = 0;
|
||||||
|
foreach($billing_addresses as $key => $address){
|
||||||
|
if ($address['id'] == $address_id){
|
||||||
|
array_splice($billing_addresses, $counter, 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
$counter++;
|
||||||
|
}
|
||||||
|
return update_user_meta( $customer_id, 'billing_addresses', $billing_addresses);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if address is valid
|
||||||
|
*
|
||||||
|
* @param $address
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
private static function validate_address($address){
|
||||||
|
if (empty($address->city)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (empty($address->detailed_address)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return is_numeric($address->zip_code);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -20,17 +20,37 @@ require_once $_tests_dir . '/includes/functions.php';
|
|||||||
#load setup
|
#load setup
|
||||||
tests_add_filter( 'muplugins_loaded', 'load_wiaas_test_setup' );
|
tests_add_filter( 'muplugins_loaded', 'load_wiaas_test_setup' );
|
||||||
|
|
||||||
|
tests_add_filter( 'pre_option_active_plugins', 'load_active_plugins_list');
|
||||||
|
|
||||||
# Start up the WP testing environment.
|
# Start up the WP testing environment.
|
||||||
require $_tests_dir . '/includes/bootstrap.php';
|
require $_tests_dir . '/includes/bootstrap.php';
|
||||||
|
|
||||||
# Require Wiaas Unit Test case class
|
# 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-unit-test-case.php';
|
||||||
|
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/tests/wiaas-api-unit-test-case.php';
|
||||||
|
|
||||||
|
function load_active_plugins_list() {
|
||||||
|
return array(
|
||||||
|
'woocommerce/woocommerce.php',
|
||||||
|
'woocommerce-product-bundles/woocommerce-product-bundles.php',
|
||||||
|
'woocommerce-jetpack/woocommerce-jetpack.php',
|
||||||
|
'jwt-authentication-for-wp-rest-api/jwt-auth.php',
|
||||||
|
'gravityforms/gravityforms.php',
|
||||||
|
'gravityflow/gravityflow.php',
|
||||||
|
'capability-manager-enhanced/capsman-enhanced.php',
|
||||||
|
'groups/groups.php',
|
||||||
|
'wp-user-groups/wp-user-groups.php',
|
||||||
|
'wiaas/wiaas.php'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function load_wiaas_test_setup() {
|
function load_wiaas_test_setup() {
|
||||||
|
|
||||||
# Activate plugins needed for testing
|
# Activate plugins needed for testing
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/woocommerce/woocommerce.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/woocommerce/woocommerce.php';
|
||||||
|
|
||||||
|
require_once '/tmp/wiaas-backend-test/app/plugins/woocommerce-product-bundles/woocommerce-product-bundles.php';
|
||||||
|
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/gravityforms/gravityforms.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/gravityforms/gravityforms.php';
|
||||||
|
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/gravityflow/gravityflow.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/gravityflow/gravityflow.php';
|
||||||
@@ -42,6 +62,7 @@ function load_wiaas_test_setup() {
|
|||||||
|
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/wiaas.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/wiaas.php';
|
||||||
|
|
||||||
|
|
||||||
# Require classes needed for db updates
|
# Require classes needed for db updates
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/class-wiaas-db-update.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/class-wiaas-db-update.php';
|
||||||
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php';
|
require_once '/tmp/wiaas-backend-test/app/plugins/wiaas/includes/db-updates/wiaas-db-update-functions.php';
|
||||||
|
|||||||
@@ -0,0 +1,81 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Order_Project_API_Test extends Wiaas_API_Unit_Test_Case {
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Projects_API::get_order_projects()
|
||||||
|
*/
|
||||||
|
function test_get_order_projects_as_guest() {
|
||||||
|
$this->check_endpoint_forbidden_for_guest(
|
||||||
|
new WP_REST_Request( 'GET', '/wiaas/order-projects')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Projects_API::get_order_projects()
|
||||||
|
*/
|
||||||
|
function test_get_order_projects_as_customer() {
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Available 1', true);
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Available 2', true);
|
||||||
|
|
||||||
|
$customer_id = $this->create_new_customer();
|
||||||
|
wp_set_current_user($customer_id);
|
||||||
|
|
||||||
|
$data = $this->dispatch_endpoint_request(
|
||||||
|
new WP_REST_Request( 'GET', '/wiaas/order-projects')
|
||||||
|
);
|
||||||
|
$this->assertNotNull($data);
|
||||||
|
$this->assertTrue(is_array($data));
|
||||||
|
|
||||||
|
$this->assertCount(2, $data);
|
||||||
|
foreach ($data as $project) {
|
||||||
|
$this->assertArrayHasKey('id', $project);
|
||||||
|
$this->assertArrayHasKey('name', $project);
|
||||||
|
|
||||||
|
$this->assertContains($project['name'], array(
|
||||||
|
'Test Available 1',
|
||||||
|
'Test Available 2',
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Projects_API::create_order_project()
|
||||||
|
*/
|
||||||
|
function test_create_order_project_as_guest() {
|
||||||
|
$request = new WP_REST_Request( 'POST', '/wiaas/order-projects');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'name' => 'Test'
|
||||||
|
));
|
||||||
|
$this->check_endpoint_forbidden_for_guest($request);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Projects_API::create_order_project()
|
||||||
|
*/
|
||||||
|
function test_create_valid_order_project_as_customer() {
|
||||||
|
$customer_id = $this->create_new_customer();
|
||||||
|
wp_set_current_user($customer_id);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'POST', '/wiaas/order-projects');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'name' => 'Test Project'
|
||||||
|
));
|
||||||
|
$data = $this->dispatch_endpoint_request($request);
|
||||||
|
|
||||||
|
$this->assertNotNull($data);
|
||||||
|
$this->assertTrue(is_array($data));
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
$this->assertNotEmpty($data['messages']);
|
||||||
|
|
||||||
|
$message = $data['messages'][0];
|
||||||
|
$this->assertArrayHasKey('code', $message);
|
||||||
|
$this->assertEquals('success', $message['code']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,597 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Wiaas_Customer_Test
|
||||||
|
*
|
||||||
|
* @package Wiaas
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Wiass_REST_Customer_Api_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
protected $server;
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
/** @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' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_profile_addresses
|
||||||
|
*/
|
||||||
|
function test_update_customer_profile_addresses_as_guest() {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/0/profile-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'profile_address' => $dummy_address
|
||||||
|
));
|
||||||
|
$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_Customer_API::update_customer_profile_addresses
|
||||||
|
*/
|
||||||
|
function test_add_customer_profile_addresses_with_valid_address() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/profile-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'profile_address' => json_encode($dummy_address)
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('profile_addresses', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['profile_addresses'][0]['city'], $dummy_address['city']);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'PROFILE_ADDRESS_UPDATED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_profile_addresses
|
||||||
|
*/
|
||||||
|
function test_add_customer_profile_addresses_with_invalid_address() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
$dummy_address['zip_code'] = 'this is not a zip code';
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/profile-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'profile_address' => json_encode($dummy_address)
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('profile_addresses', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['profile_addresses'][0], NULL);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'PROFILE_ADDRESS_NOT_CHANGED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_billing_addresses
|
||||||
|
*/
|
||||||
|
function test_update_customer_billing_addresses_as_guest() {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/0/billing-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'billing_address' => $dummy_address
|
||||||
|
));
|
||||||
|
$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_Customer_API::update_customer_billing_addresses
|
||||||
|
*/
|
||||||
|
function test_add_customer_billing_addresses_with_valid_address() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/billing-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'billing_address' => json_encode($dummy_address)
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('billing_addresses', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['billing_addresses'][0]['city'], $dummy_address['city']);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'BILLING_ADDRESS_UPDATED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_billing_addresses
|
||||||
|
*/
|
||||||
|
function test_add_customer_billing_addresses_with_invalid_address() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
$dummy_address['zip_code'] = 'this is not a zip code';
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/billing-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'billing_address' => json_encode($dummy_address)
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('billing_addresses', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['billing_addresses'][0], NULL);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'BILLING_ADDRESS_NOT_CHANGED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::delete_customer_billing_addresses
|
||||||
|
*/
|
||||||
|
function test_delete_customer_billing_addresses_as_guest() {
|
||||||
|
$address_id = self::insert_dummy_billing_address();
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'DELETE', '/wiaas/customer/1/billing-addresses/' . $address_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(), 401);
|
||||||
|
|
||||||
|
$error_data = $response->as_error();
|
||||||
|
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::delete_customer_billing_addresses
|
||||||
|
*/
|
||||||
|
function test_delete_customer_billing_addresses() {
|
||||||
|
$address_id = self::insert_dummy_billing_address();
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'DELETE', '/wiaas/customer/1/billing-addresses/' . $address_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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('billing_addresses', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['billing_addresses'][0], NULL);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'ADDRESS_REMOVED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::delete_customer_profile_addresses
|
||||||
|
*/
|
||||||
|
function test_delete_customer_delivery_addresses_as_guest() {
|
||||||
|
$address_id = self::insert_dummy_profile_address();
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'DELETE', '/wiaas/customer/1/profile-addresses/' . $address_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(), 401);
|
||||||
|
|
||||||
|
$error_data = $response->as_error();
|
||||||
|
$this->assertEquals($error_data->get_error_message(), 'Sorry, you are not allowed to do that.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::delete_customer_profile_addresses
|
||||||
|
*/
|
||||||
|
function test_delete_customer_profile_addresses() {
|
||||||
|
$address_id = self::insert_dummy_profile_address();
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'DELETE', '/wiaas/customer/1/profile-addresses/' . $address_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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('profile_addresses', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['profile_addresses'][0], NULL);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'ADDRESS_REMOVED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_personal_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_personal_info_as_guest() {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/personal-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'first_name' => 'Trunks',
|
||||||
|
'last_name' => 'Goten',
|
||||||
|
'phone' => 11111
|
||||||
|
));
|
||||||
|
$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_Customer_API::update_customer_personal_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_personal_info_with_empty_phone() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/personal-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'first_name' => 'Trunks',
|
||||||
|
'last_name' => 'Goten',
|
||||||
|
'phone' => ''
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('phone', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['phone'], '');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'ADD_PHONE_NUMBER');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_personal_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_personal_info_with_empty_name() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/personal-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'first_name' => '',
|
||||||
|
'last_name' => '',
|
||||||
|
'phone' => '23232'
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('phone', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['phone'], '');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'ADD_NAME');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_personal_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_personal_info() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/personal-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'first_name' => 'Trunks',
|
||||||
|
'last_name' => 'Goten',
|
||||||
|
'phone' => '3434'
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('phone', $profile_info);
|
||||||
|
$this->assertArrayHasKey('name', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['phone'], '3434');
|
||||||
|
$this->assertEquals($profile_info['name'], 'Trunks Goten');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'PROFILE_UPDATED');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_company_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_company_info_as_guest() {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/company-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'company_name' => 'Saburly',
|
||||||
|
'vat_code' => '12345'
|
||||||
|
));
|
||||||
|
$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_Customer_API::update_customer_company_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_company_info_with_empty_company_name() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/company-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'company_name' => '',
|
||||||
|
'vat_code' => '12345'
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('company_name', $profile_info);
|
||||||
|
$this->assertArrayHasKey('vat_code', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['company_name'], '');
|
||||||
|
$this->assertEquals($profile_info['vat_code'], '');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'ADD_COMPANY_NAME');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_company_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_company_info_with_empty_vat() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/company-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'company_name' => 'Saburly',
|
||||||
|
'vat_code' => ''
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('company_name', $profile_info);
|
||||||
|
$this->assertArrayHasKey('vat_code', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['company_name'], '');
|
||||||
|
$this->assertEquals($profile_info['vat_code'], '');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'ADD_VAT');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_Customer_API::update_customer_company_info
|
||||||
|
*/
|
||||||
|
function test_update_customer_company_info() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/company-info');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'company_name' => 'Saburly',
|
||||||
|
'vat_code' => '123'
|
||||||
|
));
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('data', $data);
|
||||||
|
$this->assertArrayHasKey('messages', $data);
|
||||||
|
|
||||||
|
$profile_info = $data['data'];
|
||||||
|
$messages = $data['messages'][0];
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('company_name', $profile_info);
|
||||||
|
$this->assertArrayHasKey('vat_code', $profile_info);
|
||||||
|
$this->assertEquals($profile_info['company_name'], 'Saburly');
|
||||||
|
$this->assertEquals($profile_info['vat_code'], '123');
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('message', $messages);
|
||||||
|
$this->assertEquals($messages['message'], 'COMPANY_UPDATED');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//Helper functions
|
||||||
|
private function create_dummy_address(){
|
||||||
|
return array(
|
||||||
|
'country_name' => 'Sweden',
|
||||||
|
'delivery_mail' => 'delivery@email.com',
|
||||||
|
'id_country_selected' => 1,
|
||||||
|
'city' => 'Stockholm',
|
||||||
|
'detailed_address' => 'Dummy Street 7',
|
||||||
|
'zip_code' => 124443,
|
||||||
|
'first_name' => 'Tester',
|
||||||
|
'last_name' => 'Retset',
|
||||||
|
'invoice_mail' => 'invoice@mail.com'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function insert_dummy_billing_address(){
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/billing-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'billing_address' => json_encode($dummy_address)
|
||||||
|
));
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
|
||||||
|
return $response->get_data()['data']['billing_addresses'][0]['id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
private function insert_dummy_profile_address(){
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$dummy_address = self::create_dummy_address();
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'PUT', '/wiaas/customer/1/profile-addresses');
|
||||||
|
$request->set_body_params(array(
|
||||||
|
'profile_address' => json_encode($dummy_address)
|
||||||
|
));
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
|
||||||
|
return $response->get_data()['data']['profile_addresses'][0]['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Wiaas_Delivery_Process_Step_Test
|
||||||
|
*
|
||||||
|
* @package Wiaas
|
||||||
|
*/
|
||||||
|
|
||||||
|
class Wiass_REST_User_Api_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
protected $server;
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
/** @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' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_User_API::validate_token
|
||||||
|
*/
|
||||||
|
function test_validate_token_as_guest() {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'POST', '/wiaas/user/validate-token');
|
||||||
|
$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_User_API::validate_token
|
||||||
|
*/
|
||||||
|
function test_validate_token_with_valid_user() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'POST', '/wiaas/user/validate-token');
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$user_info = $response->get_data()['userInfo'];
|
||||||
|
$this->assertNotNull($user_info);
|
||||||
|
$this->assertTrue(is_array($user_info));
|
||||||
|
$this->assertArrayHasKey('wiaas_id_user', $user_info);
|
||||||
|
$this->assertArrayHasKey('wiaas_is_company_admin', $user_info);
|
||||||
|
$this->assertArrayHasKey('wiaas_user_full_name', $user_info);
|
||||||
|
$this->assertArrayHasKey('wiaas_user_type', $user_info);
|
||||||
|
$this->assertArrayHasKey('wiaas_username', $user_info);
|
||||||
|
$this->assertEquals($user_info['wiaas_id_user'], '1');
|
||||||
|
$this->assertEquals($user_info['wiaas_is_company_admin'], '1');
|
||||||
|
$this->assertEquals($user_info['wiaas_username'], 'admin');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiass_REST_User_API::get_countries
|
||||||
|
*/
|
||||||
|
function test_get_countries_as_guest() {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'GET', '/wiaas/user/get-countries');
|
||||||
|
$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_User_API::get_countries
|
||||||
|
*/
|
||||||
|
function test_get_countries() {
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
|
$request = new WP_REST_Request( 'GET', '/wiaas/user/get-countries');
|
||||||
|
$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);
|
||||||
|
|
||||||
|
$data = $response->get_data();
|
||||||
|
$this->assertNotNull($data);
|
||||||
|
$this->assertTrue(is_array($data));
|
||||||
|
|
||||||
|
$country = $data[0];
|
||||||
|
$this->assertNotNull($country);
|
||||||
|
$this->assertTrue(is_array($country));
|
||||||
|
$this->assertArrayHasKey('country_id', $country);
|
||||||
|
$this->assertArrayHasKey('country_name', $country);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Package_Addon_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Addon::register_addon_package_type()
|
||||||
|
*/
|
||||||
|
function test_addon_package_type_registered() {
|
||||||
|
$package_types = Wiaas_Package_Type::get_available_package_types();
|
||||||
|
|
||||||
|
$this->assertContains('add_on', $package_types);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Addon::set_package_addons()
|
||||||
|
* @covers Wiaas_Package_Addon::get_package_addons()
|
||||||
|
*/
|
||||||
|
function test_adding_package_addons() {
|
||||||
|
$package = $this->create_new_package();
|
||||||
|
|
||||||
|
$addon1 = $this->create_new_package();
|
||||||
|
$addon2 = $this->create_new_package();
|
||||||
|
$addons_ids = array(
|
||||||
|
$addon1->get_id(),
|
||||||
|
$addon2->get_id()
|
||||||
|
);
|
||||||
|
|
||||||
|
Wiaas_Package_Addon::set_package_addons($package, $addons_ids);
|
||||||
|
|
||||||
|
$added_addons = Wiaas_Package_Addon::get_package_addons($package);
|
||||||
|
|
||||||
|
$this->assertNotEmpty($added_addons);
|
||||||
|
$this->assertCount(2, $added_addons);
|
||||||
|
|
||||||
|
foreach ($added_addons as $added_addon) {
|
||||||
|
$this->assertTrue(in_array($added_addon->get_id(), $addons_ids));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Package_Option_Groups_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Option_Groups::register_option_package_type()
|
||||||
|
*/
|
||||||
|
function test_option_package_type_registered() {
|
||||||
|
$package_types = Wiaas_Package_Type::get_available_package_types();
|
||||||
|
|
||||||
|
$this->assertContains('option', $package_types);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Option_Groups::set_package_option_groups()
|
||||||
|
* @covers Wiaas_Package_Option_Groups::get_package_option_groups()
|
||||||
|
*/
|
||||||
|
function test_adding_package_option_group() {
|
||||||
|
$package = $this->create_new_package();
|
||||||
|
|
||||||
|
$option_package1 = $this->create_new_package();
|
||||||
|
Wiaas_Package_Type::set_package_type($option_package1->get_id(), 'option');
|
||||||
|
|
||||||
|
$option_package2 = $this->create_new_package();
|
||||||
|
Wiaas_Package_Type::set_package_type($option_package2->get_id(), 'option');
|
||||||
|
|
||||||
|
$option_group1 = array(
|
||||||
|
'id' => 'option1',
|
||||||
|
'name' => 'Option 1',
|
||||||
|
'default' => $option_package1->get_id(),
|
||||||
|
'options' => array( $option_package1->get_id() )
|
||||||
|
);
|
||||||
|
|
||||||
|
$option_group2 = array(
|
||||||
|
'id' => 'option2',
|
||||||
|
'name' => 'Option 2',
|
||||||
|
'default' => $option_package2->get_id(),
|
||||||
|
'options' => array( $option_package2->get_id() )
|
||||||
|
);
|
||||||
|
|
||||||
|
Wiaas_Package_Option_Groups::set_package_option_groups($package, array(
|
||||||
|
$option_group1,
|
||||||
|
$option_group2
|
||||||
|
));
|
||||||
|
|
||||||
|
$added_option_groups = Wiaas_Package_Option_Groups::get_package_option_groups($package);
|
||||||
|
|
||||||
|
$this->assertNotEmpty($added_option_groups);
|
||||||
|
$this->assertCount(2, $added_option_groups);
|
||||||
|
|
||||||
|
foreach ($added_option_groups as $index => $added_option_group) {
|
||||||
|
$this->assertNotEmpty($added_option_group);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('id', $added_option_group);
|
||||||
|
$this->assertArrayHasKey('name', $added_option_group);
|
||||||
|
$this->assertArrayHasKey('default', $added_option_group);
|
||||||
|
$this->assertArrayHasKey('options', $added_option_group);
|
||||||
|
|
||||||
|
$this->assertEquals($added_option_group['id'], 'option' . ($index + 1));
|
||||||
|
$this->assertEquals($added_option_group['name'], 'Option ' . ($index + 1));
|
||||||
|
$this->assertCount(1, $added_option_group['options']);
|
||||||
|
|
||||||
|
$added_option = $added_option_group['options'][0];
|
||||||
|
$this->assertNotNull($added_option);
|
||||||
|
|
||||||
|
$relevant_option = null;
|
||||||
|
if ($index === 0) {
|
||||||
|
$relevant_option = $option_package1;
|
||||||
|
} else {
|
||||||
|
$relevant_option = $option_package2;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($added_option_group['default'], $relevant_option->get_id());
|
||||||
|
$this->assertEquals($added_option->get_id(), $relevant_option->get_id());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Option_Groups::get_group_name_for_package_option()
|
||||||
|
*/
|
||||||
|
function test_get_group_name_for_package_option() {
|
||||||
|
$package = $this->create_new_package();
|
||||||
|
|
||||||
|
$option_package = $this->create_new_package();
|
||||||
|
Wiaas_Package_Type::set_package_type($option_package->get_id(), 'option');
|
||||||
|
|
||||||
|
$option_group = array(
|
||||||
|
'id' => 'option1',
|
||||||
|
'name' => 'Option 1',
|
||||||
|
'default' => $option_package->get_id(),
|
||||||
|
'options' => array( $option_package->get_id() )
|
||||||
|
);
|
||||||
|
|
||||||
|
Wiaas_Package_Option_Groups::set_package_option_groups($package, array( $option_group ));
|
||||||
|
|
||||||
|
$option_group_name = Wiaas_Package_Option_Groups::get_group_name_for_package_option($package, $option_package);
|
||||||
|
|
||||||
|
$this->assertEquals($option_group_name, $option_group['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas__Package_Type_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Type::register_package_type_taxonomy()
|
||||||
|
* @covers Wiaas_Package_Type::get_available_package_types()
|
||||||
|
*/
|
||||||
|
function test_register_package_type_taxonomy() {
|
||||||
|
$taxonomy = get_taxonomy('package_type');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||||
|
|
||||||
|
$package_types = Wiaas_Package_Type::get_available_package_types();
|
||||||
|
|
||||||
|
$this->assertNotEmpty($package_types);
|
||||||
|
|
||||||
|
$this->assertContains('standard', $package_types);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Type::set_package_type()
|
||||||
|
* @covers Wiaas_Package_Type::get_package_type()
|
||||||
|
*/
|
||||||
|
function test_adding_package_type() {
|
||||||
|
$package = $this->create_new_package();
|
||||||
|
|
||||||
|
Wiaas_Package_Type::set_package_type($package->get_id(), 'standard');
|
||||||
|
|
||||||
|
$package_type = Wiaas_Package_Type::get_package_type($package->get_id());
|
||||||
|
|
||||||
|
$this->assertNotNull($package_type);
|
||||||
|
$this->assertEquals($package_type, 'standard');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Package_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Package_Pricing::set_package_prices()
|
||||||
|
* @covers Wiaas_Package_Pricing::get_package_prices()
|
||||||
|
*/
|
||||||
|
function test_set_and_get_package_prices() {
|
||||||
|
|
||||||
|
$package = $this->create_new_package();
|
||||||
|
|
||||||
|
$pricing_rules = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'minimal_fixed_price' => 10,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'minimal_fixed_price' => 10,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 10
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'minimal_fixed_price' => 10,
|
||||||
|
'principal_amount' => 10,
|
||||||
|
'minimal_services_price' => 10
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$commision = 60;
|
||||||
|
|
||||||
|
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision);
|
||||||
|
|
||||||
|
$configured_prices = Wiaas_Package_Pricing::get_package_prices($package);
|
||||||
|
|
||||||
|
$this->assertCount(3, $configured_prices);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('purchase', $configured_prices);
|
||||||
|
$this->assertArrayHasKey('purchase_24', $configured_prices);
|
||||||
|
$this->assertArrayHasKey('managed_36', $configured_prices);
|
||||||
|
|
||||||
|
foreach ($configured_prices as $type => $configured_price) {
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('id', $configured_price);
|
||||||
|
$this->assertArrayHasKey('payment_type', $configured_price);
|
||||||
|
$this->assertArrayHasKey('max_contract_period', $configured_price);
|
||||||
|
$this->assertArrayHasKey('package_pay_period', $configured_price);
|
||||||
|
$this->assertArrayHasKey('period_unit', $configured_price);
|
||||||
|
$this->assertArrayHasKey('services_contract_period', $configured_price);
|
||||||
|
$this->assertArrayHasKey('commision_split', $configured_price);
|
||||||
|
$this->assertArrayHasKey('minimal_fixed_price', $configured_price);
|
||||||
|
$this->assertArrayHasKey('principal_amount', $configured_price);
|
||||||
|
$this->assertArrayHasKey('minimal_services_price', $configured_price);
|
||||||
|
|
||||||
|
$this->assertEquals($configured_price['id'], $type);
|
||||||
|
$this->assertEquals($configured_price['commision_split'], $commision / 100);
|
||||||
|
|
||||||
|
$this->assertEquals($configured_price['minimal_fixed_price'], $pricing_rules[$type]['minimal_fixed_price']);
|
||||||
|
$this->assertEquals($configured_price['principal_amount'], $pricing_rules[$type]['principal_amount']);
|
||||||
|
$this->assertEquals($configured_price['minimal_services_price'], $pricing_rules[$type]['minimal_services_price']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Product_Pricing_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Pricing::set_product_price()
|
||||||
|
* @covers Wiaas_Product_Pricing::get_product_price()
|
||||||
|
*/
|
||||||
|
function test_adding_product_price() {
|
||||||
|
$product = $this->create_new_product(10, true, 2);
|
||||||
|
|
||||||
|
$configured_price = Wiaas_Product_Pricing::get_product_price($product);
|
||||||
|
|
||||||
|
$this->assertNotNull($configured_price);
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('price', $configured_price);
|
||||||
|
$this->assertArrayHasKey('is_recurring', $configured_price);
|
||||||
|
$this->assertArrayHasKey('pay_period', $configured_price);
|
||||||
|
|
||||||
|
$this->assertEquals($configured_price['price'], 10);
|
||||||
|
$this->assertEquals($configured_price['is_recurring'], true);
|
||||||
|
$this->assertEquals($configured_price['pay_period'], 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Pricing::get_product_price_html()
|
||||||
|
*/
|
||||||
|
function test_get_product_fixed_price_html() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
|
||||||
|
$original_price_html = $product->get_price_html();
|
||||||
|
|
||||||
|
$price_html = Wiaas_Product_Pricing::get_product_price_html($original_price_html, $product);
|
||||||
|
|
||||||
|
$this->assertEquals($price_html, $original_price_html);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Pricing::get_product_price_html()
|
||||||
|
*/
|
||||||
|
function test_get_product_recurrent_price_html() {
|
||||||
|
$product = $this->create_new_product(10, true, 1);
|
||||||
|
|
||||||
|
$original_price_html = $product->get_price_html();
|
||||||
|
|
||||||
|
$price_html = Wiaas_Product_Pricing::get_product_price_html($original_price_html, $product);
|
||||||
|
|
||||||
|
$this->assertEquals($price_html, $original_price_html . ' / month');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Pricing::get_product_fixed_price()
|
||||||
|
*/
|
||||||
|
function test_get_fixed_price_for_fixed_product() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
|
||||||
|
$original_price = $product->get_price();
|
||||||
|
|
||||||
|
$fixed_price = Wiaas_Product_Pricing::get_product_fixed_price($original_price, $product);
|
||||||
|
|
||||||
|
$this->assertEquals($fixed_price, $original_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Pricing::get_product_fixed_price()
|
||||||
|
*/
|
||||||
|
function test_get_fixed_price_for_recurring_product() {
|
||||||
|
$product = $this->create_new_product(10, true, 1);
|
||||||
|
|
||||||
|
$fixed_price = Wiaas_Product_Pricing::get_product_fixed_price($product->get_price(), $product);
|
||||||
|
|
||||||
|
$this->assertEquals($fixed_price, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class Wiaas_Countries_Test
|
||||||
|
*/
|
||||||
|
class Wiaas_Countries_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
var $product, $package, $current_country = 'Sweden';
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
# 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->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' );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Countries::register_product_countries_taxonomy()
|
||||||
|
*/
|
||||||
|
function test_available_countries_created() {
|
||||||
|
// test taxonomy is available
|
||||||
|
$taxonomy = get_taxonomy('product_country');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||||
|
|
||||||
|
$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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Countries::get_product_country()
|
||||||
|
*/
|
||||||
|
function test_get_product_country() {
|
||||||
|
|
||||||
|
$retrieved_country = Wiaas_Countries::get_product_country($this->product);
|
||||||
|
|
||||||
|
$this->assertNotNull($retrieved_country, 'Product has not country!');
|
||||||
|
|
||||||
|
$this->assertEquals($retrieved_country['name'], $this->current_country, 'Retrieved product country is incorrect!');
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Countries::get_package_country()
|
||||||
|
*/
|
||||||
|
function test_get_package_country() {
|
||||||
|
$retrieved_country = Wiaas_Countries::get_package_country($this->package);
|
||||||
|
|
||||||
|
$this->assertNotNull($retrieved_country, 'Package has not country!');
|
||||||
|
|
||||||
|
$this->assertEquals($retrieved_country['name'], $this->current_country, 'Retrieved package country is incorrect!');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Order_Project_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Project::register_order_project_taxonomy()
|
||||||
|
*/
|
||||||
|
function test_order_project_taxonomy_created() {
|
||||||
|
$taxonomy = get_taxonomy('shop_order_project');
|
||||||
|
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Project::add_order_project()
|
||||||
|
*/
|
||||||
|
function test_adding_order_project() {
|
||||||
|
Wiaas_Order_Project::add_order_project('Test', true);
|
||||||
|
|
||||||
|
$added_order_project = get_term_by('name', 'Test', 'shop_order_project');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(WP_Term::class, $added_order_project);
|
||||||
|
$this->assertEquals($added_order_project->name, 'Test');
|
||||||
|
|
||||||
|
$saved_available_flag = get_term_meta($added_order_project->term_id, '_wiaas_is_available', true);
|
||||||
|
$this->assertEquals('yes', $saved_available_flag);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Project::is_order_project_available()
|
||||||
|
*/
|
||||||
|
function test_is_order_project_available() {
|
||||||
|
Wiaas_Order_Project::add_order_project('Test', true);
|
||||||
|
$added_order_project = get_term_by('name', 'Test', 'shop_order_project');
|
||||||
|
|
||||||
|
$this->assertTrue(Wiaas_Order_Project::is_order_project_available($added_order_project));
|
||||||
|
|
||||||
|
$this->assertTrue(Wiaas_Order_Project::is_order_project_available($added_order_project->term_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Project::set_is_order_project_available()
|
||||||
|
*/
|
||||||
|
function test_set_is_order_project_available() {
|
||||||
|
Wiaas_Order_Project::add_order_project('Test', true);
|
||||||
|
$added_order_project = get_term_by('name', 'Test', 'shop_order_project');
|
||||||
|
|
||||||
|
Wiaas_Order_Project::set_is_order_project_available($added_order_project, false);
|
||||||
|
$saved_available_flag = get_term_meta($added_order_project->term_id, '_wiaas_is_available', true);
|
||||||
|
$this->assertEquals('no', $saved_available_flag);
|
||||||
|
|
||||||
|
Wiaas_Order_Project::set_is_order_project_available($added_order_project->term_id, true);
|
||||||
|
$saved_available_flag = get_term_meta($added_order_project->term_id, '_wiaas_is_available', true);
|
||||||
|
$this->assertEquals('yes', $saved_available_flag);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order_Project::get_available_order_projects()
|
||||||
|
*/
|
||||||
|
function test_get_available_order_projects() {
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Available 1', true);
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Available 2', true);
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Available 3', true);
|
||||||
|
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Not Available 1', false);
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Not Available 2', false);
|
||||||
|
Wiaas_Order_Project::add_order_project('Test Not Available 3', false);
|
||||||
|
|
||||||
|
$available_projects = Wiaas_Order_Project::get_available_order_projects();
|
||||||
|
|
||||||
|
$this->assertCount(3, $available_projects);
|
||||||
|
|
||||||
|
foreach ($available_projects as $project) {
|
||||||
|
$this->assertArrayHasKey('id', $project);
|
||||||
|
$this->assertArrayHasKey('name', $project);
|
||||||
|
|
||||||
|
$this->assertContains($project['name'], array(
|
||||||
|
'Test Available 1',
|
||||||
|
'Test Available 2',
|
||||||
|
'Test Available 3'
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -198,4 +198,28 @@ class Wiaas_Order_Test extends Wiaas_Unit_Test_Case {
|
|||||||
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
|
$this->assertArrayHasKey('email', $transformed_order_response['commercial_lead']);
|
||||||
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
|
$this->assertArrayHasKey('phone', $transformed_order_response['commercial_lead']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Order::transform_rest_order()
|
||||||
|
*/
|
||||||
|
function test_order_rest_response_has_empty_documents_when_package_has_no_documents() {
|
||||||
|
$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['documents']);
|
||||||
|
$this->assertTrue(is_array($transformed_order_response['documents']));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,359 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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));
|
||||||
|
|
||||||
|
$pricing_rules = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'minimal_fixed_price' => 100,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'minimal_fixed_price' => 100,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 100
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'minimal_fixed_price' => 100,
|
||||||
|
'principal_amount' => 100,
|
||||||
|
'minimal_services_price' => 100
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$commision = 50;
|
||||||
|
Wiaas_Package_Pricing::set_package_prices($package, $pricing_rules, $commision);
|
||||||
|
|
||||||
|
$expected_prices = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'fixed_extra' => 100,
|
||||||
|
'recurrent_extra' => 0,
|
||||||
|
'services_extra' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'fixed_extra' => 100,
|
||||||
|
'recurrent_extra' => 0,
|
||||||
|
'services_extra' => 100
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'fixed_extra' => 100,
|
||||||
|
'recurrent_extra' => 3,
|
||||||
|
'services_extra' => 100
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return array( $package, $expected_prices );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Pricing::get_product_total_cost()
|
||||||
|
*/
|
||||||
|
function test_get_fixed_product_total_cost() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
|
||||||
|
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
|
||||||
|
|
||||||
|
$this->assertEquals($total_cost, $product->get_price());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Pricing::get_product_total_cost()
|
||||||
|
*/
|
||||||
|
function test_get_recurring_product_total_cost() {
|
||||||
|
$product = $this->create_new_product(10, true, 2);
|
||||||
|
|
||||||
|
$total_cost = Wiaas_Pricing::get_product_total_cost($product);
|
||||||
|
|
||||||
|
$this->assertEquals($total_cost, 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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));
|
||||||
|
|
||||||
|
$expected_total_price = 40;
|
||||||
|
|
||||||
|
$total_price = Wiaas_Pricing::get_package_total_cost($package);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_total_price, $total_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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));
|
||||||
|
|
||||||
|
$expected_total_price = 60;
|
||||||
|
|
||||||
|
$total_price = Wiaas_Pricing::get_package_total_cost($package);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_total_price, $total_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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));
|
||||||
|
|
||||||
|
$expected_total_price = 60;
|
||||||
|
|
||||||
|
$total_price = Wiaas_Pricing::get_package_total_cost($package);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_total_price, $total_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @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));
|
||||||
|
|
||||||
|
// price will be 20 + 20*2 , more expensive installation will be applied
|
||||||
|
$expected_total_price = 60;
|
||||||
|
|
||||||
|
$total_price = Wiaas_Pricing::get_package_total_cost($package);
|
||||||
|
|
||||||
|
$this->assertEquals($expected_total_price, $total_price);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Pricing::get_standard_package_customer_prices()
|
||||||
|
*/
|
||||||
|
function test_get_standard_package_customer_price() {
|
||||||
|
|
||||||
|
list( $package, $expected_prices ) = $this->_create_package_to_sell();
|
||||||
|
|
||||||
|
$customer_prices = Wiaas_Pricing::get_standard_package_customer_prices($package);
|
||||||
|
|
||||||
|
$this->assertCount(3, $customer_prices);
|
||||||
|
|
||||||
|
foreach ($customer_prices as $customer_price) {
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('id', $customer_price);
|
||||||
|
$this->assertArrayHasKey('payment_type', $customer_price);
|
||||||
|
$this->assertArrayHasKey('max_contract_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('package_pay_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('period_unit', $customer_price);
|
||||||
|
$this->assertArrayHasKey('services_contract_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('fixed_extra', $customer_price);
|
||||||
|
$this->assertArrayHasKey('recurrent_extra', $customer_price);
|
||||||
|
$this->assertArrayHasKey('services_extra', $customer_price);
|
||||||
|
|
||||||
|
$id = $customer_price['id'];
|
||||||
|
|
||||||
|
$this->assertEquals($customer_price['fixed_extra'], $expected_prices[$id]['fixed_extra']);
|
||||||
|
$this->assertEquals($customer_price['recurrent_extra'], $expected_prices[$id]['recurrent_extra']);
|
||||||
|
$this->assertEquals($customer_price['services_extra'], $expected_prices[$id]['services_extra']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Pricing::get_addon_package_customer_price()
|
||||||
|
*/
|
||||||
|
function test_get_addon_package_customer_price() {
|
||||||
|
list( $package ) = $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));
|
||||||
|
|
||||||
|
$pricing_rules = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'minimal_fixed_price' => 500,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'minimal_fixed_price' => 500,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 500
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'minimal_fixed_price' => 500,
|
||||||
|
'principal_amount' => 500,
|
||||||
|
'minimal_services_price' => 500
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$commision = 50;
|
||||||
|
Wiaas_Package_Pricing::set_package_prices($addon_package, $pricing_rules, $commision);
|
||||||
|
|
||||||
|
Wiaas_Package_Addon::set_package_addons($package, array($addon_package->get_id()));
|
||||||
|
|
||||||
|
$expected_prices = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'fixed_extra' => 500,
|
||||||
|
'recurrent_extra' => 0,
|
||||||
|
'services_extra' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'fixed_extra' => 500,
|
||||||
|
'recurrent_extra' => 0,
|
||||||
|
'services_extra' => 500
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'fixed_extra' => 500,
|
||||||
|
'recurrent_extra' => 14,
|
||||||
|
'services_extra' => 500
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$customer_prices = Wiaas_Pricing::get_addon_package_customer_price($addon_package, $package);
|
||||||
|
|
||||||
|
$this->assertCount(3, $customer_prices);
|
||||||
|
|
||||||
|
foreach ($customer_prices as $customer_price) {
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('id', $customer_price);
|
||||||
|
$this->assertArrayHasKey('payment_type', $customer_price);
|
||||||
|
$this->assertArrayHasKey('max_contract_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('package_pay_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('period_unit', $customer_price);
|
||||||
|
$this->assertArrayHasKey('services_contract_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('fixed_extra', $customer_price);
|
||||||
|
$this->assertArrayHasKey('recurrent_extra', $customer_price);
|
||||||
|
$this->assertArrayHasKey('services_extra', $customer_price);
|
||||||
|
|
||||||
|
$id = $customer_price['id'];
|
||||||
|
|
||||||
|
$this->assertEquals($customer_price['fixed_extra'], $expected_prices[$id]['fixed_extra']);
|
||||||
|
$this->assertEquals($customer_price['recurrent_extra'], $expected_prices[$id]['recurrent_extra']);
|
||||||
|
$this->assertEquals($customer_price['services_extra'], $expected_prices[$id]['services_extra']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Pricing::get_option_package_customer_price()
|
||||||
|
*/
|
||||||
|
function test_get_option_package_customer_price() {
|
||||||
|
list( $package ) = $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));
|
||||||
|
|
||||||
|
$pricing_rules = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'minimal_fixed_price' => 500,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'minimal_fixed_price' => 500,
|
||||||
|
'principal_amount' => 0,
|
||||||
|
'minimal_services_price' => 500
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'minimal_fixed_price' => 500,
|
||||||
|
'principal_amount' => 500,
|
||||||
|
'minimal_services_price' => 500
|
||||||
|
)
|
||||||
|
);
|
||||||
|
$commision = 50;
|
||||||
|
Wiaas_Package_Pricing::set_package_prices($option_package, $pricing_rules, $commision);
|
||||||
|
|
||||||
|
Wiaas_Package_Option_Groups::set_package_option_groups($package, array(
|
||||||
|
'id' => 'option',
|
||||||
|
'name' => 'Option',
|
||||||
|
'default' => $option_package->get_id(),
|
||||||
|
'options' => array( $option_package->get_id() )
|
||||||
|
));
|
||||||
|
|
||||||
|
$expected_prices = array(
|
||||||
|
'purchase' => array(
|
||||||
|
'fixed_extra' => 500,
|
||||||
|
'recurrent_extra' => 0,
|
||||||
|
'services_extra' => 0
|
||||||
|
),
|
||||||
|
'purchase_24' => array(
|
||||||
|
'fixed_extra' => 500,
|
||||||
|
'recurrent_extra' => 0,
|
||||||
|
'services_extra' => 500
|
||||||
|
),
|
||||||
|
'managed_36' => array(
|
||||||
|
'fixed_extra' => 500,
|
||||||
|
'recurrent_extra' => 14,
|
||||||
|
'services_extra' => 500
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$customer_prices = Wiaas_Pricing::get_option_package_customer_price($option_package, $package);
|
||||||
|
|
||||||
|
$this->assertCount(3, $customer_prices);
|
||||||
|
|
||||||
|
foreach ($customer_prices as $customer_price) {
|
||||||
|
|
||||||
|
$this->assertArrayHasKey('id', $customer_price);
|
||||||
|
$this->assertArrayHasKey('payment_type', $customer_price);
|
||||||
|
$this->assertArrayHasKey('max_contract_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('package_pay_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('period_unit', $customer_price);
|
||||||
|
$this->assertArrayHasKey('services_contract_period', $customer_price);
|
||||||
|
$this->assertArrayHasKey('fixed_extra', $customer_price);
|
||||||
|
$this->assertArrayHasKey('recurrent_extra', $customer_price);
|
||||||
|
$this->assertArrayHasKey('services_extra', $customer_price);
|
||||||
|
|
||||||
|
$id = $customer_price['id'];
|
||||||
|
|
||||||
|
$this->assertEquals($customer_price['fixed_extra'], $expected_prices[$id]['fixed_extra']);
|
||||||
|
$this->assertEquals($customer_price['recurrent_extra'], $expected_prices[$id]['recurrent_extra']);
|
||||||
|
$this->assertEquals($customer_price['services_extra'], $expected_prices[$id]['services_extra']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
class Wiaas_Product_Category_Test extends Wiaas_Unit_Test_Case {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Category::register_product_categories()
|
||||||
|
*/
|
||||||
|
function test_available_product_categories_created() {
|
||||||
|
$taxonomy = get_taxonomy('product_cat');
|
||||||
|
|
||||||
|
$this->assertInstanceOf(WP_Taxonomy::class, $taxonomy);
|
||||||
|
|
||||||
|
$category_names = array_map(function($term) {
|
||||||
|
return $term->name;
|
||||||
|
}, get_terms(array( 'taxonomy' => 'product_cat', 'hide_empty' => false )));
|
||||||
|
|
||||||
|
$this->assertNotEmpty($category_names);
|
||||||
|
|
||||||
|
$this->assertTrue(in_array('hardware', $category_names));
|
||||||
|
$this->assertTrue(in_array('software', $category_names));
|
||||||
|
$this->assertTrue(in_array('service', $category_names));
|
||||||
|
$this->assertTrue(in_array('installation', $category_names));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Category::get_category()
|
||||||
|
*/
|
||||||
|
function test_get_category() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
$this->add_product_category($product, 'hardware');
|
||||||
|
|
||||||
|
$product_category = Wiaas_Product_Category::get_category($product);
|
||||||
|
|
||||||
|
$this->assertNotNull($product_category);
|
||||||
|
$this->assertEquals($product_category, 'hardware');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Category::is_service()
|
||||||
|
*/
|
||||||
|
function test_is_service_negative() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
$this->add_product_category($product, 'hardware');
|
||||||
|
|
||||||
|
$this->assertFalse(Wiaas_Product_Category::is_service($product));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Category::is_service()
|
||||||
|
*/
|
||||||
|
function test_is_service_positive() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
$this->add_product_category($product, 'service');
|
||||||
|
|
||||||
|
$this->assertTrue(Wiaas_Product_Category::is_service($product));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Category::is_installation()
|
||||||
|
*/
|
||||||
|
function test_is_installation_negative() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
$this->add_product_category($product, 'hardware');
|
||||||
|
|
||||||
|
$this->assertFalse(Wiaas_Product_Category::is_installation($product));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Wiaas_Product_Category::is_installation()
|
||||||
|
*/
|
||||||
|
function test_is_installation_positive() {
|
||||||
|
$product = $this->create_new_product();
|
||||||
|
$this->add_product_category($product, 'installation');
|
||||||
|
|
||||||
|
$this->assertTrue(Wiaas_Product_Category::is_installation($product));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
63
backend/app/plugins/wiaas/tests/wiaas-api-unit-test-case.php
Normal file
63
backend/app/plugins/wiaas/tests/wiaas-api-unit-test-case.php
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements common logic for testing Wiaas API
|
||||||
|
*
|
||||||
|
* Class Wiaas_API_Unit_Test_Case
|
||||||
|
*/
|
||||||
|
class Wiaas_API_Unit_Test_Case extends Wiaas_Unit_Test_Case {
|
||||||
|
protected $server;
|
||||||
|
|
||||||
|
function setUp() {
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
/** @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' );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that given endpoint is forbidden when accessed as guest
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request Request to test
|
||||||
|
*/
|
||||||
|
function check_endpoint_forbidden_for_guest($request) {
|
||||||
|
wp_set_current_user(0);
|
||||||
|
|
||||||
|
$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.');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles common action during dispatching of rest request
|
||||||
|
*
|
||||||
|
* @param WP_REST_Request $request
|
||||||
|
* @param int $expected_status_code
|
||||||
|
* @param bool $is_error_expected
|
||||||
|
*
|
||||||
|
* @return mixed Result error when error is expected, result data otherwise
|
||||||
|
*/
|
||||||
|
function dispatch_endpoint_request($request, $expected_status_code = 200, $is_error_expected = false) {
|
||||||
|
$response = $this->server->dispatch( $request );
|
||||||
|
|
||||||
|
$this->assertNotNull($response);
|
||||||
|
$this->assertInstanceOf('WP_REST_Response',$response);
|
||||||
|
$this->assertEquals($response->get_status(), $expected_status_code);
|
||||||
|
|
||||||
|
if ($is_error_expected) {
|
||||||
|
$this->assertTrue($response->is_error());
|
||||||
|
return $response->as_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertFalse($response->is_error());
|
||||||
|
return $response->get_data();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,18 +8,107 @@ class Wiaas_Unit_Test_Case extends WP_UnitTestCase {
|
|||||||
*/
|
*/
|
||||||
function setUp() {
|
function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
wp_set_current_user(1);
|
||||||
|
|
||||||
# Setup Gravity info since options table is deleted after each test
|
# Setup Gravity info since options table is deleted after each test
|
||||||
gf_upgrade()->install();
|
gf_upgrade()->install();
|
||||||
|
|
||||||
|
WC_PB_Install::install();
|
||||||
|
|
||||||
wiaas_db_update_setup_gravity();
|
wiaas_db_update_setup_gravity();
|
||||||
|
|
||||||
wiaas_db_update_enable_orders_access_management();
|
wiaas_db_update_enable_orders_access_management();
|
||||||
|
|
||||||
|
Wiaas_Countries::register_product_countries_taxonomy();
|
||||||
|
|
||||||
|
Wiaas_Product_Category::register_product_categories();
|
||||||
|
|
||||||
|
Wiaas_Package_Type::register_package_type_taxonomy();
|
||||||
|
|
||||||
|
Wiaas_Order_Project::register_order_project_taxonomy();
|
||||||
|
|
||||||
define('WP_TEST_IN_PROGRESS',true);
|
define('WP_TEST_IN_PROGRESS',true);
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function create_new_product($price = 10, $is_recurring = false, $pay_period = 0) {
|
||||||
|
$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);
|
||||||
|
|
||||||
|
Wiaas_Product_Pricing::set_product_price($product, $price, $is_recurring, $pay_period);
|
||||||
|
|
||||||
|
$product->save();
|
||||||
|
|
||||||
|
return $product;
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_new_package() {
|
||||||
|
$post_id = wp_insert_post(array(
|
||||||
|
'post_type' => 'product',
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'post_name' => 'product',
|
||||||
|
'post_title' => 'Package',
|
||||||
|
'post_content' => 'Package',
|
||||||
|
'post_excerpt' => 'Package'
|
||||||
|
), true);
|
||||||
|
|
||||||
|
return new WC_Product_Bundle($post_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_product_category($product, $name) {
|
||||||
|
wp_set_object_terms($product->get_id(), $name, 'product_cat', false);
|
||||||
|
clean_object_term_cache( $product->get_id(), 'product_cat' );
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_products_to_package($package, $products) {
|
||||||
|
$bundled_data = array();
|
||||||
|
|
||||||
|
foreach ($products as $product) {
|
||||||
|
$bundled_data[] = array(
|
||||||
|
'product_id' => $product->get_id(),
|
||||||
|
'quantity_min' => 1,
|
||||||
|
'quantity_max' => 1,
|
||||||
|
'priced_individually' => true
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$package->set_bundled_data_items($bundled_data);
|
||||||
|
|
||||||
|
$package->sync(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
function create_new_customer($login = 'customer_test', $organization_name = 'test-customer-organization') {
|
||||||
|
$customer_id = wp_insert_user(array(
|
||||||
|
'user_login' => $login,
|
||||||
|
'user_pass' => 'test',
|
||||||
|
'user_email' => $login . '@mail.com',
|
||||||
|
'role' => 'customer',
|
||||||
|
));
|
||||||
|
|
||||||
|
$organization = get_term_by('name', $organization_name, Wiaas_User_Organization::TAXONOMY_NAME);
|
||||||
|
if (is_wp_error($organization)) {
|
||||||
|
$organization = wp_insert_term(
|
||||||
|
$organization_name,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
wp_set_terms_for_user(
|
||||||
|
$customer_id,
|
||||||
|
Wiaas_User_Organization::TAXONOMY_NAME,
|
||||||
|
[$organization_name]);
|
||||||
|
|
||||||
|
return $customer_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -40,6 +40,8 @@ include_once WIAAS_DIR . '/includes/class-wiaas-documents.php';
|
|||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-cart.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-cart.php';
|
||||||
|
|
||||||
|
include_once WIAAS_DIR . '/includes/class-wiaas-checkout.php';
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';
|
||||||
|
|
||||||
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
include_once WIAAS_DIR . '/includes/class-wiaas-admin.php';
|
||||||
|
|||||||
41
docker/frontend/000-default.conf
Normal file
41
docker/frontend/000-default.conf
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
<VirtualHost *:80>
|
||||||
|
# The ServerName directive sets the request scheme, hostname and port that
|
||||||
|
# the server uses to identify itself. This is used when creating
|
||||||
|
# redirection URLs. In the context of virtual hosts, the ServerName
|
||||||
|
# specifies what hostname must appear in the request's Host: header to
|
||||||
|
# match this virtual host. For the default virtual host (this file) this
|
||||||
|
# value is not decisive as it is used as a last resort host regardless.
|
||||||
|
# However, you must set it for any further virtual host explicitly.
|
||||||
|
#ServerName www.example.com
|
||||||
|
|
||||||
|
ServerAdmin webmaster@localhost
|
||||||
|
DocumentRoot /var/www/html
|
||||||
|
|
||||||
|
<Directory "/var/www/html">
|
||||||
|
RewriteEngine on
|
||||||
|
# Don't rewrite files or directories
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -f [OR]
|
||||||
|
RewriteCond %{REQUEST_FILENAME} -d
|
||||||
|
RewriteRule ^ - [L]
|
||||||
|
# Rewrite everything else to index.html to allow html5 state links
|
||||||
|
RewriteRule ^ index.html [L]
|
||||||
|
</Directory>
|
||||||
|
|
||||||
|
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
|
||||||
|
# error, crit, alert, emerg.
|
||||||
|
# It is also possible to configure the loglevel for particular
|
||||||
|
# modules, e.g.
|
||||||
|
#LogLevel info ssl:warn
|
||||||
|
|
||||||
|
ErrorLog ${APACHE_LOG_DIR}/error.log
|
||||||
|
CustomLog ${APACHE_LOG_DIR}/access.log combined
|
||||||
|
|
||||||
|
# For most configuration files from conf-available/, which are
|
||||||
|
# enabled or disabled at a global level, it is possible to
|
||||||
|
# include a line for only one particular virtual host. For example the
|
||||||
|
# following line enables the CGI configuration for this host only
|
||||||
|
# after it has been globally disabled with "a2disconf".
|
||||||
|
#Include conf-available/serve-cgi-bin.conf
|
||||||
|
</VirtualHost>
|
||||||
|
|
||||||
|
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
|
||||||
@@ -8,6 +8,8 @@ RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
|
|||||||
RUN apt-get install -y nodejs
|
RUN apt-get install -y nodejs
|
||||||
|
|
||||||
COPY frontend /home/wiaas/frontend
|
COPY frontend /home/wiaas/frontend
|
||||||
|
RUN a2enmod rewrite
|
||||||
|
COPY docker/frontend/000-default.conf /etc/apache2/sites-available
|
||||||
|
|
||||||
WORKDIR /home/wiaas/frontend
|
WORKDIR /home/wiaas/frontend
|
||||||
RUN npm install && npm rebuild node-sass --force && npm run build
|
RUN npm install && npm rebuild node-sass --force && npm run build
|
||||||
|
|||||||
@@ -1,34 +1,37 @@
|
|||||||
import React, {Component} from 'react';
|
import React, { Component } from 'react';
|
||||||
import {connect} from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import ContentContainer from './containers/ContentContainer.jsx';
|
import ContentContainer from './containers/ContentContainer.jsx';
|
||||||
import LogInContainer from './containers/login/LogInContainer.jsx';
|
import LogInContainer from './containers/login/LogInContainer.jsx';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import './mainComponents/box/WiaasBox.css';
|
import './mainComponents/box/WiaasBox.css';
|
||||||
import NotificationBox from './mainComponents/notification/NotificationBox.jsx';
|
import NotificationBox from './mainComponents/notification/NotificationBox.jsx';
|
||||||
import DialogBox from './mainComponents/dialog/DialogBox.jsx';
|
import DialogBox from './mainComponents/dialog/DialogBox.jsx';
|
||||||
|
import LoaderContainer from './containers/LoaderContainer';
|
||||||
|
|
||||||
class App extends Component {
|
class App extends Component {
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {isLoggedIn, updateMessages, isDialogOpen, dialogContent} = this.props;
|
const { isLoggedIn, updateMessages, isDialogOpen, dialogContent } = this.props;
|
||||||
|
let hasAccesToken = localStorage.accessToken;
|
||||||
|
|
||||||
return (<div className="App">
|
return (<div className="App">
|
||||||
|
|
||||||
{
|
{
|
||||||
!isLoggedIn
|
!isLoggedIn
|
||||||
? (<LogInContainer/>)
|
? hasAccesToken ? (<LoaderContainer />) : (<LogInContainer />)
|
||||||
: (<ContentContainer className="content"/>)
|
: (<ContentContainer className="content" />)
|
||||||
}
|
}
|
||||||
<NotificationBox messages={updateMessages}/>
|
<NotificationBox messages={updateMessages} />
|
||||||
<DialogBox isDialogOpen={isDialogOpen} dialogContent={dialogContent}/>
|
<DialogBox isDialogOpen={isDialogOpen} dialogContent={dialogContent} />
|
||||||
</div>);
|
</div>);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
isLoggedIn: state.auth.isLoggedIn,
|
isLoggedIn: state.auth.isLoggedIn,
|
||||||
updateMessages: state.notificationReducer.updateMessages,
|
updateMessages: state.notificationReducer.updateMessages,
|
||||||
isDialogOpen: state.dialogReducer.isDialogOpen,
|
isDialogOpen: state.dialogReducer.isDialogOpen,
|
||||||
dialogContent: state.dialogReducer.dialogContent
|
dialogContent: state.dialogReducer.dialogContent
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(mapStateToProps)(App);
|
export default connect(mapStateToProps)(App);
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ import {
|
|||||||
cartMessages
|
cartMessages
|
||||||
} from '../../constants/cartConstants';
|
} from '../../constants/cartConstants';
|
||||||
import {updateMessages} from '../notification/notificationActions';
|
import {updateMessages} from '../notification/notificationActions';
|
||||||
|
import { fromWCCartItems } from '../../helpers/CartHelper';
|
||||||
|
|
||||||
const client = new HtmlClient();
|
const client = new HtmlClient();
|
||||||
|
|
||||||
export const requestShopCartCount = () => ({type: REQUEST_SHOP_CART_COUNT});
|
export const requestShopCartCount = () => ({type: REQUEST_SHOP_CART_COUNT});
|
||||||
@@ -72,10 +74,13 @@ export const fetchCartItems = (isForSteps = false) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestShopCartItems());
|
dispatch(requestShopCartItems());
|
||||||
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/cart/items`}).then(response => {
|
return client.fetch({url: `${API_SERVER}/wp-json/wiaas/cart/items`}).then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'cartItems' in response.data) {
|
if (typeof response.data !== 'undefined' && 'items' in response.data) {
|
||||||
dispatch(receiveShopCartItems(response.data.cartItems));
|
|
||||||
dispatch(fetchCartDocuments(response.data.cartItems.map((cartItem) => cartItem.idPackage), isForSteps));
|
const cartItems = response.data.items.map(wcCartItem => fromWCCartItems(wcCartItem));
|
||||||
dispatch(updateOrderTotalPrice(response.data.cartItems));
|
|
||||||
|
dispatch(receiveShopCartItems(cartItems));
|
||||||
|
dispatch(fetchCartDocuments(cartItems.map((cartItem) => cartItem.idPackage), isForSteps));
|
||||||
|
dispatch(updateOrderTotalPrice(cartItems));
|
||||||
}
|
}
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
client.onError(error, dispatch);
|
client.onError(error, dispatch);
|
||||||
@@ -90,19 +95,14 @@ const updateCartItems = (newItem)=>(
|
|||||||
);
|
);
|
||||||
|
|
||||||
export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
||||||
const params = {
|
|
||||||
idPackage: cartItem.idPackage || 0,
|
|
||||||
package_item_key: cartItem.key,
|
|
||||||
idCustomerInstance: cartItem.idCustomerInstance || 0,
|
|
||||||
idPrice: cartItem.idPrice || 0,
|
|
||||||
quantity
|
|
||||||
};
|
|
||||||
|
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wiaas/cart/update-quantity`,
|
url: `${API_SERVER}/wp-json/wiaas/cart/items/${cartItem.key}`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: params
|
data: {
|
||||||
|
quantity
|
||||||
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||||
const filteredMessages = response.data.messages.filter(message => {
|
const filteredMessages = response.data.messages.filter(message => {
|
||||||
@@ -125,11 +125,8 @@ export const updateQuantity = (cartItem, quantity, updateCartAllItems) => {
|
|||||||
export const removeCartItem = (cartItemKey) => {
|
export const removeCartItem = (cartItemKey) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wiaas/cart/remove`,
|
url: `${API_SERVER}/wp-json/wiaas/cart/items/${cartItemKey}`,
|
||||||
method: 'post',
|
method: 'delete',
|
||||||
data: {
|
|
||||||
package_item_key: cartItemKey
|
|
||||||
}
|
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||||
@@ -269,21 +266,30 @@ export const fetchCartDocuments = (packages, isForSteps = false) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestCartDocuments());
|
dispatch(requestCartDocuments());
|
||||||
|
|
||||||
return client.fetch({
|
dispatch(receiveCartDocuments({
|
||||||
url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
areFilesUploaded: true,
|
||||||
method: 'get',
|
templates: [],
|
||||||
data: {packages}
|
uploaded: []
|
||||||
}).then(response => {
|
}));
|
||||||
if (response.data) {
|
if(isForSteps) {
|
||||||
dispatch(receiveCartDocuments(response.data));
|
dispatch(loadSteps(true));
|
||||||
if(isForSteps) {
|
}
|
||||||
const whitoutUploadDoc = response.data.templates.length === 0;
|
|
||||||
dispatch(loadSteps(whitoutUploadDoc));
|
// return client.fetch({
|
||||||
}
|
// url: `${API_SERVER}/wp-json/wiaas/cart/documents`,
|
||||||
}
|
// method: 'get',
|
||||||
}).catch(error => {
|
// data: {packages}
|
||||||
client.onError(error, dispatch);
|
// }).then(response => {
|
||||||
});
|
// if (response.data) {
|
||||||
|
// dispatch(receiveCartDocuments(response.data));
|
||||||
|
// if(isForSteps) {
|
||||||
|
// const whitoutUploadDoc = response.data.templates.length === 0;
|
||||||
|
// dispatch(loadSteps(whitoutUploadDoc));
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }).catch(error => {
|
||||||
|
// client.onError(error, dispatch);
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,9 +325,17 @@ export const placeOrder = (orderInfo) => {
|
|||||||
const {orderDetails, cartItems} = orderInfo;
|
const {orderDetails, cartItems} = orderInfo;
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wiaas/cart/place-order`,
|
url: `${API_SERVER}/wp-json/wiaas/cart/checkout`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: orderDetails
|
data: {
|
||||||
|
vat: orderDetails.vatCode,
|
||||||
|
company: orderDetails.companyName,
|
||||||
|
reference: orderDetails.details.reference,
|
||||||
|
tender: orderDetails.details.tender,
|
||||||
|
project_id: orderDetails.details.idProject,
|
||||||
|
delivery_address_id: orderDetails.delivery.id,
|
||||||
|
billing_address_id: orderDetails.billing.id,
|
||||||
|
}
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||||
dispatch(updateMessages(response.data.messages, cartMessages));
|
dispatch(updateMessages(response.data.messages, cartMessages));
|
||||||
|
|||||||
@@ -111,13 +111,6 @@ export const addToCart = (addParams) => {
|
|||||||
addParams.selectedAdditionals,
|
addParams.selectedAdditionals,
|
||||||
addParams.selectedAgreement);
|
addParams.selectedAgreement);
|
||||||
|
|
||||||
const params = {
|
|
||||||
'package_id': addParams.selectedPackage.id,
|
|
||||||
'price_id': addParams.selectedAgreement.idPrice,
|
|
||||||
'addons': result.additionalPackages,
|
|
||||||
'options': result.optionPackages
|
|
||||||
};
|
|
||||||
|
|
||||||
if(result.unavailablePackages.length){
|
if(result.unavailablePackages.length){
|
||||||
const unavailable = result.unavailablePackages.map((unavailable) =>{return unavailable.optionName || unavailable.packageName;});
|
const unavailable = result.unavailablePackages.map((unavailable) =>{return unavailable.optionName || unavailable.packageName;});
|
||||||
const message = coMarketMessages.UNAVAILABLE_PACKAGES + ' ' + unavailable.join();
|
const message = coMarketMessages.UNAVAILABLE_PACKAGES + ' ' + unavailable.join();
|
||||||
@@ -128,9 +121,14 @@ export const addToCart = (addParams) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestAddToCart());
|
dispatch(requestAddToCart());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/wp-json/wiaas/cart/add`,
|
url: `${API_SERVER}/wp-json/wiaas/cart/items`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: params
|
data: {
|
||||||
|
'package_id': addParams.selectedPackage.id,
|
||||||
|
'price_id': addParams.selectedAgreement.idPrice,
|
||||||
|
'addons_ids': result.additionalPackages,
|
||||||
|
'options_ids': result.optionPackages
|
||||||
|
},
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data && response.data.messages){
|
||||||
|
|||||||
@@ -34,56 +34,23 @@ export const validateToken = () => ({
|
|||||||
type: VALIDATE_TOKEN
|
type: VALIDATE_TOKEN
|
||||||
});
|
});
|
||||||
|
|
||||||
export const validateAccessToken = (token) => {
|
export const validateAccessToken = () => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(validateToken());
|
dispatch(validateToken());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/wp-json/jwt-auth/v1/token/validate`,
|
url: `${API_SERVER}/wp-json/wiaas/user/validate-token`,
|
||||||
method: 'post'
|
method: 'post'
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data && response.data.data.status === 200) {
|
if (response.data && response.status === 200) {
|
||||||
|
|
||||||
// TODO: Implement refresh logic on backend as it was on old wias , or find a nother way
|
// TODO: Implement refresh logic on backend as it was on old wias , or find a nother way
|
||||||
// to handle token validation another way
|
// to handle token validation another way
|
||||||
// const serverTime = response.data.serverTime || 1;
|
// const serverTime = response.data.serverTime || 1;
|
||||||
|
dispatch(loggedIn(response.data.userInfo));
|
||||||
dispatch(loggedIn({
|
|
||||||
accessToken: token,
|
|
||||||
userInfo: {
|
|
||||||
"id": 2,
|
|
||||||
"name": "Customer User",
|
|
||||||
"mail": "customer@mail.com",
|
|
||||||
"phone": "",
|
|
||||||
"userType": "customer",
|
|
||||||
"vatCode": "556084-6783",
|
|
||||||
"companyName": "Coor Service Management AB",
|
|
||||||
"billingAddresses": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"city": "fsdfcsdfcs",
|
|
||||||
"countryName": "SE",
|
|
||||||
"detailedAddress": "sdfcsvfsdf, fdfvds, fdfvds",
|
|
||||||
"firstName": "Customer",
|
|
||||||
"lastName": "User",
|
|
||||||
"zipCode": "323232"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"profileAddresses": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"city": "fsdfcsdfcs",
|
|
||||||
"countryName": "fsdfcsdfcs",
|
|
||||||
"detailedAddress": "sdfcsvfsdf, fdfvds, fdfvds",
|
|
||||||
"zipCode": "323232"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
// refreshToken = response.data.refreshToken;
|
// refreshToken = response.data.refreshToken;
|
||||||
// startRefreshTimer(dispatch, serverTime);
|
// startRefreshTimer(dispatch, serverTime);
|
||||||
// dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
||||||
dispatch(setUserAsCompanyAdmin(false));
|
|
||||||
} else {
|
} else {
|
||||||
dispatch(loginFail(response.data));
|
dispatch(loginFail(response.data));
|
||||||
}
|
}
|
||||||
@@ -96,7 +63,7 @@ export const validateAccessToken = (token) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setUserAsCompanyAdmin = (isCompanyAdmin) => ({type: SET_COMPANY_ADMIN_FLAG, isCompanyAdmin});
|
export const setUserAsCompanyAdmin = (isCompanyAdmin) => ({ type: SET_COMPANY_ADMIN_FLAG, isCompanyAdmin });
|
||||||
|
|
||||||
export const validateCredentials = (username, password) => {
|
export const validateCredentials = (username, password) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
@@ -113,22 +80,12 @@ export const validateCredentials = (username, password) => {
|
|||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.data && response.data.token) {
|
if (response.data && response.data.token) {
|
||||||
const decodedAceessToken = jwtDecode(response.data.token);
|
const decodedAceessToken = jwtDecode(response.data.token);
|
||||||
|
|
||||||
// TODO : Uncomment code, and fix user type logic after adding customer type to woocommerce backend
|
|
||||||
|
|
||||||
// if(decodedAceessToken.data.wiaas_user_type === 'customer'){
|
|
||||||
localStorage.setItem('accessToken', response.data.token);
|
localStorage.setItem('accessToken', response.data.token);
|
||||||
localStorage.setItem('username', username);
|
localStorage.setItem('userInfo', JSON.stringify(response.data.userInfo));
|
||||||
const serverTime = decodedAceessToken.nbf || 1;
|
const serverTime = decodedAceessToken.nbf || 1;
|
||||||
// refreshToken = response.data.refreshToken;
|
|
||||||
startRefreshTimer(dispatch, serverTime);
|
startRefreshTimer(dispatch, serverTime);
|
||||||
dispatch(loggedIn(response.data));
|
dispatch(loggedIn(response.data.userInfo));
|
||||||
// dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
||||||
dispatch(setUserAsCompanyAdmin(false));
|
|
||||||
|
|
||||||
// }else{
|
|
||||||
// dispatch(loginFail({status: 'fail', errorMessage: 'INVALID_USER_TYPE'}));
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
dispatch(loginFail(response.data));
|
dispatch(loginFail(response.data));
|
||||||
}
|
}
|
||||||
@@ -145,10 +102,10 @@ const startRefreshTimer = (dispatch, serverTime) => {
|
|||||||
const tokenTimeLeft = decodedAceessToken.exp - serverTime;
|
const tokenTimeLeft = decodedAceessToken.exp - serverTime;
|
||||||
const refreshTime = tokenTimeLeft ? (tokenTimeLeft - TEN_MINUTES) * 1000 : REFRESH_TIME;
|
const refreshTime = tokenTimeLeft ? (tokenTimeLeft - TEN_MINUTES) * 1000 : REFRESH_TIME;
|
||||||
|
|
||||||
if(refreshTime <= 0){
|
if (refreshTime <= 0) {
|
||||||
dispatch(validateRefreshToken());
|
dispatch(validateRefreshToken());
|
||||||
}else{
|
} else {
|
||||||
refreshTimer = setTimeout(()=>{
|
refreshTimer = setTimeout(() => {
|
||||||
dispatch(validateRefreshToken());
|
dispatch(validateRefreshToken());
|
||||||
}, refreshTime);
|
}, refreshTime);
|
||||||
}
|
}
|
||||||
@@ -162,28 +119,28 @@ const validateRefreshToken = () => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestRefreshToken());
|
dispatch(requestRefreshToken());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/login/api/refreshToken`,
|
url: `${API_SERVER}/login/api/refreshToken`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {
|
data: {
|
||||||
refreshToken,
|
refreshToken,
|
||||||
lastActivity: authActivity.lastActivity
|
lastActivity: authActivity.lastActivity
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (response.data.status === 'success') {
|
|
||||||
localStorage.setItem('accessToken', response.data.accessToken);
|
|
||||||
const serverTime = response.data.serverTime || 1;
|
|
||||||
refreshToken = response.data.refreshToken;
|
|
||||||
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
|
||||||
startRefreshTimer(dispatch, serverTime);
|
|
||||||
} else {
|
|
||||||
dispatch(logout(response.data));
|
|
||||||
dispatch(loginFail(response.data));
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.then(response => {
|
||||||
htmlClient.onError(error, dispatch);
|
if (response.data.status === 'success') {
|
||||||
});
|
localStorage.setItem('accessToken', response.data.accessToken);
|
||||||
|
const serverTime = response.data.serverTime || 1;
|
||||||
|
refreshToken = response.data.refreshToken;
|
||||||
|
dispatch(setUserAsCompanyAdmin(response.data.userInfo.wiaas_is_company_admin));
|
||||||
|
startRefreshTimer(dispatch, serverTime);
|
||||||
|
} else {
|
||||||
|
dispatch(logout(response.data));
|
||||||
|
dispatch(loginFail(response.data));
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
htmlClient.onError(error, dispatch);
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,62 +150,62 @@ export const getModules = () => {
|
|||||||
dispatch(requestModules());
|
dispatch(requestModules());
|
||||||
let appModules = {
|
let appModules = {
|
||||||
modules: {
|
modules: {
|
||||||
modules: [
|
modules: [
|
||||||
{
|
{
|
||||||
id: '15',
|
id: '15',
|
||||||
name: 'Terms',
|
name: 'Terms',
|
||||||
menuName: 'Terms',
|
menuName: 'Terms',
|
||||||
url: 'terms',
|
url: 'terms',
|
||||||
isInMenu: '0'
|
isInMenu: '0'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '19',
|
id: '19',
|
||||||
name: 'Cart',
|
name: 'Cart',
|
||||||
menuName: 'Cart',
|
menuName: 'Cart',
|
||||||
url: 'cart',
|
url: 'cart',
|
||||||
isInMenu: '0'
|
isInMenu: '0'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '14',
|
id: '14',
|
||||||
name: 'ProfileSettings',
|
name: 'ProfileSettings',
|
||||||
menuName: 'ProfileSettings',
|
menuName: 'ProfileSettings',
|
||||||
url: 'profileSettings',
|
url: 'profileSettings',
|
||||||
isInMenu: '0'
|
isInMenu: '0'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '23',
|
id: '23',
|
||||||
name: 'OrderProjects',
|
name: 'OrderProjects',
|
||||||
menuName: 'OrderProjects',
|
menuName: 'OrderProjects',
|
||||||
url: 'orderProjects',
|
url: 'orderProjects',
|
||||||
isInMenu: '0'
|
isInMenu: '0'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '1',
|
id: '1',
|
||||||
name: 'Dashboards',
|
name: 'Dashboards',
|
||||||
menuName: 'Overview',
|
menuName: 'Overview',
|
||||||
url: 'dashboards',
|
url: 'dashboards',
|
||||||
isInMenu: '1'
|
isInMenu: '1'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: '18',
|
id: '18',
|
||||||
name: 'CoMarket',
|
name: 'CoMarket',
|
||||||
menuName: 'Co-Market',
|
menuName: 'Co-Market',
|
||||||
url: 'co-market',
|
url: 'co-market',
|
||||||
isInMenu: '1'
|
isInMenu: '1'
|
||||||
|
}
|
||||||
|
],
|
||||||
|
subModules: {
|
||||||
|
'co-market': [
|
||||||
|
{
|
||||||
|
moduleUrl: 'co-market',
|
||||||
|
menuName: 'Orders',
|
||||||
|
name: 'Orders',
|
||||||
|
url: 'orders'
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
|
||||||
subModules: {
|
|
||||||
'co-market': [
|
|
||||||
{
|
|
||||||
moduleUrl: 'co-market',
|
|
||||||
menuName: 'Orders',
|
|
||||||
name: 'Orders',
|
|
||||||
url: 'orders'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return dispatch(recieveModules(appModules));
|
return dispatch(recieveModules(appModules));
|
||||||
// return htmlClient.fetch({
|
// return htmlClient.fetch({
|
||||||
// url: `${API_SERVER}/login/api/getModules`,
|
// url: `${API_SERVER}/login/api/getModules`,
|
||||||
@@ -275,6 +232,7 @@ const recieveModules = (json) => ({
|
|||||||
|
|
||||||
export const logout = () => {
|
export const logout = () => {
|
||||||
localStorage.removeItem('accessToken');
|
localStorage.removeItem('accessToken');
|
||||||
|
localStorage.removeItem('userInfo');
|
||||||
clearInterval(refreshTimer);
|
clearInterval(refreshTimer);
|
||||||
return {
|
return {
|
||||||
type: LOGOUT,
|
type: LOGOUT,
|
||||||
@@ -283,11 +241,11 @@ export const logout = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const loggedIn = (jsonData) => {
|
export const loggedIn = (userInfo) => {
|
||||||
return {
|
return {
|
||||||
type: LOGIN_SUCCESS,
|
type: LOGIN_SUCCESS,
|
||||||
isLoggedIn: true
|
isLoggedIn: true,
|
||||||
// userInfo: jsonData.userInfo
|
userInfo: userInfo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -303,13 +261,13 @@ export const generatePassword = (mail) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestForgotPassword());
|
dispatch(requestForgotPassword());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/login/api/forgotPassword`,
|
url: `${API_SERVER}/login/api/forgotPassword`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {mail},
|
data: { mail },
|
||||||
header: {}
|
header: {}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(typeof response.data !== 'undefined' && 'messages' in response.data) {
|
if (typeof response.data !== 'undefined' && 'messages' in response.data) {
|
||||||
dispatch(forgotPasswordMessage(response.data.messages[0]));
|
dispatch(forgotPasswordMessage(response.data.messages[0]));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -319,7 +277,7 @@ export const generatePassword = (mail) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const requestForgotPassword = () => ({
|
const requestForgotPassword = () => ({
|
||||||
type: REQUEST_FORGOT_PASSWORD,
|
type: REQUEST_FORGOT_PASSWORD,
|
||||||
errorMessage: 'FORGOT_REQUEST_SENT'
|
errorMessage: 'FORGOT_REQUEST_SENT'
|
||||||
});
|
});
|
||||||
@@ -350,13 +308,13 @@ export const changePassword = (token, newPassword, confirmPassword) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestChange());
|
dispatch(requestChange());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/login/api/changePassword`,
|
url: `${API_SERVER}/login/api/changePassword`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {token, newPassword, confirmPassword},
|
data: { token, newPassword, confirmPassword },
|
||||||
header: {}
|
header: {}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data.messages && response.data.messages.length > 0){
|
if (response.data.messages && response.data.messages.length > 0) {
|
||||||
dispatch(passwordChanged(response.data.messages[0]));
|
dispatch(passwordChanged(response.data.messages[0]));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -23,8 +23,8 @@ const recieveOrderProjects = (json) => ({
|
|||||||
|
|
||||||
const generateOptions = (orderProjects) => {
|
const generateOptions = (orderProjects) => {
|
||||||
orderProjects.forEach((orderProject) => {
|
orderProjects.forEach((orderProject) => {
|
||||||
orderProject.value = orderProject.idProject;
|
orderProject.value = orderProject.id;
|
||||||
orderProject.label = orderProject.projectName;
|
orderProject.label = orderProject.name;
|
||||||
});
|
});
|
||||||
|
|
||||||
return orderProjects;
|
return orderProjects;
|
||||||
@@ -34,40 +34,18 @@ export const getOrderProjects = () => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestOrderProjects());
|
dispatch(requestOrderProjects());
|
||||||
|
|
||||||
dispatch(recieveOrderProjects(generateOptions([
|
return htmlClient.fetch({
|
||||||
{
|
url: `${API_SERVER}/wp-json/wiaas/order-projects`
|
||||||
"idProject": 1,
|
})
|
||||||
"projectName": "Innovation Center",
|
.then(response => {
|
||||||
"isAvailable": 1
|
if (response.data) {
|
||||||
},
|
const orderProjects = generateOptions(response.data);
|
||||||
{
|
dispatch(recieveOrderProjects(orderProjects));
|
||||||
"idProject": 2,
|
}
|
||||||
"projectName": "Demo01",
|
})
|
||||||
"isAvailable": 1
|
.catch(error => {
|
||||||
},
|
htmlClient.onError(error, dispatch);
|
||||||
{
|
});
|
||||||
"idProject": 3,
|
|
||||||
"projectName": "Kontorsrådet",
|
|
||||||
"isAvailable": 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"idProject": 4,
|
|
||||||
"projectName": "PerProj01",
|
|
||||||
"isAvailable": 1
|
|
||||||
}
|
|
||||||
])));
|
|
||||||
// return htmlClient.fetch({
|
|
||||||
// url: `${API_SERVER}/orderProjects/api/getOrderProjects`
|
|
||||||
// })
|
|
||||||
// .then(response => {
|
|
||||||
// if (response.data) {
|
|
||||||
// const orderProjects = generateOptions(response.data);
|
|
||||||
// dispatch(recieveOrderProjects(orderProjects));
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// htmlClient.onError(error, dispatch);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,13 +54,15 @@ const requestAddProject = () => ({
|
|||||||
isLoading: true
|
isLoading: true
|
||||||
});
|
});
|
||||||
|
|
||||||
export const addProject = (projectData) => {
|
export const addProject = (projectName) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestAddProject());
|
dispatch(requestAddProject());
|
||||||
return htmlClient.fetch({
|
return htmlClient.fetch({
|
||||||
url: `${API_SERVER}/orderProjects/api/addOrderProject`,
|
url: `${API_SERVER}/wp-json/wiaas/order-projects`,
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data: {projectData: JSON.stringify(projectData)}
|
data: {
|
||||||
|
name: projectName
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data && response.data.messages){
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import {
|
|||||||
REQUEST_SAVE_BILLING_ADDRESS,
|
REQUEST_SAVE_BILLING_ADDRESS,
|
||||||
profileTexts
|
profileTexts
|
||||||
} from '../../constants/profileSettingsConstants';
|
} from '../../constants/profileSettingsConstants';
|
||||||
import {fetchProfileInfo} from './profileSettingsActions';
|
|
||||||
import {updateMessages} from '../notification/notificationActions';
|
import {updateMessages} from '../notification/notificationActions';
|
||||||
import {setDialogOpenFlag} from '../dialog/dialogActions';
|
import {setDialogOpenFlag} from '../dialog/dialogActions';
|
||||||
|
import {recieveProfileInfo} from './profileSettingsActions';
|
||||||
|
import { fromWiaasProfileInfo } from '../../helpers/ProfileHelper';
|
||||||
|
import { toWiaasAddress } from '../../helpers/AddressHelper';
|
||||||
|
|
||||||
const client = new HtmlClient();
|
const client = new HtmlClient();
|
||||||
|
|
||||||
@@ -23,17 +25,17 @@ export const saveProfileAddress = (idUser, profileAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveAddress());
|
dispatch(requestSaveAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/profileSettings/api/saveProfileAddress`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses`,
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: {profileAddress: JSON.stringify(profileAddress)}
|
data: {
|
||||||
|
'profile_address': JSON.stringify(toWiaasAddress(profileAddress))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data){
|
||||||
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
if(response.data.messages[0].code === 'success'){
|
dispatch(setDialogOpenFlag(false));
|
||||||
dispatch(fetchProfileInfo(idUser));
|
|
||||||
dispatch(setDialogOpenFlag(false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -50,14 +52,13 @@ export const removeProfileAddress = (idUser, idProfileAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestRemoveAddress());
|
dispatch(requestRemoveAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/profileSettings/api/removeProfileAddress`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/profile-addresses/${idProfileAddress}`,
|
||||||
method: 'post',
|
method: 'delete'
|
||||||
data: {idProfileAddress}
|
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data){
|
||||||
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
dispatch(fetchProfileInfo(idUser));
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -70,21 +71,21 @@ const requestSaveBillingAddress = () => ({
|
|||||||
type: REQUEST_SAVE_BILLING_ADDRESS
|
type: REQUEST_SAVE_BILLING_ADDRESS
|
||||||
});
|
});
|
||||||
|
|
||||||
export const saveBillingAddress = (idUser, idCompany, billingAddress) => {
|
export const saveBillingAddress = (idUser, billingAddress) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveBillingAddress());
|
dispatch(requestSaveBillingAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/profileSettings/api/saveBillingAddress`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses`,
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: {idCompany, billingAddress: JSON.stringify(billingAddress)}
|
data: {
|
||||||
|
'billing_address': JSON.stringify(toWiaasAddress(billingAddress))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data){
|
||||||
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
if(response.data.messages[0].code === 'success'){
|
dispatch(setDialogOpenFlag(false));
|
||||||
dispatch(fetchProfileInfo(idUser));
|
|
||||||
dispatch(setDialogOpenFlag(false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -101,14 +102,14 @@ export const removeBillingAddress = (idUser, idBillingAddress) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestRemoveBillingAddress());
|
dispatch(requestRemoveBillingAddress());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/profileSettings/api/removeBillingAddress`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/billing-addresses/${idBillingAddress}`,
|
||||||
method: 'post',
|
method: 'delete'
|
||||||
data: {idBillingAddress}
|
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data){
|
||||||
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
dispatch(fetchProfileInfo(idUser));
|
dispatch(setDialogOpenFlag(false));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ import {
|
|||||||
profileTexts
|
profileTexts
|
||||||
} from '../../constants/profileSettingsConstants';
|
} from '../../constants/profileSettingsConstants';
|
||||||
import {updateMessages} from '../notification/notificationActions';
|
import {updateMessages} from '../notification/notificationActions';
|
||||||
|
import { fromWiaasProfileInfo} from '../../helpers/ProfileHelper';
|
||||||
|
import {fromWiaasCountryList} from '../../helpers/CountryHelper';
|
||||||
|
|
||||||
const client = new HtmlClient();
|
const client = new HtmlClient();
|
||||||
|
|
||||||
@@ -29,49 +31,15 @@ export const recieveProfileInfo = (json) => ({
|
|||||||
export const fetchProfileInfo = (idUser) => {
|
export const fetchProfileInfo = (idUser) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestProfileInfo());
|
dispatch(requestProfileInfo());
|
||||||
|
return client.fetch({
|
||||||
dispatch(recieveProfileInfo({
|
url: `${API_SERVER}/wp-json/wc/v2/customers/${idUser}`,
|
||||||
"id": 2,
|
method: 'get'
|
||||||
"name": "Customer User",
|
})
|
||||||
"mail": "customer@mail.com",
|
.then(response => {
|
||||||
"phone": "",
|
if(response.data){
|
||||||
"userType": "customer",
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data)));
|
||||||
"vatCode": "556084-6783",
|
|
||||||
"companyName": "Coor Service Management AB",
|
|
||||||
"billingAddresses": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"city": "Göteborg",
|
|
||||||
"countryName": "SE",
|
|
||||||
"detailedAddress": "Lilla Bommen 2",
|
|
||||||
"firstName": "Customer",
|
|
||||||
"lastName": "User",
|
|
||||||
"zipCode": "12323"
|
|
||||||
}
|
}
|
||||||
],
|
});
|
||||||
"profileAddresses": [
|
|
||||||
{
|
|
||||||
"id": 1,
|
|
||||||
"city": "Göteborg",
|
|
||||||
"countryName": "Göteborg",
|
|
||||||
"detailedAddress": "Lilla Bommen 2",
|
|
||||||
"zipCode": "12323"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}));
|
|
||||||
// return client.fetch({
|
|
||||||
// url: `${API_SERVER}/wp-json/wiaas/cart/customer-info`,
|
|
||||||
// method: 'get',
|
|
||||||
// data: {idUser}
|
|
||||||
// })
|
|
||||||
// .then(response => {
|
|
||||||
// if(response.data){
|
|
||||||
// dispatch(recieveProfileInfo(response.data));
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// client.onError(error, dispatch);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -82,15 +50,20 @@ const requestSaveProfile = () => ({
|
|||||||
export const saveProfileInfo = (idUser, profile) => {
|
export const saveProfileInfo = (idUser, profile) => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveProfile());
|
dispatch(requestSaveProfile());
|
||||||
|
const parsedFullName = profile.name.trim().split(' ');
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/profileSettings/api/saveProfileInfo`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/personal-info`,
|
||||||
method: 'post',
|
method: 'PUT',
|
||||||
data: {idUser, profile: JSON.stringify(profile)}
|
data: {
|
||||||
|
'first_name': parsedFullName[0],
|
||||||
|
'last_name': parsedFullName[1],
|
||||||
|
'phone': profile.phone
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data){
|
||||||
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
dispatch(fetchProfileInfo(idUser));
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -107,14 +80,17 @@ export const saveCompanyInfo = (idUser, companyInfo) => {
|
|||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestSaveCompany());
|
dispatch(requestSaveCompany());
|
||||||
return client.fetch({
|
return client.fetch({
|
||||||
url: `${API_SERVER}/profileSettings/api/saveCompanyInfo`,
|
url: `${API_SERVER}/wp-json/wiaas/customer/${idUser}/company-info`,
|
||||||
method: 'post',
|
method: 'put',
|
||||||
data: {companyInfo: JSON.stringify(companyInfo)}
|
data: {
|
||||||
|
'vat_code': companyInfo.vatCode,
|
||||||
|
'company_name': companyInfo.companyName
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if(response.data && response.data.messages){
|
if(response.data){
|
||||||
|
dispatch(recieveProfileInfo(fromWiaasProfileInfo(response.data.data)));
|
||||||
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
dispatch(updateMessages(response.data.messages, profileTexts.messages));
|
||||||
dispatch(fetchProfileInfo(idUser));
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
@@ -137,32 +113,17 @@ const recieveCountries = (json) => ({
|
|||||||
export const fetchCountries = () => {
|
export const fetchCountries = () => {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestCountries());
|
dispatch(requestCountries());
|
||||||
|
return client.fetch({
|
||||||
dispatch(recieveCountries([
|
url: `${API_SERVER}/wp-json/wiaas/user/get-countries`,
|
||||||
{
|
method: 'get'
|
||||||
"idCountry": 3,
|
})
|
||||||
"countryName": "Denmark"
|
.then(response => {
|
||||||
},
|
if(response.data){
|
||||||
{
|
dispatch(recieveCountries(response.data.map(country => fromWiaasCountryList(country))));
|
||||||
"idCountry": 4,
|
}
|
||||||
"countryName": "Finland"
|
})
|
||||||
},
|
.catch(error => {
|
||||||
{
|
client.onError(error, dispatch);
|
||||||
"idCountry": 2,
|
});
|
||||||
"countryName": "Sweden"
|
|
||||||
}
|
|
||||||
]));
|
|
||||||
// return client.fetch({
|
|
||||||
// url: `${API_SERVER}/profileSettings/api/getCoutnries`,
|
|
||||||
// method: 'get'
|
|
||||||
// })
|
|
||||||
// .then(response => {
|
|
||||||
// if(response.data){
|
|
||||||
// dispatch(recieveCountries(response.data));
|
|
||||||
// }
|
|
||||||
// })
|
|
||||||
// .catch(error => {
|
|
||||||
// client.onError(error, dispatch);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -35,7 +35,8 @@ export const profileTexts = {
|
|||||||
FIRST_NAME: 'First Name',
|
FIRST_NAME: 'First Name',
|
||||||
LAST_NAME: 'Last Name',
|
LAST_NAME: 'Last Name',
|
||||||
DELEGATE: 'Attention',
|
DELEGATE: 'Attention',
|
||||||
INVOICE_MAIL: 'Invoice Mail'
|
INVOICE_MAIL: 'Invoice Mail',
|
||||||
|
DELIVERY_MAIL: 'Delivery Mail'
|
||||||
},
|
},
|
||||||
buttons: {
|
buttons: {
|
||||||
SAVE: 'Save',
|
SAVE: 'Save',
|
||||||
@@ -56,7 +57,7 @@ export const profileTexts = {
|
|||||||
PROFILE_NOT_CHANGED: 'No changes!',
|
PROFILE_NOT_CHANGED: 'No changes!',
|
||||||
NOT_COMPANY_ADMIN: 'You are not allowed to change the company information! Contact your company admin user.',
|
NOT_COMPANY_ADMIN: 'You are not allowed to change the company information! Contact your company admin user.',
|
||||||
ADD_VAT: 'The vat code can not be empty!',
|
ADD_VAT: 'The vat code can not be empty!',
|
||||||
ADD_COPMANY_NAME: 'The company name can not be empty!',
|
ADD_COMPANY_NAME: 'The company name can not be empty!',
|
||||||
COMPANY_UPDATED: 'Company info updated!',
|
COMPANY_UPDATED: 'Company info updated!',
|
||||||
COMPANY_NOT_CHANGED: 'No changes!',
|
COMPANY_NOT_CHANGED: 'No changes!',
|
||||||
ADD_COMPANY: 'Invalid company!',
|
ADD_COMPANY: 'Invalid company!',
|
||||||
@@ -77,6 +78,7 @@ export const profileTexts = {
|
|||||||
ADD_FIRST_NAME: 'The first name field can not be empty',
|
ADD_FIRST_NAME: 'The first name field can not be empty',
|
||||||
ADD_LAST_NAME: 'The last name field can not be empty',
|
ADD_LAST_NAME: 'The last name field can not be empty',
|
||||||
ADD_INVOICE_MAIL: 'The invoice mail field can not be empty',
|
ADD_INVOICE_MAIL: 'The invoice mail field can not be empty',
|
||||||
INVALID_INVOICE_MAIL: 'Invalid invoice mail address'
|
INVALID_INVOICE_MAIL: 'Invalid invoice mail address',
|
||||||
|
INTERNAL_SERVER_ERROR: 'Error occured. Please try again'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
27
frontend/src/containers/LoaderContainer.jsx
Normal file
27
frontend/src/containers/LoaderContainer.jsx
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React, { Component } from 'react';
|
||||||
|
import { connect } from 'react-redux';
|
||||||
|
import './loaderContainer.css';
|
||||||
|
import { validateAccessToken } from '../actions/login/authActions';
|
||||||
|
import {
|
||||||
|
Col
|
||||||
|
} from 'reactstrap';
|
||||||
|
|
||||||
|
class LoaderContainer extends Component {
|
||||||
|
|
||||||
|
componentDidMount() {
|
||||||
|
if (localStorage.accessToken) {
|
||||||
|
this.props.dispatch(validateAccessToken());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Col xl="12" className="loader">
|
||||||
|
<i className="fa fa-spinner fa-spin fa-4x login-loader" aria-hidden="true"></i>
|
||||||
|
</Col>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
export default connect()(LoaderContainer);
|
||||||
@@ -45,8 +45,7 @@ class CartCustomerDetailsContainer extends Component {
|
|||||||
this.props.dispatch(fetchCartItems());
|
this.props.dispatch(fetchCartItems());
|
||||||
this.props.dispatch(setNextActionFct(this.handleNextAction));
|
this.props.dispatch(setNextActionFct(this.handleNextAction));
|
||||||
this.props.dispatch(setPrevActionFct(this.handlePrevAction));
|
this.props.dispatch(setPrevActionFct(this.handlePrevAction));
|
||||||
//this.props.dispatch(fetchProfileInfo(this.props.userInfo.wiaas_id_user));
|
this.props.dispatch(fetchProfileInfo(this.props.userInfo.wiaas_id_user));
|
||||||
this.props.dispatch(fetchProfileInfo());
|
|
||||||
this.props.dispatch(fetchCountries());
|
this.props.dispatch(fetchCountries());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +87,7 @@ class CartCustomerDetailsContainer extends Component {
|
|||||||
|
|
||||||
handleProjectChange(project){
|
handleProjectChange(project){
|
||||||
const newDetails = this.state.details;
|
const newDetails = this.state.details;
|
||||||
newDetails.idProject = project ? project.idProject : null;
|
newDetails.idProject = project ? project.id : null;
|
||||||
return this.setState({details: newDetails});
|
return this.setState({details: newDetails});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -192,7 +191,7 @@ class CartCustomerDetailsContainer extends Component {
|
|||||||
(profileInfo && !isProfileLoading) &&
|
(profileInfo && !isProfileLoading) &&
|
||||||
<ProfileAddressesContainer
|
<ProfileAddressesContainer
|
||||||
params={{location: 'cart', handleDeliveryChange: this.handleDeliveryChange, idSelectedDeliveryAddress: this.state.delivery.id}}
|
params={{location: 'cart', handleDeliveryChange: this.handleDeliveryChange, idSelectedDeliveryAddress: this.state.delivery.id}}
|
||||||
idUser={0}/>
|
idUser={this.props.userInfo.wiaas_id_user}/>
|
||||||
}
|
}
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
@@ -206,7 +205,7 @@ class CartCustomerDetailsContainer extends Component {
|
|||||||
<BillingAddressesContainer
|
<BillingAddressesContainer
|
||||||
idCompany={profileInfo.idCompany}
|
idCompany={profileInfo.idCompany}
|
||||||
params={{location: 'cart', handleBillingChange: this.handleBillingChange, idSelectedBillingAddress: this.state.billing.id}}
|
params={{location: 'cart', handleBillingChange: this.handleBillingChange, idSelectedBillingAddress: this.state.billing.id}}
|
||||||
idUser={0}/>
|
idUser={this.props.userInfo.wiaas_id_user}/>
|
||||||
}
|
}
|
||||||
</Form>
|
</Form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -37,10 +37,10 @@ class CartReviewOrderContainer extends Component {
|
|||||||
|
|
||||||
getProjectName(idProject){
|
getProjectName(idProject){
|
||||||
const selectedProject = this.props.orderProjects.find(orderProject => {
|
const selectedProject = this.props.orderProjects.find(orderProject => {
|
||||||
return orderProject.idProject === idProject
|
return orderProject.id === idProject
|
||||||
});
|
});
|
||||||
|
|
||||||
return selectedProject && selectedProject.projectName ? selectedProject.projectName : '-';
|
return selectedProject && selectedProject.name ? selectedProject.name : '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class AddOrderProject extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onProjectAdd(){
|
onProjectAdd(){
|
||||||
this.props.dispatch(addProject(this.state));
|
this.props.dispatch(addProject(this.state.projectName));
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
|||||||
@@ -21,7 +21,16 @@ class SelectDeliveryAddress extends Component {
|
|||||||
<div>
|
<div>
|
||||||
<div className="address-text">
|
<div className="address-text">
|
||||||
<Input id={'delivery-addres-check-' + profileAddress.id} checked={idSelectedDeliveryAddress === profileAddress.id} type="radio" onChange={this.handleOptionChange} name="deliveryAddress" />
|
<Input id={'delivery-addres-check-' + profileAddress.id} checked={idSelectedDeliveryAddress === profileAddress.id} type="radio" onChange={this.handleOptionChange} name="deliveryAddress" />
|
||||||
{profileAddress.countryName}, {profileAddress.city}, {profileAddress.detailedAddress}, {profileAddress.zipCode}
|
<div className="small-address-title">
|
||||||
|
{profileAddress.firstName} {profileAddress.lastName}
|
||||||
|
{
|
||||||
|
profileAddress.deliveryMail &&
|
||||||
|
<span>( {profileAddress.deliveryMail} )</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{profileAddress.countryName}, {profileAddress.city}, {profileAddress.detailedAddress}, {profileAddress.zipCode}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="address-icons">
|
<div className="address-icons">
|
||||||
<i className="fa fa-pencil control-icon edit-address-btn"
|
<i className="fa fa-pencil control-icon edit-address-btn"
|
||||||
|
|||||||
@@ -226,11 +226,6 @@
|
|||||||
.cart-address-box {
|
.cart-address-box {
|
||||||
margin-top: 2rem;
|
margin-top: 2rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
#order-projects .actions-button, .add-address-btn, .address-icons {
|
|
||||||
opacity: 0.3;
|
|
||||||
pointer-events: none;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#cart-customer-main-information-container {
|
#cart-customer-main-information-container {
|
||||||
|
|||||||
3
frontend/src/containers/loaderContainer.scss
Normal file
3
frontend/src/containers/loaderContainer.scss
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.login-loader {
|
||||||
|
padding: 100px
|
||||||
|
}
|
||||||
@@ -9,7 +9,7 @@ import {
|
|||||||
Button
|
Button
|
||||||
} from 'reactstrap';
|
} from 'reactstrap';
|
||||||
import './login.css';
|
import './login.css';
|
||||||
import {validateCredentials, validateAccessToken, generatePassword} from '../../actions/login/authActions';
|
import {validateCredentials, generatePassword} from '../../actions/login/authActions';
|
||||||
import {setDialogContent, setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
import {setDialogContent, setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
||||||
import {loginMessages, loginTexts} from '../../constants/authConstants';
|
import {loginMessages, loginTexts} from '../../constants/authConstants';
|
||||||
|
|
||||||
@@ -53,12 +53,6 @@ class LogInForm extends Component {
|
|||||||
this.props.dispatch(generatePassword(currentDialogState.inputValue));
|
this.props.dispatch(generatePassword(currentDialogState.inputValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount() {
|
|
||||||
if (localStorage.accessToken) {
|
|
||||||
this.props.dispatch(validateAccessToken(localStorage.accessToken));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
setDialogParams(dialogContent) {
|
setDialogParams(dialogContent) {
|
||||||
this.props.dispatch(setDialogOpenFlag(true));
|
this.props.dispatch(setDialogOpenFlag(true));
|
||||||
this.props.dispatch(setDialogContent(dialogContent));
|
this.props.dispatch(setDialogContent(dialogContent));
|
||||||
|
|||||||
@@ -140,9 +140,6 @@ class ProcessContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onViewChange(activeView){
|
onViewChange(activeView){
|
||||||
if(activeView === 'documents'){
|
|
||||||
this.props.dispatch(fetchOrderInfo(this.props.idOrder));
|
|
||||||
}
|
|
||||||
this.setState({activeView});
|
this.setState({activeView});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,7 +229,7 @@ class ProcessContainer extends Component {
|
|||||||
|
|
||||||
{
|
{
|
||||||
this.state.activeView === 'documents' &&
|
this.state.activeView === 'documents' &&
|
||||||
<OrderDocuments idOrder={orderInfo.id} />
|
<OrderDocuments orderDocumentsBundle={orderInfo.documents} />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,16 +5,14 @@ import {orderTexts} from '../../../constants/ordersConstants';
|
|||||||
|
|
||||||
class OrderDocuments extends Component {
|
class OrderDocuments extends Component {
|
||||||
render() {
|
render() {
|
||||||
const {orderInfo} = this.props;
|
const {orderDocumentsBundle} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div id="order-documents" className="order-documents">
|
<div id="order-documents" className="order-documents">
|
||||||
{
|
{
|
||||||
orderInfo.packages.map(orderPackage => <OrderDocumentsGroup key={'order-package-' + orderPackage.id} documentsGroup={orderPackage} />)
|
orderDocumentsBundle.map(bundle => <OrderDocumentsGroup key={'order-package-' + bundle.package.name} packageName={bundle.package.name} packageID={bundle.package.id} documents={bundle.documents} />)
|
||||||
}
|
|
||||||
{
|
|
||||||
orderInfo.orderDocuments && <OrderDocumentsGroup key={'order-package-0'} documentsGroup={{documents: orderInfo.documents, packageName: orderTexts.labels.OTHER_DOCS}} />
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,39 +40,39 @@ class OrderDocumentsGroup extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getDocumentText(document) {
|
getDocumentText(document) {
|
||||||
const name = document.documentName + '.' + document.extension;
|
const name = document.name + '.' + document.extension;
|
||||||
|
|
||||||
return name.length > 9 ? name.substring(0, 10) + '...' : name;
|
return name.length > 9 ? name.substring(0, 10) + '...' : name;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadDocument(document){
|
downloadDocument(document, packageID){
|
||||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}&fileType=${document.documentTypeName}`
|
const fileUrl = `${API_SERVER}/wp-json/wiaas/download-package-file?document_id=${document.id}&package_id=${packageID}`
|
||||||
const fileName = document.documentName + '.' + document.extension;
|
const fileName = document.name + '.' + document.extension;
|
||||||
fileHandler.download(fileUrl, fileName);
|
fileHandler.download(fileUrl, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {documentsGroup} = this.props;
|
const {documents, packageName, packageID} = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
{
|
{
|
||||||
documentsGroup.documents &&
|
documents &&
|
||||||
documentsGroup.documents.length > 0 &&
|
documents.length > 0 &&
|
||||||
<WiaasBox mainTitle={documentsGroup.packageName}>
|
<WiaasBox mainTitle={packageName}>
|
||||||
{
|
{
|
||||||
documentsGroup.documents.map(document => <a id={'document-' + document.idDocument} key={'order-document-' + document.idDocument}>
|
documents.map(document => <a id={'document-' + document.id} key={'order-document-' + document.id}>
|
||||||
<div onClick={() => {this.downloadDocument(document)}} className="document-link-big">
|
<div onClick={() => {this.downloadDocument(document, packageID)}} className="document-link-big">
|
||||||
<i className={'fa fa-4x fa-' + this.getDocumentIcon(document.extension)} aria-hidden="true"></i>
|
<i className={'fa fa-4x fa-' + this.getDocumentIcon(document.extension)} aria-hidden="true"></i>
|
||||||
<div>
|
<div>
|
||||||
{this.getDocumentText(document)}
|
{this.getDocumentText(document)}
|
||||||
<Tooltip placement="bottom"
|
<Tooltip placement="bottom"
|
||||||
delay={{ show: 0, hide: 0}}
|
delay={{ show: 0, hide: 0}}
|
||||||
container="order-documents"
|
container="order-documents"
|
||||||
isOpen={this.state[document.idDocument]}
|
isOpen={this.state[document.id]}
|
||||||
target={'document-' + document.idDocument}
|
target={'document-' + document.id}
|
||||||
toggle={()=>this.toggle(document.idDocument)}>
|
toggle={()=>this.toggle(document.id)}>
|
||||||
{document.documentName} ({document.extension})
|
{document.name} ({document.extension})
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
</div></a>)
|
</div></a>)
|
||||||
|
|||||||
@@ -22,12 +22,6 @@ class PackageInfo extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadDocument(document){
|
|
||||||
const fileUrl = `${API_SERVER}/utils/api/downloadFile?idDocument=${document.idDocument}&fileName=${document.documentName}.${document.extension}&fileType=${document.documentTypeName}`
|
|
||||||
const fileName = document.documentName + '.' + document.extension;
|
|
||||||
fileHandler.download(fileUrl, fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {orderPackage, currency, onViewChange} = this.props;
|
const {orderPackage, currency, onViewChange} = this.props;
|
||||||
const shouldShowPriceInfo = orderPackage.recurringPrice > 0 || orderPackage.servicePrice > 0;
|
const shouldShowPriceInfo = orderPackage.recurringPrice > 0 || orderPackage.servicePrice > 0;
|
||||||
@@ -122,17 +116,6 @@ class PackageInfo extends Component {
|
|||||||
}
|
}
|
||||||
</Col>
|
</Col>
|
||||||
}
|
}
|
||||||
{
|
|
||||||
orderPackage.documents &&
|
|
||||||
<Col xl="2">
|
|
||||||
<div className="subtitle"><h6>{orderTexts.labels.DOCUMENTS}:</h6></div>
|
|
||||||
{
|
|
||||||
orderPackage.documents.length > 0 ?
|
|
||||||
<div className="link-to-docs" onClick={()=>onViewChange('documents')}>{orderTexts.buttons.SEE_DOCUMENTS}</div>:
|
|
||||||
<span>{orderTexts.labels.NO_DOCUMENTS}</span>
|
|
||||||
}
|
|
||||||
</Col>
|
|
||||||
}
|
|
||||||
</Row>
|
</Row>
|
||||||
</Container>
|
</Container>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {profileTexts} from '../../constants/profileSettingsConstants';
|
|||||||
import {setDialogContent, setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
import {setDialogContent, setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
||||||
import {saveBillingAddress, removeBillingAddress} from '../../actions/profileSettings/addressActions';
|
import {saveBillingAddress, removeBillingAddress} from '../../actions/profileSettings/addressActions';
|
||||||
import './style/AddressesContainer.css';
|
import './style/AddressesContainer.css';
|
||||||
|
import { updateMessages } from '../../actions/notification/notificationActions';
|
||||||
|
|
||||||
class BillingAddressesContainer extends Component {
|
class BillingAddressesContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -21,7 +22,30 @@ class BillingAddressesContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveBillingAddress(address){
|
saveBillingAddress(address){
|
||||||
this.props.dispatch(saveBillingAddress(this.props.idUser, this.props.idCompany, address));
|
const messages = [];
|
||||||
|
if (!address.zipCode){
|
||||||
|
messages.push({
|
||||||
|
'code':'error',
|
||||||
|
'message':'ADD_ZIP'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!address.detailedAddress){
|
||||||
|
messages.push({
|
||||||
|
'code':'error',
|
||||||
|
'message':'ADD_ADDRESS'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!address.city){
|
||||||
|
messages.push({
|
||||||
|
'code':'error',
|
||||||
|
'message':'ADD_CITY'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (messages.length > 0){
|
||||||
|
this.props.dispatch(updateMessages(messages, profileTexts.messages));
|
||||||
|
}else{
|
||||||
|
this.props.dispatch(saveBillingAddress(this.props.idUser, address));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddressChange(address){
|
onAddressChange(address){
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {profileTexts} from '../../constants/profileSettingsConstants';
|
|||||||
import {setDialogContent, setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
import {setDialogContent, setDialogOpenFlag} from '../../actions/dialog/dialogActions';
|
||||||
import {saveProfileAddress, removeProfileAddress} from '../../actions/profileSettings/addressActions';
|
import {saveProfileAddress, removeProfileAddress} from '../../actions/profileSettings/addressActions';
|
||||||
import './style/AddressesContainer.css';
|
import './style/AddressesContainer.css';
|
||||||
|
import { updateMessages } from '../../actions/notification/notificationActions';
|
||||||
|
|
||||||
class ProfileAddressesContainer extends Component {
|
class ProfileAddressesContainer extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -21,7 +22,30 @@ class ProfileAddressesContainer extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
saveProfileAddress(profileAddress){
|
saveProfileAddress(profileAddress){
|
||||||
this.props.dispatch(saveProfileAddress(this.props.idUser, profileAddress));
|
const messages = [];
|
||||||
|
if (!profileAddress.zipCode){
|
||||||
|
messages.push({
|
||||||
|
'code':'error',
|
||||||
|
'message':'ADD_ZIP'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!profileAddress.detailedAddress){
|
||||||
|
messages.push({
|
||||||
|
'code':'error',
|
||||||
|
'message':'ADD_ADDRESS'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!profileAddress.city){
|
||||||
|
messages.push({
|
||||||
|
'code':'error',
|
||||||
|
'message':'ADD_CITY'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (messages.length > 0){
|
||||||
|
this.props.dispatch(updateMessages(messages, profileTexts.messages));
|
||||||
|
}else{
|
||||||
|
this.props.dispatch(saveProfileAddress(this.props.idUser, profileAddress));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onAddressChange(address){
|
onAddressChange(address){
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Label for="address-first-name">{profileTexts.labels.FIRST_NAME}</Label>
|
<Label for="address-first-name">{profileTexts.labels.FIRST_NAME}</Label>
|
||||||
<Input value={firstName}
|
<Input value={firstName}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="text"
|
type="text"
|
||||||
name="firstName"
|
name="firstName"
|
||||||
id="address-first-name"
|
id="address-first-name"
|
||||||
@@ -52,6 +53,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Label for="address-last-name">{profileTexts.labels.LAST_NAME}</Label>
|
<Label for="address-last-name">{profileTexts.labels.LAST_NAME}</Label>
|
||||||
<Input value={lastName}
|
<Input value={lastName}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="text"
|
type="text"
|
||||||
name="lastName"
|
name="lastName"
|
||||||
id="address-last-name"
|
id="address-last-name"
|
||||||
@@ -62,6 +64,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Label for="address-invoice-mail">{profileTexts.labels.INVOICE_MAIL}</Label>
|
<Label for="address-invoice-mail">{profileTexts.labels.INVOICE_MAIL}</Label>
|
||||||
<Input value={invoiceMail}
|
<Input value={invoiceMail}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="text"
|
type="text"
|
||||||
name="invoiceMail"
|
name="invoiceMail"
|
||||||
id="address-invoice-mail"
|
id="address-invoice-mail"
|
||||||
@@ -74,6 +77,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Input value={idCountrySelected}
|
<Input value={idCountrySelected}
|
||||||
type="select"
|
type="select"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
name="idCountrySelected"
|
name="idCountrySelected"
|
||||||
id="address-country"
|
id="address-country"
|
||||||
placeholder={profileTexts.labels.ADDRESS_COUNTRY}>
|
placeholder={profileTexts.labels.ADDRESS_COUNTRY}>
|
||||||
@@ -89,6 +93,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Label for="address-city">{profileTexts.labels.ADDRESS_CITY}<span className="required-icon">*</span></Label>
|
<Label for="address-city">{profileTexts.labels.ADDRESS_CITY}<span className="required-icon">*</span></Label>
|
||||||
<Input value={city}
|
<Input value={city}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="text"
|
type="text"
|
||||||
name="city"
|
name="city"
|
||||||
id="address-city"
|
id="address-city"
|
||||||
@@ -99,6 +104,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Label for="address-details">{profileTexts.labels.ADDRESS_DETAILS}<span className="required-icon">*</span></Label>
|
<Label for="address-details">{profileTexts.labels.ADDRESS_DETAILS}<span className="required-icon">*</span></Label>
|
||||||
<Input value={detailedAddress}
|
<Input value={detailedAddress}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="textarea"
|
type="textarea"
|
||||||
name="detailedAddress"
|
name="detailedAddress"
|
||||||
id="address-details"
|
id="address-details"
|
||||||
@@ -109,6 +115,7 @@ class AddEditBillingAddress extends Component {
|
|||||||
<Label for="address-zip">{profileTexts.labels.ADDRESS_ZIP}<span className="required-icon">*</span></Label>
|
<Label for="address-zip">{profileTexts.labels.ADDRESS_ZIP}<span className="required-icon">*</span></Label>
|
||||||
<Input value={zipCode}
|
<Input value={zipCode}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="text"
|
type="text"
|
||||||
name="zipCode"
|
name="zipCode"
|
||||||
id="address-zip"
|
id="address-zip"
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ class AddEditProfileAddress extends Component {
|
|||||||
idCountrySelected: address.idCountrySelected || this.props.params.countries[0].idCountry,
|
idCountrySelected: address.idCountrySelected || this.props.params.countries[0].idCountry,
|
||||||
city: address.city || '',
|
city: address.city || '',
|
||||||
detailedAddress: address.detailedAddress || '',
|
detailedAddress: address.detailedAddress || '',
|
||||||
zipCode: address.zipCode || ''
|
zipCode: address.zipCode || '',
|
||||||
|
firstName: address.firstName || '',
|
||||||
|
lastName: address.lastName || '',
|
||||||
|
deliveryMail: address.deliveryMail || ''
|
||||||
};
|
};
|
||||||
this.props.params.onAddressChange(this.state);
|
this.props.params.onAddressChange(this.state);
|
||||||
|
|
||||||
@@ -30,16 +33,52 @@ class AddEditProfileAddress extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const {idCountrySelected, city, detailedAddress, zipCode} = this.state;
|
const {idCountrySelected, city, detailedAddress, zipCode, firstName, lastName, deliveryMail} = this.state;
|
||||||
const {countries} = this.props.params;
|
const {countries} = this.props.params;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="address-add-edit-content">
|
<div className="address-add-edit-content">
|
||||||
<Form className="address-edit-content">
|
<Form className="address-edit-content">
|
||||||
|
<h5>{profileTexts.labels.DELEGATE}</h5>
|
||||||
|
<FormGroup>
|
||||||
|
<Label for="address-first-name">{profileTexts.labels.FIRST_NAME}</Label>
|
||||||
|
<Input value={firstName}
|
||||||
|
autoComplete="nope"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
type="text"
|
||||||
|
name="firstName"
|
||||||
|
id="address-first-name"
|
||||||
|
placeholder={profileTexts.labels.FIRST_NAME} />
|
||||||
|
</FormGroup>
|
||||||
|
|
||||||
|
<FormGroup>
|
||||||
|
<Label for="address-last-name">{profileTexts.labels.LAST_NAME}</Label>
|
||||||
|
<Input value={lastName}
|
||||||
|
autoComplete="nope"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
type="text"
|
||||||
|
name="lastName"
|
||||||
|
id="address-last-name"
|
||||||
|
placeholder={profileTexts.labels.LAST_NAME} />
|
||||||
|
</FormGroup>
|
||||||
|
|
||||||
|
<FormGroup>
|
||||||
|
<Label for="address-delivery-mail">{profileTexts.labels.DELIVERY_MAIL}</Label>
|
||||||
|
<Input value={deliveryMail}
|
||||||
|
autoComplete="nope"
|
||||||
|
onChange={this.handleChange}
|
||||||
|
type="text"
|
||||||
|
name="deliveryMail"
|
||||||
|
id="address-delivery-mail"
|
||||||
|
placeholder={profileTexts.labels.DELIVERY_MAIL} />
|
||||||
|
</FormGroup>
|
||||||
|
|
||||||
|
<h5>{profileTexts.labels.BILLING_ADDRESSES}</h5>
|
||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Label for="address-country">{profileTexts.labels.ADDRESS_COUNTRY}<span className="required-icon">*</span></Label>
|
<Label for="address-country">{profileTexts.labels.ADDRESS_COUNTRY}<span className="required-icon">*</span></Label>
|
||||||
<Input value={idCountrySelected}
|
<Input value={idCountrySelected}
|
||||||
type="select"
|
type="select"
|
||||||
|
autoComplete="nope"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
name="idCountrySelected"
|
name="idCountrySelected"
|
||||||
id="address-country"
|
id="address-country"
|
||||||
@@ -56,6 +95,7 @@ class AddEditProfileAddress extends Component {
|
|||||||
<Label for="address-city">{profileTexts.labels.ADDRESS_CITY}<span className="required-icon">*</span></Label>
|
<Label for="address-city">{profileTexts.labels.ADDRESS_CITY}<span className="required-icon">*</span></Label>
|
||||||
<Input value={city}
|
<Input value={city}
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
|
autoComplete="nope"
|
||||||
type="text"
|
type="text"
|
||||||
name="city"
|
name="city"
|
||||||
id="address-city"
|
id="address-city"
|
||||||
@@ -65,6 +105,7 @@ class AddEditProfileAddress extends Component {
|
|||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Label for="address-details">{profileTexts.labels.ADDRESS_DETAILS}<span className="required-icon">*</span></Label>
|
<Label for="address-details">{profileTexts.labels.ADDRESS_DETAILS}<span className="required-icon">*</span></Label>
|
||||||
<Input value={detailedAddress}
|
<Input value={detailedAddress}
|
||||||
|
autoComplete="nope"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
type="textarea"
|
type="textarea"
|
||||||
name="detailedAddress"
|
name="detailedAddress"
|
||||||
@@ -75,6 +116,7 @@ class AddEditProfileAddress extends Component {
|
|||||||
<FormGroup>
|
<FormGroup>
|
||||||
<Label for="address-zip">{profileTexts.labels.ADDRESS_ZIP}<span className="required-icon">*</span></Label>
|
<Label for="address-zip">{profileTexts.labels.ADDRESS_ZIP}<span className="required-icon">*</span></Label>
|
||||||
<Input value={zipCode}
|
<Input value={zipCode}
|
||||||
|
autoComplete="nope"
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
type="text"
|
type="text"
|
||||||
name="zipCode"
|
name="zipCode"
|
||||||
|
|||||||
@@ -8,7 +8,16 @@ class ProfileAddress extends Component {
|
|||||||
return (
|
return (
|
||||||
<div className="address-row">
|
<div className="address-row">
|
||||||
<div className="address-text">
|
<div className="address-text">
|
||||||
{profileAddress.countryName}, {profileAddress.city}, {profileAddress.detailedAddress}, {profileAddress.zipCode}
|
<div className="small-address-title">
|
||||||
|
{profileAddress.firstName} {profileAddress.lastName}
|
||||||
|
{
|
||||||
|
profileAddress.deliveryMail &&
|
||||||
|
<span>( {profileAddress.deliveryMail} )</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
{profileAddress.countryName}, {profileAddress.city}, {profileAddress.detailedAddress}, {profileAddress.zipCode}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="address-icons">
|
<div className="address-icons">
|
||||||
<i className="fa fa-pencil control-icon edit-address-btn"
|
<i className="fa fa-pencil control-icon edit-address-btn"
|
||||||
|
|||||||
29
frontend/src/helpers/AddressHelper.js
Normal file
29
frontend/src/helpers/AddressHelper.js
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
export const fromWiaasAddress = (address) => {
|
||||||
|
return {
|
||||||
|
id: address.id,
|
||||||
|
countryName: address.country_name,
|
||||||
|
deliveryMail: address.delivery_mail,
|
||||||
|
idCountrySelected: address.id_country_selected,
|
||||||
|
city: address.city,
|
||||||
|
detailedAddress: address.detailed_address,
|
||||||
|
zipCode: address.zip_code,
|
||||||
|
firstName: address.first_name,
|
||||||
|
lastName: address.lastName,
|
||||||
|
invoiceMail: address.invoice_mail
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export const toWiaasAddress = (address) => {
|
||||||
|
return {
|
||||||
|
id: address.id,
|
||||||
|
country_name: address.countryName,
|
||||||
|
delivery_mail: address.deliveryMail,
|
||||||
|
id_country_selected: address.idCountrySelected,
|
||||||
|
city: address.city,
|
||||||
|
detailed_address: address.detailedAddress,
|
||||||
|
zip_code: address.zipCode,
|
||||||
|
first_name: address.firstName,
|
||||||
|
last_name: address.lastName,
|
||||||
|
invoice_mail: address.invoiceMail
|
||||||
|
}
|
||||||
|
};
|
||||||
55
frontend/src/helpers/CartHelper.js
Normal file
55
frontend/src/helpers/CartHelper.js
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
|
||||||
|
export const fromWCCartItems = wcCartItem => {
|
||||||
|
const paymentInfo = wcCartItem['payment_info'] || {};
|
||||||
|
const totalPrices = wcCartItem['total_prices'] || {};
|
||||||
|
|
||||||
|
return {
|
||||||
|
idPackage: wcCartItem['package_id'],
|
||||||
|
key: wcCartItem.key,
|
||||||
|
packageName: wcCartItem['package_name'],
|
||||||
|
quantity: wcCartItem.quantity,
|
||||||
|
|
||||||
|
idCommercialLead: wcCartItem['commercial_lead_id'],
|
||||||
|
commercialLead: wcCartItem['commercial_lead'],
|
||||||
|
country: wcCartItem.country ? wcCartItem.country : [],
|
||||||
|
|
||||||
|
areAdditionalAvailable: wcCartItem['are_additional_available'],
|
||||||
|
additionalPackages: wcCartItem['additional_packages'] ? wcCartItem['additional_packages'].map(additionalPackageItem => ({
|
||||||
|
idAdditionalPackage: additionalPackageItem['package_id'],
|
||||||
|
packageName: additionalPackageItem['package_name'],
|
||||||
|
prices: {
|
||||||
|
fixedExtra: additionalPackageItem['prices'] ? additionalPackageItem['prices']['fixed_extra'] : 0,
|
||||||
|
recurrentExtra: additionalPackageItem['prices'] ? additionalPackageItem['prices']['recurrent_extra'] : 0,
|
||||||
|
servicesExtra: additionalPackageItem['prices'] ? additionalPackageItem['prices']['services_extra'] : 0,
|
||||||
|
}
|
||||||
|
})) : [],
|
||||||
|
|
||||||
|
areOptionsAvailable: wcCartItem['are_options_available'],
|
||||||
|
options: wcCartItem.options ? wcCartItem.options.map(optionPackageItem => ({
|
||||||
|
idOptionPackage: optionPackageItem['package_id'],
|
||||||
|
packageName: optionPackageItem['package_name'],
|
||||||
|
groupName: optionPackageItem['group_name'],
|
||||||
|
prices: {
|
||||||
|
fixedExtra: optionPackageItem['prices'] ? optionPackageItem['prices']['fixed_extra'] : 0,
|
||||||
|
recurrentExtra: optionPackageItem['prices'] ? optionPackageItem['prices']['recurrent_extra'] : 0,
|
||||||
|
servicesExtra: optionPackageItem['prices'] ? optionPackageItem['prices']['services_extra'] : 0,
|
||||||
|
}
|
||||||
|
})) : [],
|
||||||
|
|
||||||
|
bids: wcCartItem.bids,
|
||||||
|
|
||||||
|
idPayType: paymentInfo.id,
|
||||||
|
payType: paymentInfo.type,
|
||||||
|
periodUnit: paymentInfo['period_unit'] || 'month',
|
||||||
|
idPrice: paymentInfo.id,
|
||||||
|
fixedPrice: paymentInfo['fixed_extra'] !== undefined ? paymentInfo['fixed_extra'] : 0,
|
||||||
|
recurrentPrice: paymentInfo['recurrent_extra'] !== undefined ? paymentInfo['recurrent_extra'] : 0,
|
||||||
|
servicesPrice: paymentInfo['services_extra'] !== undefined ? paymentInfo['services_extra'] : 0,
|
||||||
|
|
||||||
|
totalPrices: {
|
||||||
|
fixedPrice: totalPrices['fixed_extra'] !== undefined ? totalPrices['fixed_extra'] : 0,
|
||||||
|
recurrentPrice: totalPrices['recurrent_extra'] !== undefined ? totalPrices['recurrent_extra'] : 0,
|
||||||
|
servicesPrice: totalPrices['services_extra'] !== undefined ? totalPrices['services_extra'] : 0,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
||||||
6
frontend/src/helpers/CountryHelper.js
Normal file
6
frontend/src/helpers/CountryHelper.js
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
export const fromWiaasCountryList = (countryList) => {
|
||||||
|
return {
|
||||||
|
idCountry: countryList.country_id,
|
||||||
|
countryName: countryList.country_name
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,6 +60,24 @@ class HtmlClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onError(error) {
|
onError(error) {
|
||||||
|
const response = error.response;
|
||||||
|
if (response && response.data && response.data.code) {
|
||||||
|
switch (response.data.code) {
|
||||||
|
case 'rest_missing_callback_param':
|
||||||
|
store.dispatch(updateMessages([{code:'error', message: response.data.message }]));
|
||||||
|
return;
|
||||||
|
case 'rest_invalid_param':
|
||||||
|
const messages = Object.keys(response.data.data.params).map(paramName => {
|
||||||
|
const errorMessage = response.data.data.params[paramName];
|
||||||
|
if (errorMessage === 'Invalid parameter.') {
|
||||||
|
return { code: 'error', message: `Invalid ${paramName} parameter!` };
|
||||||
|
}
|
||||||
|
return { code: 'error', message: errorMessage };
|
||||||
|
});
|
||||||
|
store.dispatch(updateMessages(messages));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
store.dispatch(updateMessages([{code:'error', message: 'HTML_ERROR'}], notificationMessages));
|
store.dispatch(updateMessages([{code:'error', message: 'HTML_ERROR'}], notificationMessages));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
dateCreated: formatDate(WCOrder['date_created']),
|
dateCreated: formatDate(WCOrder['date_created']),
|
||||||
dateCompleted: formatDate(WCOrder['date_completed']),
|
dateCompleted: formatDate(WCOrder['date_completed']),
|
||||||
estimatedDeliveryDate: undefined,
|
estimatedDeliveryDate: undefined,
|
||||||
|
vatCode: WCOrder['vat'],
|
||||||
reference: WCOrder['reference'],
|
reference: WCOrder['reference'],
|
||||||
|
tender: WCOrder['tender'],
|
||||||
|
companyName: WCOrder['company_name'],
|
||||||
|
projectName: WCOrder['project_name'],
|
||||||
assignedTo: 'assigned to',
|
assignedTo: 'assigned to',
|
||||||
fixedPrice: WCOrder.total,
|
fixedPrice: WCOrder.total,
|
||||||
recurringPrice: WCOrder['recurring_price'],
|
recurringPrice: WCOrder['recurring_price'],
|
||||||
@@ -33,6 +37,7 @@ export const fromWCOrder = (WCOrder) => {
|
|||||||
email: WCOrder.billing.email,
|
email: WCOrder.billing.email,
|
||||||
address: formatAddress(WCOrder.billing)
|
address: formatAddress(WCOrder.billing)
|
||||||
},
|
},
|
||||||
|
documents: WCOrder.documents,
|
||||||
packages: WCOrder['line_items'].map(packageLine => {
|
packages: WCOrder['line_items'].map(packageLine => {
|
||||||
return {
|
return {
|
||||||
id: packageLine['product_id'],
|
id: packageLine['product_id'],
|
||||||
|
|||||||
17
frontend/src/helpers/ProfileHelper.js
Normal file
17
frontend/src/helpers/ProfileHelper.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import { fromWiaasAddress } from "./AddressHelper";
|
||||||
|
|
||||||
|
export const fromWiaasProfileInfo = (profileInfo) => {
|
||||||
|
return {
|
||||||
|
id: profileInfo.id,
|
||||||
|
idCompany: profileInfo.company_id,
|
||||||
|
companyName: profileInfo.company_name,
|
||||||
|
vatCode: profileInfo.vat_code,
|
||||||
|
isCompanyAdmin: profileInfo.is_company_admin,
|
||||||
|
mail: profileInfo.mail,
|
||||||
|
name: profileInfo.name,
|
||||||
|
phone: profileInfo.phone,
|
||||||
|
billingAddresses: profileInfo.billing_addresses.map(address => fromWiaasAddress(address)),
|
||||||
|
profileAddresses: profileInfo.profile_addresses.map(address => fromWiaasAddress(address)),
|
||||||
|
userType: profileInfo.user_type,
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user