order delivery process

This commit is contained in:
Bilal Catic
2018-10-21 16:39:58 +02:00
parent 1ae60eb6eb
commit 69c74d9340
6 changed files with 226 additions and 7 deletions

View File

@@ -0,0 +1,11 @@
<?php
class Wiaas_Admin_Order_Delivery_Process {
public static function init() {
require_once dirname( __FILE__ ) . '/delivery-process/class-wiaas-admin-order-delivery-process-flow.php';
require_once dirname( __FILE__ ) . '/delivery-process/wiaas-admin-order-delivery-process-ajax.php';
}
}
Wiaas_Admin_Order_Delivery_Process::init();

View File

@@ -0,0 +1,60 @@
<?php
class Wiaas_Admin_Order_Process_Flow {
public static function init() {
add_action('add_meta_boxes', array(__CLASS__, 'create_custom_meta_box'), 100);
}
public static function create_custom_meta_box() {
add_meta_box(
'order_process_flow_meta_box',
__('Order Process Flow', 'cmb'),
'Wiaas_Admin_Order_Process_Flow::add_process_flow_meta_box',
'shop_order',
'normal',
'default'
);
add_meta_box(
'order_delivery_dates_meta_box',
__('Delivery dates', 'cmb'),
'Wiaas_Admin_Order_Process_Flow::add_delivery_dates_meta_box',
'shop_order',
'normal',
'default'
);
}
public static function add_process_flow_meta_box(){
global $post;
$order_id = $post->ID;
$process = Wiaas_Delivery_Process::get_order_delivery_process($order_id);
if ($process === NULL){
$list_of_delivery_processes = Wiaas_Delivery_Process::get_available_delivery_processes();
require 'views/html-order-select-delivery-process.php';
}else{
$title = $process['name'];
$steps = $process['steps'];
require 'views/html-order-process-flow.php';
}
}
public static function add_delivery_dates_meta_box(){
// global $post;
// $order_id = $post->ID;
// $suppliers = Wiaas_Order::get_suppliers($order_id);
// require 'views/html-order-delivery-dates.php';
}
}
Wiaas_Admin_Order_Process_Flow::init();

View File

@@ -0,0 +1,65 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<style>
.collapsible {
background-color: #777;
color: white;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
.collapsible-active, .collapsible:hover {
background-color: #555;
}
.collapsible-content {
padding: 0 18px;
max-height: 0;
overflow: hidden;
transition: max-height 0.2s ease-out;
background-color: #f1f1f1;
}
</style>
<div>
<h3><?php echo $title ?></h3>
<br/>
<?php
foreach($steps as $index => $step){
$count = $index + 1;
echo '<button class="collapsible">' . $count . '. ' . $step['short_desc'] . '</button>';
echo '<div class="collapsible-content">';
echo $step['full_desc'];
echo '</div>';
}
?>
</div>
<script>
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function(event) {
event.preventDefault();
this.classList.toggle("collapsible-active");
var content = this.nextElementSibling;
if (content.style.maxHeight){
content.style.maxHeight = null;
} else {
content.style.maxHeight = content.scrollHeight + "px";
}
});
}
</script>

View File

@@ -0,0 +1,62 @@
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
?>
<style>
.delivery-process {
background-color: #777;
color: white;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
.delivery-process:hover {
background-color: #555;
}
</style>
<div>
<h1>Please select a process for the order:</h1>
<br/>
<?php
foreach($list_of_delivery_processes as $index => $process){
echo '<button class="delivery-process" id=' . $process['id'] . '>' . $process['title'] . '</button>';
}
?>
</div>
<script type="text/javascript" >
jQuery(document).ready(function($) {
$('.delivery-process').click(function(e){
e.preventDefault();
var data = {
action: 'wiaas_create_order_delivery_process',
_ajax_nonce: '<?php echo wp_create_nonce( "wiaas_create_order_delivery_process" ) ?>',
order: '<?php echo $order_id ?>',
form: e.target.id
};
// since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php
$.post(ajaxurl, data, function(response) {
if (response.success){
location.reload();
}else{
alert(response.data[0].message);
}
});
});
});
</script>

View File

@@ -20,6 +20,8 @@ class Wiaas_Admin {
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-documents.php';
// Admin organization interface
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-organization.php';
// Admin order delivery process
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-order-delivery-process.php';
require_once dirname(__FILE__) . '/admin/class-wiaas-admin-cl.php';

View File

@@ -19,8 +19,6 @@ class Wiaas_Delivery_Process {
}
private static function _init_hooks() {
add_action('woocommerce_new_order', array( __CLASS__, 'create_delivery_process_for_order' ));
add_filter( 'gform_entry_meta', array(__CLASS__, 'extend_gravity_form_entry_meta'), 10, 2 );
add_action( 'gravityflow_workflow_complete', array(__CLASS__, 'maybe_complete_parent_process_step'), 5, 3 );
@@ -80,7 +78,25 @@ class Wiaas_Delivery_Process {
$order = wc_get_order($order_id);
$order->update_status('completed', 'Completed order delivery process.', true);
}
}
}
/**
* List available delivery processes
*
* @return array
*/
public static function get_available_delivery_processes(){
$forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true );
$result = array();
foreach($forms as $form){
$result[] = array(
'title' => str_replace(self::$process_form_title_prefix, '', $form->title),
'id' => $form->id
);
}
return $result;
}
/**
* Retrieves delivery process instance for order
@@ -92,7 +108,7 @@ class Wiaas_Delivery_Process {
public static function get_order_delivery_process($order_id) {
$process_entry_id = get_post_meta($order_id, 'wiaas_delivery_process_entry_id');
if (!isset($process_entry_id)) {
if (empty($process_entry_id)) {
return null;
}
@@ -132,13 +148,13 @@ class Wiaas_Delivery_Process {
}
/**
* Automatically create delivery process instance when order is created
* create delivery process instance
* @param $order_id
*/
public static function create_delivery_process_for_order($order_id) {
public static function create_delivery_process_for_order($order_id, $form_id) {
$process_form = null;
$forms = GFFormsModel::search_forms( self::$process_form_title_prefix, true );
$process_form = $forms[0];
$process_form = GFFormsModel::get_form($form_id);
if(isset($process_form)) {
$order = wc_get_order( $order_id );
$new_process_entry = array(
@@ -150,7 +166,10 @@ class Wiaas_Delivery_Process {
add_post_meta($order_id, 'wiaas_delivery_process_id', $process_form->id);
add_post_meta($order_id, 'wiaas_delivery_process_entry_id', $process_entry_id);
return true;
}
return false;
}
/**