Merge branch 'master' into order-delivery-flow
This commit is contained in:
@@ -18,6 +18,7 @@ class Wiaas_Order {
|
||||
public static function init() {
|
||||
|
||||
require_once dirname( __FILE__ ) . '/order/class-wiaas-order-project.php';
|
||||
require_once dirname( __FILE__ ) . '/order/class-wiaas-procurement-order.php';
|
||||
require_once dirname( __FILE__ ) . '/order/wiaas-order-functions.php';
|
||||
|
||||
add_filter('woocommerce_register_post_type_shop_order', array(__CLASS__, 'manage_order_settings'));
|
||||
@@ -45,6 +46,164 @@ class Wiaas_Order {
|
||||
return "1000000$number";
|
||||
}
|
||||
|
||||
public static function get_additional_days_prior_installation($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
return $order->get_meta('_wiaas_order_additional_days_prior_installation');
|
||||
}
|
||||
|
||||
public static function add_additional_tracking_info($order_id, $supplier_id){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['tracking_info'][] = array(
|
||||
'number' => '',
|
||||
'url' => ''
|
||||
);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function save_tracking_info($order_id, $supplier_id, $tracking_index, $tracking_num, $tracking_url){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['tracking_info'][$tracking_index]['number'] = $tracking_num;
|
||||
$suppliers[$key]['tracking_info'][$tracking_index]['url'] = $tracking_url;
|
||||
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function delete_tracking_info($order_id, $supplier_id, $tracking_index){
|
||||
$suppliers = self::get_suppliers($order_id);
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
unset($suppliers[$key]['tracking_info'][$tracking_index]);
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function save_estimated_date($order_id, $supplier_id, $date){
|
||||
$suppliers = wiaas_get_order_delivery_suppliers($order_id);
|
||||
$updated = false;
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['estimated_date'] = $date;
|
||||
$updated = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$updated){
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function save_confirmed_date($order_id, $supplier_id, $date){
|
||||
|
||||
$suppliers = wiaas_get_order_delivery_suppliers($order_id);
|
||||
$updated = false;
|
||||
|
||||
foreach($suppliers as $key => $supplier){
|
||||
if ($supplier['id'] === $supplier_id){
|
||||
$suppliers[$key]['confirmed_date'] = $date;
|
||||
$updated = true;
|
||||
if (!$suppliers[$key]['estimated_date']){
|
||||
$suppliers[$key]['estimated_date'] = $date;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$updated){
|
||||
return false;
|
||||
}
|
||||
|
||||
$order = wc_get_order($order_id);
|
||||
|
||||
$order->update_meta_data('_wiaas_suppliers', $suppliers);
|
||||
self::_update_max_and_earliest_dates($order, $suppliers);
|
||||
|
||||
$order->save_meta_data();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function get_order_estimated_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_order_estimated_delivery_date') ?: NULL;
|
||||
}
|
||||
|
||||
public static function save_order_estimated_date($order_id, $date){
|
||||
return update_post_meta($order_id, '_wiaas_order_estimated_delivery_date', $date);
|
||||
}
|
||||
|
||||
public static function get_final_estimated_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_final_estimated_delivery_date') ?: 0;
|
||||
}
|
||||
|
||||
public static function get_final_confirmed_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_final_confirmed_delivery_date') ?: 0;
|
||||
}
|
||||
|
||||
public static function get_earliest_installation_date($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
if (!$order){
|
||||
return 0;
|
||||
}
|
||||
|
||||
return $order->get_meta('_wiaas_earliest_installation_date') ?: 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get suppliers related to order
|
||||
*/
|
||||
public static function get_suppliers($order_id){
|
||||
$order = wc_get_order($order_id);
|
||||
return $order->get_meta('_wiaas_suppliers');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update `shop_order` post type settings before creation to enable better order management for wiaas
|
||||
*
|
||||
@@ -191,12 +350,53 @@ class Wiaas_Order {
|
||||
|
||||
public static function get_order_tender($order_id) {
|
||||
return get_post_meta($order_id, '_wiaas_tender', true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* PRIVATE
|
||||
*/
|
||||
|
||||
private static function _update_max_and_earliest_dates($order, $suppliers){
|
||||
$max_estimated_date = 0;
|
||||
$max_confirmed_date = 0;
|
||||
$earliest_installation_date = 0;
|
||||
$missing_estimated = false;
|
||||
|
||||
foreach($suppliers as $supplier) {
|
||||
|
||||
error_log($supplier['confirmed_date']);
|
||||
error_log($supplier['estimated_date']);
|
||||
|
||||
if (! empty($supplier['confirmed_date']) ) {
|
||||
|
||||
$max_confirmed_date = max($max_confirmed_date, $supplier['confirmed_date']);
|
||||
} else {
|
||||
|
||||
$missing_confirmed = true;
|
||||
}
|
||||
|
||||
if (! empty($supplier['estimated_date']) ) {
|
||||
|
||||
$max_estimated_date = max($max_estimated_date, $supplier['estimated_date']);
|
||||
|
||||
} else {
|
||||
|
||||
$missing_estimated = true;
|
||||
$earliest_installation_date = 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $missing_estimated) {
|
||||
|
||||
$earliest_installation_date = max($max_estimated_date, $max_confirmed_date);
|
||||
$earliest_installation_date = strtotime('+' . self::get_additional_days_prior_installation($order->id) . ' days', $earliest_installation_date);
|
||||
}
|
||||
|
||||
$order->update_meta_data('_wiaas_final_confirmed_delivery_date', $max_confirmed_date);
|
||||
$order->update_meta_data('_wiaas_final_estimated_delivery_date', $max_estimated_date);
|
||||
$order->update_meta_data('_wiaas_earliest_installation_date', $earliest_installation_date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Append specific wiaas order details, like reference
|
||||
* @param $data
|
||||
|
||||
Reference in New Issue
Block a user