Handle additional orders info for wiaas

This commit is contained in:
Almira Krdzic
2018-08-09 12:20:20 +02:00
46 changed files with 381 additions and 364 deletions

View File

@@ -65,4 +65,4 @@ COPY docker/php/.htaccess /var/www/html/
RUN chown -R www-data:www-data /var/www/html
CMD /init-scripts/setup.sh
CMD /init-scripts/setup.sh

13
backend/.htaccess Normal file
View File

@@ -0,0 +1,13 @@
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
</IfModule>
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
# END WordPress

View File

@@ -51,10 +51,10 @@ class Wiass_REST_Delivery_Process_API {
foreach ($entries as $entry) {
$step = gravity_flow()->get_step( $entry['workflow_step'] );
$data[] = array(
'idOrder' => $entry['wiaas_delivery_order_id'],
'orderNumber' => $entry['wiaas_delivery_order_id'],
'order_id' => $entry['wiaas_delivery_order_id'],
'order_number' => $entry['wiaas_delivery_order_id'],
'status' => $entry['workflow_final_status'],
'stepAction' => $step->get_name(),
'step_action' => $step->get_name(),
);
}

View File

@@ -1,25 +0,0 @@
<?php
/**
* Class Wiaas_Customer
*
* Handler integration of Wiaas customer with Woocommerce customer
*/
class Wiaas_Customer {
public static function init() {
add_action('woocommerce_new_customer', array(__CLASS__, 'append_customer_info'));
}
/**
* Appends Wiaas customer info (name, phone)
*
* For now we will generate these, but later will be added to the interface
*/
public static function append_customer_info($customer_id) {
update_user_meta($customer_id, 'wiaas_customer_name', 'Wiaas Customer');
update_user_meta($customer_id, 'wiaas_customer_phone', '+46 (10) 5595148');
}
}
Wiaas_Customer::init();

View File

@@ -8,7 +8,7 @@ class Wiaas_DB_Update {
'20180728222206' => 'wiaas_db_update_enable_product_by_user_role',
'20180801222206' => 'wiaas_db_update_setup_gravity',
'20180802222206' => 'wiaas_db_update_add_delivery_process_forms',
'20180808222206' => 'wiaas_db_update_setup_customer_capabilities'
'20180807222206' => 'wiaas_db_update_setup_customer_capabilities'
);
public static function execute() {

View File

@@ -159,4 +159,4 @@ class Wiaas_Delivery_Process {
}
}
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );
add_action( 'gravityflow_loaded', array('Wiaas_Delivery_Process', 'init') );

View File

@@ -10,18 +10,27 @@ class Wiaas_Order {
private static $object_order_type = 'shop_order';
private static $wiaas_order_status = array(
);
public static function init() {
add_filter('woocommerce_rest_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3);
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_prepare_shop_order_object', array(__CLASS__, 'transform_rest_order'), 10, 3);
add_filter('woocommerce_rest_orders_prepare_object_query', array( __CLASS__, 'wiaas_prepare_rest_orders_query'), 10, 2);
add_filter('wc_order_statuses', array( __CLASS__, 'wiaas_order_statuses'));
}
/**
* Assignees order to corresponding user organization when order is created.
*
* @param $order_id
*/
public static function assign_order_to_organization($order_id) {
$user = wp_get_current_user();
Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID);
}
/**
* Checks if current user has access to requested order/{orderId} via woocommerce REST API.
@@ -37,25 +46,36 @@ class Wiaas_Order {
* @return bool
*/
public static function check_order_access($permission, $context, $object_id, $post_type) {
if ($post_type === 'shop_order' && $object_id !== 0) {
if ($post_type === self::$object_order_type && $object_id !== 0) {
return Groups_Post_Access::user_can_read_post($object_id);
}
#return Groups_Post_Access::user_can_read_post($object_id);
return $permission;
}
/**
* Assignees order to corresponding user organization when order is created.
* Handles custom wiaas arguments to woocommerce orders api endpoint `wc/v2/orders`
* @param $args
* @param $request
*
* @param $order_id
* @return mixed
*/
public static function assign_order_to_organization($order_id) {
$user = wp_get_current_user();
Wiaas_User_Organization::assign_post_to_user_organization($order_id, $user->ID);
public static function wiaas_prepare_rest_orders_query($args, $request) {
# Handle wiaas_is_active flag
if (isset($request['wiaas_is_active'])) {
if ($request['wiaas_is_active'] === '1') {
$args['post_status'] = array('wc-open', 'wc-processing');
}
if ($request['wiaas_is_active'] === '0') {
$args['post_status'] = array('wc-completed', 'wc-cancelled');
}
}
return $args;
}
/**
* Apply wiaas custome tranformation on retrieved JSON order object
* Apply wiaas custom transformation on retrieved JSON order object
*
* @param $response
* @param $order
@@ -66,15 +86,6 @@ class Wiaas_Order {
public static function transform_rest_order($response, $order, $request) {
$data = $response->get_data();
$is_customer = wcj_is_user_role('customer');
if ($is_customer || true) {
// Format date values.
$data['date_created'] = self::_format_order_date($order->get_date_created());
$data['date_modified'] = self::_format_order_date($order->get_date_modified());
$data['date_completed'] = self::_format_order_date($order->get_date_completed());
}
# apply overrides
$data = self::_append_products_info($data, $order, $request);
@@ -89,6 +100,18 @@ class Wiaas_Order {
return $response;
}
/**
* PRIVATE
*/
/**
* Appends additional wiaas customer lead info to order json response
* @param $data
* @param $order
* @param $request
*
* @return mixed
*/
private static function _append_commercial_lead_info($data, $order, $request) {
$data['commercial_lead'] = array(
@@ -100,20 +123,40 @@ class Wiaas_Order {
return $data;
}
/**
* Appends additional wiaas customer info to order json response
* @param $data
* @param $order
* @param $request
*
* @return mixed
*/
private static function _append_customer_info($data, $order, $request) {
$current_user = wp_get_current_user();
$customer_id = $data['customer_id'];
$customer_user = get_user_by('id', $customer_id);
$data['customer'] = array(
'email' => $customer_user->user_email,
'name' => $customer_user->display_name,
'phone' => get_user_meta($customer_id, 'wiaas_customer_phone', true)
'phone' => '+46 (10) 5595148'
);
$data['is_my_order'] = $customer_id === $current_user->ID;
return $data;
}
/**
* Appends additional wiaas products info to order json response
* @param $data
* @param $order
* @param $request
*
* @return mixed
*/
private static function _append_products_info($data, $order, $request) {
foreach ($data['line_items'] as $index => $product_line) {
# lock all products to `Purchase` payment type
@@ -130,7 +173,13 @@ class Wiaas_Order {
$product_line['pay_period'] = 0;
# collect status from order
$product_line['status'] = $data['status'];
if ($data['status'] === 'completed') {
$product_line['status'] = 'production';
} else if ($data['status'] === 'cancelled') {
$product_line['status'] = 'cancelled';
} else {
$product_line['status'] = 'processing';
}
$product_line['short_desc'] = $product_line['status'];
# collect completion data from order
@@ -158,12 +207,6 @@ class Wiaas_Order {
return $data;
}
private static function _format_order_date($date) {
$date = new WC_DateTime( $date, new DateTimeZone( 'UTC' ) );
$date->setTimezone( new DateTimeZone( wc_timezone_string() ) );
return gmdate('jS F, Y', $date->getTimestamp());
}
}
Wiaas_Order::init();

View File

@@ -1,19 +1,29 @@
<?php
add_action('init', 'wiaas_load_user_organization');
defined( 'ABSPATH' ) || exit;
function wiaas_load_user_organization() {
if (class_exists('WP_User_Taxonomy')) {
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
/**
* Class Wiaas_User
*/
class Wiaas_User {
new Wiaas_User_Organization();
public static function init() {
add_action('init', array(__CLASS__, 'load_user_organization'));
add_action('plugins_loaded', array(__CLASS__, 'remove_default_user_groups'), 30);
}
public static function load_user_organization() {
if (class_exists('WP_User_Taxonomy')) {
require_once dirname( __FILE__ ) . '/user/class-wiaas-user-organization.php';
new Wiaas_User_Organization();
}
}
public static function remove_default_user_groups() {
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
}
}
add_action('plugins_loaded', 'remove_default_user_groups', 30);
function remove_default_user_groups() {
remove_action( 'init', 'wp_register_default_user_group_taxonomy' );
remove_action( 'init', 'wp_register_default_user_type_taxonomy' );
}
Wiaas_User::init();

View File

@@ -78,10 +78,9 @@ function wiaas_db_update_add_delivery_process_forms() {
do_action('gform_forms_post_import', $created_forms);
}
function wiaas_db_update_setup_customer_capabilities() {
$customer_role = get_role('customer');
$customer_role = get_role('customer');
$customer_role->add_cap('read_private_shop_orders');
$customer_role->add_cap('read_shop_order');
$customer_role->add_cap('read_private_shop_orders');
$customer_role->add_cap('read_shop_order');
}

View File

@@ -246,4 +246,4 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
return absint($value);
}
}
}

View File

@@ -42,14 +42,14 @@ class Wiass_REST_Delivery_Process_Api_Test extends Wiaas_Unit_Test_Case {
$this->assertTrue(is_array($pending_step));
$this->assertArrayHasKey('idOrder', $pending_step);
$this->assertArrayHasKey('orderNumber', $pending_step);
$this->assertArrayHasKey('order_id', $pending_step);
$this->assertArrayHasKey('order_number', $pending_step);
$this->assertArrayHasKey('status', $pending_step);
$this->assertArrayHasKey('stepAction', $pending_step);
$this->assertArrayHasKey('step_action', $pending_step);
$this->assertEquals($pending_step['idOrder'], $this->order_id);
$this->assertEquals($pending_step['orderNumber'], $this->order_id);
$this->assertEquals($pending_step['order_id'], $this->order_id);
$this->assertEquals($pending_step['order_number'], $this->order_id);
$this->assertEquals($pending_step['status'], 'pending');
$this->assertNotEmpty($pending_step['stepAction']);
$this->assertNotEmpty($pending_step['step_action']);
}
}

View File

@@ -26,8 +26,6 @@ include_once WIAAS_DIR . '/includes/class-wiaas-delivery-process.php';
include_once WIAAS_DIR . '/includes/class-wiaas-order.php';
include_once WIAAS_DIR . '/includes/class-wiaas-customer.php';
include_once WIAAS_DIR . '/includes/class-wiaas-user.php';
include_once WIAAS_DIR . '/includes/class-wiaas-api.php';

View File

@@ -29,18 +29,6 @@
"reference": "origin/master"
}
}
},
{
"type": "package",
"package": {
"name": "3rdparty/woocommerce-product-vendors",
"type": "wordpress-plugin",
"version": "2.0.27",
"dist": {
"url": "https://github.com/wp-premium/woocommerce-product-vendors/archive/2.0.27.zip",
"type": "zip"
}
}
}
],
"require": {
@@ -59,10 +47,8 @@
"wpackagist-plugin/mailchimp-for-woocommerce": "2.1.7",
"wpackagist-plugin/woocommerce-gateway-paypal-express-checkout": "1.5.6",
"wpackagist-plugin/jwt-authentication-for-wp-rest-api": "1.2.4",
"wpackagist-plugin/woo-product-bundle": "3.1.2",
"wpackagist-plugin/capability-manager-enhanced": "1.5.9",
"wpackagist-plugin/wp-user-groups": "2.2.0",
"3rdparty/woocommerce-product-vendors": "*",
"3rdparty/gravityforms": "*",
"3rdparty/gravityflow": "*"
@@ -91,8 +77,8 @@
"wp plugin activate jwt-authentication-for-wp-rest-api",
"wp plugin activate gravityforms",
"wp plugin activate gravityflow",
"wp plugin activate woo-product-bundle",
"wp plugin activate capability-manager-enhanced",
"wp plugin activate groups",
"wp plugin activate wp-user-groups",
"wp plugin activate wiaas"
],

33
backend/composer.lock generated
View File

@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "21ce04695bffdbca2f33154b291dd1dd",
"content-hash": "798e9b8b675248e2b8dbc2bc7dcab511",
"packages": [
{
"name": "3rdparty/gravityflow",
@@ -26,17 +26,6 @@
},
"type": "wordpress-plugin"
},
{
"name": "3rdparty/woocommerce-product-vendors",
"version": "2.0.27",
"dist": {
"type": "zip",
"url": "https://github.com/wp-premium/woocommerce-product-vendors/archive/2.0.27.zip",
"reference": null,
"shasum": null
},
"type": "wordpress-plugin"
},
{
"name": "composer/installers",
"version": "v1.5.0",
@@ -568,26 +557,6 @@
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/mailchimp-for-woocommerce/"
},
{
"name": "wpackagist-plugin/woo-product-bundle",
"version": "3.1.2",
"source": {
"type": "svn",
"url": "https://plugins.svn.wordpress.org/woo-product-bundle/",
"reference": "trunk"
},
"dist": {
"type": "zip",
"url": "https://downloads.wordpress.org/plugin/woo-product-bundle.zip?timestamp=1533003376",
"reference": null,
"shasum": null
},
"require": {
"composer/installers": "~1.0"
},
"type": "wordpress-plugin",
"homepage": "https://wordpress.org/plugins/woo-product-bundle/"
},
{
"name": "wpackagist-plugin/woocommerce-gateway-paypal-express-checkout",
"version": "1.5.6",

View File

@@ -23,16 +23,6 @@ if (file_exists($env_config)) {
require_once $env_config;
}
/**
* Stops redirect loop on login page
*/
define('FORCE_SSL_ADMIN', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';
/**
* URLs
*/

View File

@@ -5,3 +5,13 @@ define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
/** Disable all file modifications including updates and update notifications */
define('DISALLOW_FILE_MODS', true);
/**
* Stops redirect loop on login page
*/
define('FORCE_SSL_ADMIN', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

View File

@@ -5,3 +5,13 @@ define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', false);
/** Disable all file modifications including updates and update notifications */
define('DISALLOW_FILE_MODS', true);
/**
* Stops redirect loop on login page
*/
define('FORCE_SSL_ADMIN', true);
// in some setups HTTP_X_FORWARDED_PROTO might contain
// a comma-separated list e.g. http,https
// so check for https existence
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false)
$_SERVER['HTTPS']='on';

View File

@@ -1,9 +1,9 @@
<?php
/**
* Do not edit this file. Edit the config files found in the config/ dir instead.
* This file is required in the root directory so WordPress can find it.
* WP is hardcoded to look in its own directory or one directory up for wp-config.php.
*/
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . '/config/application.php');
require_once(ABSPATH . 'wp-settings.php');
<?php
/**
* Do not edit this file. Edit the config files found in the config/ dir instead.
* This file is required in the root directory so WordPress can find it.
* WP is hardcoded to look in its own directory or one directory up for wp-config.php.
*/
require_once(__DIR__ . '/vendor/autoload.php');
require_once(__DIR__ . '/config/application.php');
require_once(ABSPATH . 'wp-settings.php');

View File

@@ -24,4 +24,4 @@ WP_SECURE_AUTH_SALT=generate_me
WP_LOGGED_IN_SALT=generate_me
WP_NONCE_SALT=generate_me
WP_JWT_AUTH_SECRET_KEY=generate_me
WP_JWT_AUTH_SECRET_KEY=generate_me

View File

@@ -1,4 +1,5 @@
FROM php:7.0-apache
ARG API_URL
ENV REACT_APP_API_URL ${API_URL}

View File

@@ -56,14 +56,18 @@ export const receiveCustomerDetails = (json) => ({
export const fetchCartCount = () => {
return dispatch => {
dispatch(requestShopCartCount());
//TODO : fetch cart count from woocommerce (requires plugin)
dispatch(receiveShopCartCount(0));
/*return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
/*
return client.fetch({url: `${API_SERVER}/cart/api/getCartCount`}).then(response => {
if (typeof response.data !== 'undefined' && 'cartItemsCount' in response.data) {
dispatch(receiveShopCartCount(response.data.cartItemsCount));
}
}).catch(error => {
client.onError(error, dispatch);
});*/
});
*/
}
}

View File

@@ -1,7 +1,4 @@
import {API_SERVER} from '../../config';
import HtmlClient from '../../helpers/HtmlClient';
import {REQUEST_GADGETS, RECIEVE_GADGETS} from '../../constants/dashboardConstants';
const htmlClient = new HtmlClient();
const requestGadgets = () => ({type: REQUEST_GADGETS});
const recieveGadgets = (json) => ({
@@ -12,7 +9,30 @@ const recieveGadgets = (json) => ({
export const fetchGadgets = () => {
return dispatch => {
dispatch(requestGadgets());
const data = {"info":{"idDashboard":"23","name":"Customer Basic Dashboard","isOwner":"0"},"gadgets":[{"idGadget":"3","name":"Customer Order Central","module":"gadget-order-central","position":"1"},{"idGadget":"5","name":"Customer Next Actions","module":"gadget-next-actions","position":"2"}]};
dispatch(recieveGadgets(data.gadgets))
//TODO : check how to solve gadgets, don't use hardcoded values
const gadgets = [
{
name: 'CustomerOrderCentral',
idGadget: 0,
},
{
name: 'CustomerNextActions',
idGadget: 1,
}
]
dispatch(recieveGadgets(gadgets));
/*
return htmlClient.fetch({
url: `${API_SERVER}/dashboards/api/getMyDashboard`
})
.then(response => {
if(response.data && response.data.gadgets){
dispatch(recieveGadgets(response.data.gadgets))
}
})
.catch(error => {
htmlClient.onError(error, dispatch);
});
*/
}
}

View File

@@ -1,6 +1,7 @@
import {API_SERVER} from '../../config';
import HtmlClient from '../../helpers/HtmlClient';
import {REQUEST_NEXT_ACTIONS, RECIEVE_NEXT_ACTIONS} from '../../constants/dashboardConstants';
import { API_SERVER } from '../../config';
import HtmlClient from '../../helpers/HtmlClient';
const client = new HtmlClient();
export const requestNextActions = () => ({
@@ -23,6 +24,6 @@ export const fetchNextActions = () => {
.then(response => dispatch(recieveNextActions(response.data)))
.catch(error => {
client.onError(error, dispatch);
});
});
}
}

View File

@@ -4,6 +4,8 @@ import {
REQUEST_ORDERS,
RECEIVE_ORDERS
} from '../../constants/dashboardConstants';
import {fromWCOrder} from '../../helpers/OrderHelper';
import { MAX_ORDER_COUNT } from '../../constants/ordersConstants';
const htmlClient = new HtmlClient();
export const requestOrders = () => ({
@@ -19,17 +21,16 @@ export const recieveOrders = (json) => ({
export const fetchOrders = (viewAllOrders) => {
return dispatch => {
dispatch(recieveOrders([]));
/*return htmlClient.fetch({
url: `${API_SERVER}/dashboards/api/getOrderCentralInfo`,
method: 'post',
data: {
viewAllOrders
}
dispatch(requestOrders());
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wc/v2/orders?per_page=${MAX_ORDER_COUNT}&wiaas_is_active=1`,
method: 'get',
})
.then(response => {
dispatch(recieveOrders(response.data.map(wcOrder => fromWCOrder(wcOrder))));
})
.then(response => dispatch(recieveOrders(response.data)))
.catch(error => {
htmlClient.onError(error, dispatch);
});*/
});
}
}

View File

@@ -160,68 +160,70 @@ const validateRefreshToken = () => {
export const getModules = () => {
return dispatch => {
const data = {
"modules": {
"modules": [
dispatch(requestModules());
//TODO : check how to solve modules, don't hardocde values
const modules={
modules:{
modules:[
{
"id": "14",
"name": "ProfileSettings",
"menuName": "ProfileSettings",
"url": "profileSettings",
"isInMenu": "0"
id:"19",
isInMenu:"0",
menuName:"Cart",
name:"Cart",
url:"cart",
},
{
"id": "23",
"name": "OrderProjects",
"menuName": "OrderProjects",
"url": "orderProjects",
"isInMenu": "0"
id:"14",
isInMenu:"0",
menuName:"ProfileSettings",
name:"ProfileSettings",
url:"profileSettings",
},
{
"id": "15",
"name": "Terms",
"menuName": "Terms",
"url": "terms",
"isInMenu": "0"
id:"23",
isInMenu:"0",
menuName:"OrderProjects",
name:"OrderProjects",
url:"orderProjects",
},
{
"id": "19",
"name": "Cart",
"menuName": "Cart",
"url": "cart",
"isInMenu": "0"
id:"15",
isInMenu:"0",
menuName:"Terms",
name:"Terms",
url:"terms",
},
{
"id": "1",
"name": "Dashboards",
"menuName": "Overview",
"url": "dashboards",
"isInMenu": "1"
id:"1",
isInMenu:"1",
menuName:"Overview",
name:"Dashboards",
url:"dashboards",
},
{
"id": "18",
"name": "CoMarket",
"menuName": "Co-Market",
"url": "co-market",
"isInMenu": "1"
id:"18",
isInMenu:"1",
menuName:"Co-Market",
name:"CoMarket",
url:"co-market",
}
],
"subModules": {
"co-market": [
subModules:{
"co-market":[
{
"moduleUrl": "co-market",
"menuName": "Orders",
"name": "Orders",
"url": "orders"
menuName:"Orders",
name:"Orders",
url:"orders",
moduleUrl:"co-market",
}
]
}
}
};
dispatch(recieveModules(data));
dispatch(requestModules());
/**return htmlClient.fetch({
}
dispatch(recieveModules(modules));
/*
return htmlClient.fetch({
url: `${API_SERVER}/login/api/getModules`,
})
.then(response => {
@@ -229,7 +231,8 @@ export const getModules = () => {
})
.catch(error => {
htmlClient.onError(error, dispatch);
});**/
});
*/
}
}

View File

@@ -7,13 +7,14 @@ import {
RECEIVE_HISTORY_ORDERS,
SET_VIEW_ALL_ORDERS
} from '../../constants/ordersConstants';
import {fromWCOrder} from '../../helpers/OrderHelper';
const htmlClient = new HtmlClient();
const requestActiveOrders = () => ({
type: REQUEST_ACTIVE_ORDERS,
isLoading: true
});
const recieveActiveOrders = (json) => ({
const receiveActiveOrders = (json) => ({
type: RECEIVE_ACTIVE_ORDERS,
isLoading: false,
activeOrders: json
@@ -23,10 +24,10 @@ export const getActiveOrders = () => {
return dispatch => {
dispatch(requestActiveOrders());
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wc/v2/orders?status=processing`
url: `${API_SERVER}/wp-json/wc/v2/orders?wiaas_is_active=1`
})
.then(response => {
dispatch(recieveActiveOrders(response.data));
dispatch(receiveActiveOrders(response.data.map(wcOrder => fromWCOrder(wcOrder))));
})
.catch(error => {
htmlClient.onError(error, dispatch);
@@ -48,10 +49,10 @@ export const getHistoryOrders = () => {
return dispatch => {
dispatch(requestHistoryOrders());
return htmlClient.fetch({
url: `${API_SERVER}/wp-json/wc/v2/orders?status=completed`
url: `${API_SERVER}/wp-json/wc/v2/orders?wiaas_is_active=0`
})
.then(response => {
dispatch(recieveHistoryOrders(response.data));
dispatch(recieveHistoryOrders(response.data.map(wcOrder => fromWCOrder(wcOrder))));
})
.catch(error => {
htmlClient.onError(error, dispatch);

View File

@@ -3,5 +3,6 @@ const API_VERSION = 'v2';
const API_SERVER_BASE = process.env.REACT_APP_API_URL;
const API_SERVER = API_SERVER_BASE;
const API_SERVER_LOGIN = API_SERVER + "/wp-admin";
export {API_SERVER_BASE, API_SERVER, APPLICATION_NAME}
export {API_SERVER_BASE, API_SERVER, APPLICATION_NAME, API_SERVER_LOGIN}

View File

@@ -1,4 +1,4 @@
import {API_SERVER_BASE} from '../config.js';
import {API_SERVER_LOGIN} from '../config.js';
const MODULE = 'AUTH_';
@@ -36,7 +36,7 @@ export const loginMessages = {
CHANGE_LATER: 'You can change your password in 5 minutes!',
INVALID_REFRESH_TOKEN: 'Your session has expired!',
EXPIRED_SESSION : 'Your session has expired!',
INVALID_USER_TYPE: 'Users with other roles than "customer" must use this url for login: ' + API_SERVER_BASE,
INVALID_USER_TYPE: 'Users with other roles than "customer" must use this url for login: ' + API_SERVER_LOGIN,
INVALID_CHANGE_TOKEN: 'Invalid change token value!',
PASSWORDS_MISSING: 'Password can not be empty',
WRONG_USERNAME: 'Invalid username!',

View File

@@ -30,10 +30,10 @@ export const dashboardTexts = {
},
statuses: {
open: 'Open',
'in-progress': 'In Progress',
production: 'Production',
processing: 'In Progress',
completed: 'Production',
'end-of-life': 'End Of Life',
canceled: 'Canceled',
cancelled: 'Cancelled',
'not-accepted': 'Not Accepted',
invalid: 'Invalid',
pending: 'Pending'

View File

@@ -186,7 +186,7 @@ export const orderTexts = {
},
statuses: {
open: 'Open',
'processing': 'Processing',
'processing': 'In progress',
completed: 'Completed',
'end-of-life': 'Completed',
cancelled: 'Cancelled',
@@ -207,3 +207,5 @@ export const orderTexts = {
PLACED_BY: 'Placed by'
}
};
export const MAX_ORDER_COUNT = 5;

View File

@@ -36,8 +36,8 @@
background: $not-accepted-status-color;
}
.in-progress {
background: $in-progress-status-color;
.processing {
background: $processing-status-color;
}
.next-action-details{

View File

@@ -31,15 +31,15 @@
background: $open-status-color;
}
.in-progress {
background: $in-progress-status-color;
.processing {
background: $processing-status-color;
}
.line-open {
border-left: 3px $open-status-color solid;
}
.line-in-progress {
border-left: 3px $in-progress-status-color solid;
.line-processing {
border-left: 3px $processing-status-color solid;
}
}

View File

@@ -10,10 +10,10 @@ class NextActionItem extends Component {
return (
<Row className="next-actions-row">
<Col xl="8">
{nextAction.stepAction}
{nextAction.step_action}
</Col>
<Col xl="4">
<Link to={'orders/'+ nextAction.idOrder}>
<Link to={'orders/'+ nextAction.order_id}>
<div className={'next-actions-status ' + nextAction.status}>{dashboardTexts.statuses[nextAction.status]}</div>
</Link>
</Col>

View File

@@ -14,7 +14,7 @@ class NextActionsList extends Component {
{
nextActions &&
nextActions.map((nextAction, index) =>
<NextActionItem key={'action-' + nextAction.orderNumber + index} nextAction={nextAction}/>
<NextActionItem key={'action-' + nextAction.order_number + index} nextAction={nextAction}/>
)
}
</WiaasTableBody>

View File

@@ -12,12 +12,12 @@ class OrderItem extends Component {
<WiaasTableRow className={'order-central-row line-' + order.status}>
<WiaasTableCol header="#">
<i className="fa fa-list-alt package-photo" aria-hidden="true" />
<div className="orderNumber">{order.orderNumber}</div>
<div className="orderNumber">{order.number}</div>
</WiaasTableCol>
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.orderDate}</WiaasTableCol>
<WiaasTableCol header={dashboardTexts.tableHeaders.ORDER_DATE}>{order.dateCreated}</WiaasTableCol>
{
isViewAllOrdersChecked &&
<WiaasTableCol header={dashboardTexts.tableHeaders.PLACED_BY}>{order.placedBy}</WiaasTableCol>
<WiaasTableCol header={dashboardTexts.tableHeaders.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>
}
<WiaasTableCol header={dashboardTexts.tableHeaders.REFERENCE}>{order.reference}</WiaasTableCol>
<WiaasTableCol header={dashboardTexts.tableHeaders.ON_DELIVERY}>{order.fixedPrice.toLocaleString()} {order.currency}</WiaasTableCol>
@@ -25,7 +25,7 @@ class OrderItem extends Component {
<WiaasTableCol header={dashboardTexts.tableHeaders.STATUS}>
<div className={'status-icon ' + order.status}></div>{dashboardTexts.statuses[order.status]}
</WiaasTableCol>
<WiaasTableCol><Link to={'orders/'+ order.idOrder}><Button className="wiaas-button">{dashboardTexts.buttons.DETAILS}</Button></Link></WiaasTableCol>
<WiaasTableCol><Link to={'orders/'+ order.id}><Button className="wiaas-button">{dashboardTexts.buttons.DETAILS}</Button></Link></WiaasTableCol>
</WiaasTableRow>
);
}

View File

@@ -46,7 +46,7 @@ class OrdersList extends Component {
{
orders &&
orders.map((order, index) =>
<OrderItem key={'order-' + order.orderNumber} order={order} isViewAllOrdersChecked={isViewAllOrdersChecked}/>
<OrderItem key={'order-' + order.number} order={order} isViewAllOrdersChecked={isViewAllOrdersChecked}/>
)
}
</WiaasTableBody>

View File

@@ -13,10 +13,8 @@ class OrdersDataContainer extends Component {
this.props.dispatch(getHistoryOrders());
}
checkIfOrdersExistForUser(orders) {
return orders.every((order) => {
return true;//'isMyOrder' in order && !order.isMyOrder;
})
hasCurrentCustomerOrders(orders) {
return orders.some((order) => order.isMyOrder);
}
render() {
@@ -38,7 +36,7 @@ class OrdersDataContainer extends Component {
<OrderList orders={orders} type={type}/>
}
{
((orders && orders.length === 0 && !isLoading) || (orders && !this.checkIfOrdersExistForUser(orders))) &&
((orders && orders.length === 0 && !isLoading) || (orders && !this.hasCurrentCustomerOrders(orders))) &&
<Alert color="info">{orderTexts.labels.NO_RECORDS}</Alert>
}
</WiaasBox>

View File

@@ -42,7 +42,7 @@ class HistoryOrdersButtons extends Component {
],
header: orderTexts.labels.SUPPORT_MESSAGE_HEADER,
TagName: SupportMail,
params: {orderInfo: this.props.order, orderPackages: this.props.order.line_items}
params: {orderInfo: this.props.order, orderPackages: this.props.order.packages}
};
this.props.dispatch(setDialogOpenFlag(true));

View File

@@ -1,77 +0,0 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import {WiaasTableRow, WiaasTableCol} from '../../../mainComponents/table/WiaasTable.jsx';
import {orderTexts} from '../../../constants/ordersConstants';
import '../style/Orders.css';
import OrderPackage from './OrderPackage.jsx';
import HistoryOrderButtons from './HistoryOrderButtons.jsx';
class HistoryOrdersItem extends Component {
constructor(props) {
super(props);
this.state = {
showPackages: false
};
this.toggle = this.toggle.bind(this);
}
toggle() {
this.setState({
showPackages: !this.state.showPackages
});
}
getIconClass(type) {
return 'fa fa-angle-' + type + ' toggle-view-packages';
}
render() {
const {order, isViewAllOrdersChecked} = this.props;
return (
<div>
<WiaasTableRow className={"order-central-row order-border-" + order.status}>
<WiaasTableCol header="#">
{!this.state.showPackages && <i className={this.getIconClass('down')} aria-hidden="true" onClick={this.toggle}></i>}
{this.state.showPackages && <i className={this.getIconClass('up')} aria-hidden="true" onClick={this.toggle}></i>}
<i className="fa fa-list-alt package-photo" aria-hidden="true" />
<div className="order-number">{order.number}</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.REFERENCE}>{order.reference ? order.reference : '-'}</WiaasTableCol>
{isViewAllOrdersChecked['history'] && <WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.date_created ? order.date_created : '-'}</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.DELIVERY_DATE}>{order.deliveryDate}</WiaasTableCol>
<WiaasTableCol header="Catalogue">
<div className="order-item-cl">
<img className="cl-photo" src="static/img/man-icon.png" alt="Catalogue" />
<div className="cl-details">
<div className="cl-contact-name">{order.commercial_lead ? order.commercial_lead.contact_name : ''}</div>
<div className="cl-name">{order.commercial_lead ? order.commercial_lead.name : ''}</div>
</div>
</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
{order.currency
? order.total.toLocaleString() + ' ' + order.currency
: parseFloat(order.total).toLocaleString()}
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.STATUS}>
<div className={'status-icon ' + order.status}></div>{orderTexts.statuses[order.status]}
</WiaasTableCol>
<WiaasTableCol header="End of life">{order.date_completed}</WiaasTableCol>
<WiaasTableCol header="Buttons details">
<HistoryOrderButtons order={order}/>
</WiaasTableCol>
</WiaasTableRow>
{ this.state.showPackages && <OrderPackage order={order} type="history"/> }
</div>
);
}
}
const mapStateToProps = (state) => ({
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
});
export default connect(mapStateToProps)(HistoryOrdersItem);

View File

@@ -1,7 +1,6 @@
import React, {Component} from 'react';
import {connect} from 'react-redux';
import ActiveOrderItem from './ActiveOrderItem.jsx';
import HistoryOrderItem from './HistoryOrderItem.jsx';
import OrderListItem from './OrderListItem.jsx';
import {WiaasTable, WiaasTableHeader, WiaasTableBody} from '../../../mainComponents/table/WiaasTable.jsx';
import {orderTexts} from '../../../constants/ordersConstants';
@@ -47,7 +46,6 @@ class OrderList extends Component {
render() {
const {orders, type, isCompanyAdmin, isViewAllOrdersChecked} = this.props;
const TagName = type && type === 'active' ? ActiveOrderItem : HistoryOrderItem;
return (
<div>
@@ -57,8 +55,8 @@ class OrderList extends Component {
{
orders &&
orders.map((order, index) =>
((true) || (isCompanyAdmin && isViewAllOrdersChecked[type])) &&
<TagName key={order.id} order={order} />
(order.isMyOrder || (isCompanyAdmin && isViewAllOrdersChecked[type])) &&
<OrderListItem key={order.id} order={order} type={type} />
)
}
</WiaasTableBody>

View File

@@ -6,8 +6,9 @@ import {WiaasTableRow, WiaasTableCol} from '../../../mainComponents/table/WiaasT
import {orderTexts} from '../../../constants/ordersConstants';
import '../style/Orders.css';
import OrderPackage from './OrderPackage.jsx';
import HistoryOrderButtons from './HistoryOrderButtons.jsx';
class ActiveOrderItem extends Component {
class OrderListItem extends Component {
constructor(props) {
super(props);
this.state = {
@@ -29,6 +30,16 @@ class ActiveOrderItem extends Component {
render() {
const {order, isViewAllOrdersChecked} = this.props;
const isActive = this.props.type === 'active';
let orderButtons;
if (isActive) {
orderButtons = ( <Link to={'/orders/' + order.id} className="actions-link">
<Button color="secondary" className="actions-button">{orderTexts.buttons.DELIVERY_DETAILS}</Button>
</Link>);
} else {
orderButtons = <HistoryOrderButtons order={order}/>;
}
return (
<div>
@@ -40,34 +51,37 @@ class ActiveOrderItem extends Component {
<div className="order-number">{order.number}</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.REFERENCE}>{order.reference ? order.reference : '-'}</WiaasTableCol>
{isViewAllOrdersChecked['active'] && <WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.date_created ? order.date_created : '-'}</WiaasTableCol>
{
isViewAllOrdersChecked[this.props.type] &&
<WiaasTableCol header={orderTexts.labels.PLACED_BY}>{order.customer ? order.customer.name : ''}</WiaasTableCol>
}
<WiaasTableCol header={orderTexts.labels.ORDER_DATE}>{order.dateCreated ? order.dateCreated : '-'}</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.EST_DELIVERY}>{order.estimatedDeliveryDate ? order.estimatedDeliveryDate : '-'}</WiaasTableCol>
<WiaasTableCol header="Catalogue">
<div className="order-item-cl">
<img className="cl-photo" src="static/img/man-icon.png" alt="Catalogue" />
<div className="cl-details">
<div className="cl-contact-name">{order.commercial_lead ? order.commercial_lead.contact_name : ''}</div>
<div className="cl-name">{order.commercial_lead ? order.commercial_lead.name : ''}</div>
<div className="cl-contact-name">{order.commercialLead ? order.commercialLead.contact : ''}</div>
<div className="cl-name">{order.commercialLead ? order.commercialLead.name : ''}</div>
</div>
</div>
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.AMOUNT}>
{order.currency
? order.total.toLocaleString() + ' ' + order.currency
: parseFloat(order.total).toLocaleString()}
? order.fixedPrice.toLocaleString() + ' ' + order.currency
: parseFloat(order.fixedPrice).toLocaleString()}
</WiaasTableCol>
<WiaasTableCol header={orderTexts.labels.STATUS}>
<div className={'status-icon ' + order.status}></div>{orderTexts.statuses[order.status]}
</WiaasTableCol>
{
!isActive && <WiaasTableCol header="End of life">{order.dateCompleted}</WiaasTableCol>
}
<WiaasTableCol header="Buttons details">
<Link to={'/orders/' + order.id} className="actions-link">
<Button color="secondary" className="actions-button">{orderTexts.buttons.DELIVERY_DETAILS}</Button>
</Link>
{orderButtons}
</WiaasTableCol>
</WiaasTableRow>
{ this.state.showPackages && <OrderPackage order={order} type="active"/> }
{ this.state.showPackages && <OrderPackage order={order} type={this.props.type}/> }
</div>
);
}
@@ -76,4 +90,4 @@ class ActiveOrderItem extends Component {
const mapStateToProps = (state) => ({
isViewAllOrdersChecked: state.ordersReducer.isViewAllOrdersChecked
});
export default connect(mapStateToProps)(ActiveOrderItem);
export default connect(mapStateToProps)(OrderListItem);

View File

@@ -32,7 +32,7 @@ class OrderPackage extends Component {
<div className="order-details-container">
<WiaasTableRow id={'delivery-address-' + order.id}>
<Col lg="4" sm="4" xs="4">{orderTexts.labels.DELIVERY_ADDRESS}:</Col>
<Col lg="8" sm="8" xs="8">{order.shipping.address_1}, {order.shipping.city}, {order.shipping.country}, {order.shipping.postcode}</Col>
<Col lg="8" sm="8" xs="8">{order.deliveryAddress}</Col>
</WiaasTableRow>
<WiaasTableRow id={'phone-' + order.id}>
<Col lg="4" sm="4" xs="4">{orderTexts.labels.PHONE_NUMBER}:</Col>
@@ -43,12 +43,12 @@ class OrderPackage extends Component {
<Col lg="8" sm="8" xs="8">{order.customer.email}</Col>
</WiaasTableRow>
<WiaasTableRow id={'commercial-lead-phone-' + order.id}>
<Col lg="4" sm="4" xs="4">{order.commercial_lead ? order.commercial_lead.name : ''} {orderTexts.labels.PHONE_NUMBER}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercial_lead ? order.commercial_lead.phone : ''}</Col>
<Col lg="4" sm="4" xs="4">{order.commercialLead ? order.commercialLead.name : ''} {orderTexts.labels.PHONE_NUMBER}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercialLead ? order.commercialLead.phone : ''}</Col>
</WiaasTableRow>
<WiaasTableRow id={'mail-' + order.id}>
<Col lg="4" sm="4" xs="4">{order.commercial_lead ? order.commercial_lead.name : ''} {orderTexts.labels.MAIL}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercial_lead ? order.commercial_lead.email : ''}</Col>
<Col lg="4" sm="4" xs="4">{order.commercialLead ? order.commercialLead.name : ''} {orderTexts.labels.MAIL}:</Col>
<Col lg="8" sm="8" xs="8">{order.commercialLead ? order.commercialLead.email : ''}</Col>
</WiaasTableRow>
</div>
</WiaasBox>
@@ -58,24 +58,24 @@ class OrderPackage extends Component {
<WiaasTable>
<WiaasTableHeader headers={this.getHeadersByType(type)}/>
<WiaasTableBody>
{order.line_items.map((orderPackage, index) =>
<WiaasTableRow className="order-central-row" key={orderPackage.id + '-' + orderPackage.product_id}>
{order.packages.map((orderPackage, index) =>
<WiaasTableRow className="order-central-row" key={orderPackage.id}>
<WiaasTableCol header="Package" className="package-info-col">
<div className="package-name">{orderPackage.quantity} x {orderPackage.name}</div>
</WiaasTableCol>
<WiaasTableCol header="Price">
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.price).toLocaleString()} {orderPackage.packageCurrency && orderPackage.packageCurrency.currency} {' '}
({orderPackage.payment_type})
({orderPackage.paymentType})
</WiaasTableCol>
<WiaasTableCol header="Services and support">
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.service_price, orderPackage.recurring_price).toLocaleString() + ' / ' + orderPackage.period_unit + ' '}
{orderTexts.labels.EXTEND} {orderPackage.period_unit} (Max {orderPackage.max_contract_period})
{this.calculateQuantityPrice(orderPackage.quantity, orderPackage.servicePrice, orderPackage.recurringPrice).toLocaleString() + ' / ' + orderPackage.periodUnit + ' '}
{orderTexts.labels.EXTEND} {orderPackage.periodUnit} (Max {orderPackage.maxContractPeriod})
</WiaasTableCol>
<WiaasTableCol>
{
type === 'active'
? orderPackage.short_desc || '-'
: orderPackage.date_completed || '-'
? orderPackage.shortDesc || '-'
: orderPackage.dateCompleted || '-'
}
</WiaasTableCol>
</WiaasTableRow>

View File

@@ -75,13 +75,13 @@ class SupportMail extends Component {
</Col>
</Row>
{orderInfo.date_modified &&
{orderPackage.dateCompleted &&
<Row>
<Col>
<span className="subtitle">{orderTexts.labels.END_OF_LIFE}:</span>
</Col>
<Col xl="8">
<span>{orderPackage.date_completed}</span>
<span>{orderPackage.dateCompleted}</span>
</Col>
</Row>
}

View File

@@ -18,7 +18,7 @@ $borderWidth: 3px;
border-left: $borderWidth $in-progress-status-color solid;
}
.order-border-production {
.order-border-completed {
border-left: $borderWidth $production-status-color solid;
}
@@ -26,7 +26,7 @@ $borderWidth: 3px;
border-left: $borderWidth $end-of-life-status-color solid;
}
.order-border-canceled {
.order-border-cancelled {
border-left: $borderWidth $canceled-status-color solid;
}

View File

@@ -20,11 +20,11 @@ $link-line-height: 1.5rem;
border-left: $border-width $processing-status-color solid;
}
.canceled {
.cancelled {
border-left: $border-width $canceled-status-color solid;
}
.production {
.completed {
border-left: $border-width $production-status-color solid;
}
@@ -127,7 +127,7 @@ $link-line-height: 1.5rem;
background: $end-of-life-status-color;
}
.canceled {
.cancelled {
background: $canceled-status-color;
}

View File

@@ -0,0 +1,47 @@
import moment from 'moment';
function formatDate(date) {
return date ? moment(date).format("Do MMM, YYYY") : undefined;
}
function formatAddress(addressObject) {
return `${addressObject.address_1}, ${addressObject.city}, ${addressObject.country}, ${addressObject.postcode}`;
}
export const fromWCOrder = (WCOrder) => {
return {
id: WCOrder.id,
number: WCOrder.number,
isMyOrder: WCOrder['is_my_order'],
dateCreated: formatDate(WCOrder['date_created']),
dateCompleted: formatDate(WCOrder['date_completed']),
estimatedDeliveryDate: undefined,
reference: 'reference field',
assignedTo: 'assigned to',
fixedPrice: WCOrder.total,
recurringPrice: 0,
status: WCOrder.status,
currency: WCOrder.currency,
packages: WCOrder['line_items'].map(packageLine => {
return {
id: packageLine['product_id'],
name: packageLine.name,
quantity: packageLine.quantity,
price: packageLine.price,
status: packageLine.status,
paymentType: packageLine['payment_type'],
servicePrice: packageLine['service_price'],
serviceContractPeriod: packageLine['service_contract_period'],
maxContractPeriod: packageLine['max_contract_period'],
periodUnit: packageLine['period_unit'],
recurringPrice: packageLine['recurring_price'],
payPeriod: packageLine['pay_period'],
shortDesc: packageLine['short_desc'],
dateCompleted: formatDate(packageLine['date_completed']),
};
}),
deliveryAddress: formatAddress(WCOrder.shipping),
customer: WCOrder.customer,
commercialLead: WCOrder['commercial_lead']
}
};