Handle additional orders info for wiaas
This commit is contained in:
13
backend/.htaccess
Normal file
13
backend/.htaccess
Normal 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
|
||||
@@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
@@ -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() {
|
||||
|
||||
@@ -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') );
|
||||
|
||||
@@ -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();
|
||||
@@ -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();
|
||||
@@ -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');
|
||||
}
|
||||
@@ -246,4 +246,4 @@ class Wiaas_Delivery_Process_Step extends Gravity_Flow_Step {
|
||||
|
||||
return absint($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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']);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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
33
backend/composer.lock
generated
@@ -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",
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
@@ -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';
|
||||
@@ -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';
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user