PluginProbe
MBE eShip / trunk
MBE eShip vtrunk
2.8.1 trunk 1.0.0 1.1.0 1.1.3 1.2.1 1.2.2 1.3.0 1.4.0 1.4.1 1.5.0 1.5.1 1.5.2 1.6.0 1.7.0 1.7.1 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.2.1 All 37 releases
mail-boxes-etc / includes / class-mbe-tracking-admin.php

class-mbe-tracking-admin.php in MBE eShip trunk, at includes/class-mbe-tracking-admin.php

149 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class woocommerce_mbe_tracking_admin
4 {
5 const TRACKING_TITLE_DISPLAY = "MBE Shipment Tracking";
6
7 const SHIPMENT_SOURCE_TRACKING_SERVICE = "woocommerce_mbe_tracking_service";
8 const SHIPMENT_SOURCE_TRACKING_ZONE = "woocommerce_mbe_tracking_zone";
9 const TRACKING_METABOX_KEY = "Tracking_Mbe_box";
10
11 protected $helper;
12 /**
13 * @var array
14 */
15 private array $tracking_files=[];
16 /**
17 * @var array|string|string[]
18 */
19 private $tracking_string;
20 /**
21 * @var array|string
22 */
23 private $tracking_name;
24 /**
25 * @var array|string
26 */
27 private $tracking_url;
28 private string $closure_file;
29
30 function __construct()
31 {
32 $this->helper = new Mbe_Shipping_Helper_Data();
33
34 if (is_admin()) {
35
36 $this->init();
37 }
38 }
39
40 private function init()
41 {
42 add_action('add_meta_boxes', array($this, 'add_mbe_tracking_metabox'), 15);
43 }
44
45 function add_mbe_tracking_metabox()
46 {
47 $screen = class_exists( '\Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController' ) && wc_get_container()->get( \Automattic\WooCommerce\Internal\DataStores\Orders\CustomOrdersTableController::class )->custom_orders_table_usage_is_enabled()
48 ? wc_get_page_screen_id( 'shop-order' )
49 : 'shop_order';
50
51 add_meta_box(
52 self::TRACKING_METABOX_KEY,
53 __( self::TRACKING_TITLE_DISPLAY, 'mail-boxes-etc' ),
54 array( $this, 'tracking_metabox_content' ),
55 $screen,
56 'side',
57 'default'
58 );
59 }
60
61 function tracking_metabox_content($post_or_order_object)
62 {
63 $order = ( $post_or_order_object instanceof WP_Post ) ? wc_get_order( $post_or_order_object->ID ) : $post_or_order_object;
64
65 if (isset($order)) {
66 $order_id = $order->get_id();
67 $tracking_data = $this->helper->getTrackings($order_id);
68
69 if ($this->helper->isEnabled() && $this->helper->isMbeShipping($order) && !empty( $tracking_data )) {
70 $this->tracking_string = $this->helper->getTrackingsString($order_id);
71 $this->tracking_files = $this->helper->getFileNames($order_id);
72 if ( \Automattic\WooCommerce\Utilities\OrderUtil::custom_orders_table_usage_is_enabled() ) {
73 $this->tracking_name = $order->get_meta( Mbe_Shipping_Helper_Data::SHIPMENT_SOURCE_TRACKING_NAME );
74 $this->tracking_url = $order->get_meta( Mbe_Shipping_Helper_Data::SHIPMENT_SOURCE_TRACKING_URL );
75 } else {
76 $this->tracking_name = get_post_meta($order_id, Mbe_Shipping_Helper_Data::SHIPMENT_SOURCE_TRACKING_NAME, true);
77 $this->tracking_url = get_post_meta($order_id, Mbe_Shipping_Helper_Data::SHIPMENT_SOURCE_TRACKING_URL, true);
78 }
79 if ( isset( $tracking_data[0]) && !$this->helper->isTrackingOpen( $tracking_data[0])) {
80 $this->closure_file = $this->helper->mbeUploadUrl().'/MBE_' . $tracking_data[0] . "_closed.pdf";
81 }
82 } else {
83 return;
84 }
85 } else {
86 return;
87 }
88
89
90
91 ?>
92 <ul class="order_actions submitbox">
93 <li id="actions" class="wide">
94 <strong><?php esc_html_e('Carrier name: ', 'mail-boxes-etc') ?></strong> <?php esc_html_e($this->tracking_name) ?>
95 </li>
96 <?php if ( count( $tracking_data ) > 1) { ?>
97 <li id="actions" class="wide">
98 <a target="_blank" href="<?php esc_attr_e($this->tracking_url . $this->tracking_string) ?>"><?php esc_html_e('Track all', 'mail-boxes-etc') ?></a>
99 </li>
100 <?php } ?>
101
102 <?php foreach ( $tracking_data as $t) { ?>
103 <li id="actions" class="wide">
104 <strong><?php esc_html_e('Tracking id: ', 'mail-boxes-etc') ?></strong> <a target="_blank" href="<?php esc_attr_e($this->tracking_url . $t) ?>"><?php esc_html_e($t) ?></a>
105 </li>
106 <?php } ?>
107 <?php for ($i = 0; $i < count($this->tracking_files); $i++) { ?>
108 <li id="actions" class="wide">
109 <strong><?php esc_html_e('Label', 'mail-boxes-etc') . " " . ($i + 1) . ": "; ?></strong> <a target="_blank" href="<?php esc_attr_e($this->helper->mbeUploadUrl(). DIRECTORY_SEPARATOR . $this->tracking_files[$i]); ?>"><?php esc_html_e("link", 'mail-boxes-etc'); ?></a>
110 </li>
111 <?php } ?>
112 <?php if (isset($this->closure_file)) { ?>
113 <li id="actions" class="wide">
114 <strong><?php esc_html_e('Closure file', 'mail-boxes-etc') . ": "; ?></strong> <a target="_blank" href="<?php esc_attr_e($this->closure_file); ?>"><?php esc_html_e("link", 'mail-boxes-etc'); ?></a>
115 </li>
116 <?php } ?>
117 </ul>
118 <script>
119 // jQuery(document).ready(function ($) {
120 // $("date-picker").datepicker();
121 // });
122
123 jQuery("a.woocommerce_shipment_tracking").on("click", function () {
124 location.href = this.href + '&wc_track_shipment=' + jQuery('#tracking_shipment_ids').val().replace(/ /g, '') + '&shipping_service=' + jQuery("#shipping_service").val();
125 return false;
126 });
127 </script>
128 <?php
129 }
130
131 function load_order($orderId)
132 {
133 if (!class_exists('WC_Order')) {
134 return false;
135 }
136 $order = false;
137
138 try {
139 $order = wc_get_order($orderId);
140 }
141 catch (Exception $e) {
142 }
143 return $order;
144 }
145 }
146
147 new woocommerce_mbe_tracking_admin();
148
149 ?>