PluginProbe
MakeCommerce for WooCommerce / 3.0.9
MakeCommerce for WooCommerce v3.0.9
4.1.0 4.0.8 trunk 1.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.2.0 2.2.1 2.2.2 All 96 releases
← All changes | shipping/label.php +107 -70 trunk3.0.9 View file →
@@ -50,10 +50,8 @@
50 50 $this->loader->add_action( 'wp_ajax_print_pml', $this, 'print' );
51 51 $this->loader->add_filter( 'admin_action_parcel_machine_print_labels', $this, 'bulk_print' );
52 52 $this->loader->add_filter( 'admin_footer', $this, 'bulk_print_and_register' );
53 53 $this->loader->add_filter( 'admin_action_parcel_machine_labels', $this, 'bulk_register' );
54 - // HPOS bulk action handling
55 - $this->loader->add_filter( 'handle_bulk_actions-woocommerce_page_wc-orders', $this, 'handle_bulk_action' );
56 54 }
57 55
58 56 /**
59 57 * Creates shipping label using MakeCommerce API and redirect to the page where it is available or return data
@@ -59,33 +57,34 @@
59 57 * Creates shipping label using MakeCommerce API and redirect to the page where it is available or return data
60 58 *
61 59 * @since 3.0.0
62 60 */
63 - public function create_labels( $post_ids, $ajax = false, $hpos = false ) {
61 + public function create_labels( $post_ids, $ajax = false ) {
64 62
65 63 if ( !is_array( $post_ids ) ) {
66 - $post_ids = [$post_ids];
64 + $post_ids = array( $post_ids );
67 65 }
68 66
69 67 $this->initalize();
70 68
71 - $shipping_request = ['credentials' => [], 'orders' => [], 'printFormat' => $this->page_format];
69 + $shipping_request = array( 'credentials' => array(), 'orders' => array(), 'printFormat' => $this->page_format );
72 70
73 71 foreach ( $this->shipping_methods as $shipping_method ) {
74 72 $shipping_classes_map[$shipping_method["method"]] = $shipping_method["class"];
75 73 }
76 74
77 - $missing_ids = [];
75 + $missing_ids = array();
78 76
79 77 foreach ( $post_ids as $post_id ) {
80 - $order = wc_get_order( $post_id );
81 - $shipment_id = $order->get_meta( '_parcel_machine_shipment_id', true );
78 +
79 + $shipment_id = get_post_meta( $post_id, '_parcel_machine_shipment_id', true );
82 80
83 81 if ( !$shipment_id ) {
84 82 $missing_ids[] = $post_id;
85 83 continue;
86 84 }
87 -
85 +
86 + $order = new \WC_Order( $post_id );
88 87 $shipping_methods = $order->get_shipping_methods();
89 88
90 89 if ( empty( $shipping_methods ) ) {
91 90 continue;
@@ -101,39 +100,109 @@
101 100 continue;
102 101 }
103 102
104 103 $transport_class = new $shipping_classes_map[$shipping_class]($shipping_instance);
105 - $carrier_uc = mb_strtoupper( $transport_class->carrier_id );
104 + $carrier_uc = mb_strtoupper( $transport_class->carrier );
105 +
106 + //apt == parcelmachine
107 + if ( $transport_class->type === 'apt' ) {
106 108
107 - //change carrier_uc if it has been set in the interface.
108 - if ( isset( $transport_class->settings['service_carrier'] ) ) {
109 - $carrier_uc = $transport_class->settings['service_carrier'];
110 - }
109 + $parcel_machine = get_post_meta( $post_id, '_parcel_machine', true );
110 +
111 + if ( !$parcel_machine ) {
112 + continue;
113 + }
114 +
115 + list( $carrier, $machine_id ) = explode( '||', $parcel_machine );
116 +
117 + if ( !$carrier || !$machine_id ) {
118 + continue;
119 + }
120 + }
111 121
112 122 if ( empty( $shipping_request['credentials'][$carrier_uc] ) ) {
113 - $shipping_request = $this->set_shipping_request_credentials( $carrier_uc, $transport_class, $shipping_request );
114 - // Move on to next post if the function returned empty values
115 - if ( empty( $shipping_request['credentials'][$carrier_uc] ) && empty( $transport_class->settings['use_mk_contract'] ) ) {
123 +
124 + $api_user = $transport_class->settings['service_user'];
125 + $api_password = $transport_class->settings['service_password'];
126 +
127 + $use_mk_contract = false;
128 +
129 + if ( isset( $transport_class->settings['use_mk_contract'] ) ) {
130 + $use_mk_contract = $transport_class->settings['use_mk_contract'];
131 + }
132 +
133 + //change carrier_uc if it has been set in the interface.
134 + if ( isset( $transport_class->settings['service_carrier'] ) ) {
135 + $carrier_uc = $transport_class->settings['service_carrier'];
136 + }
137 +
138 + if ( ( !$api_user || !$api_password ) and ( !$use_mk_contract ) ) {
139 +
140 + $this->loader->add_action( 'admin_notices', $this, 'mk_admin_error' );
116 141 continue;
117 142 }
143 +
144 + if ( !$use_mk_contract ) {
145 + $shipping_request['credentials'][$carrier_uc] = array( 'carrier' => $carrier_uc, 'username' => $api_user, 'password' => $api_password );
146 + }
118 147 }
148 +
149 + $sender = array(
150 + 'name' => $transport_class->settings['shop_name'],
151 + 'phone' => $transport_class->settings['shop_phone'],
152 + 'email' => $transport_class->settings['shop_email'],
153 + 'postalCode' => !empty( $transport_class->settings['shop_postal_code'] ) ? $transport_class->settings['shop_postal_code'] : '',
154 + 'country' => !empty( $transport_class->settings['shop_address_country'] ) ? $transport_class->settings['shop_address_country'] : '',
155 + 'city' => !empty( $transport_class->settings['shop_address_city'] ) ? $transport_class->settings['shop_address_city'] : '',
156 + 'street' => !empty( $transport_class->settings['shop_address_street'] ) ? $transport_class->settings['shop_address_street'] : ''
157 + );
158 +
159 + $shipping_information = $this->get_order_shipping_information( $order );
160 +
161 + $sr_order = array(
162 + 'carrier' => $carrier_uc,
163 + 'orderId' => $order->get_id(),
164 + 'recipient' => array( 'name' => $shipping_information['recipient_name'], 'phone' => $shipping_information['phone'], 'email' => $shipping_information['email'] ),
165 + 'sender' => $sender,
166 + 'shipmentId' => $shipment_id
167 + );
168 +
169 + $m_service_type = null;
119 170
120 - $sr_order = $this->set_sr_order_data(
121 - $order,
122 - $transport_class,
123 - $shipping_class,
124 - $carrier_uc,
125 - $shipment_id,
126 - true,
127 - );
171 + if ( $transport_class->carrier === 'omniva' && $transport_class->type === 'atp' ) {
172 + $m_service_type = 'PA';
173 + } else if ( !empty( $transport_class->settings['registerOnPaymentCode'] ) ) {
174 + $m_service_type = $transport_class->settings['registerOnPaymentCode'];
175 + }
128 176
129 - if ( !$sr_order ) continue;
177 + if ( !empty( $machine_id ) ) {
178 + $sr_order['destination']['destinationId'] = $machine_id;
179 + }
180 +
181 + if ( $transport_class->type === 'cou' ) {
130 182
131 - if ( $carrier_uc === 'LP_EXPRESS_LT' ) {
132 - $identifier = $order->get_meta( '_lp_express_cart_identifier', true );
133 - $sr_order['lpExpressShipmentDetails']['lpExpressCartIdentifier'] = $identifier;
183 + $sr_order['destination'] = array(
184 + 'postalCode' => $order->shipping_postcode,
185 + 'country' => $order->shipping_country,
186 + 'county' => $order->shipping_state,
187 + 'city' => $order->shipping_city,
188 + 'street' => $order->shipping_address_1 . ' ' . $order->shipping_address_2
189 + );
190 +
191 + if ( $shipping_class == "courier_smartpost" ) {
192 +
193 + $delivery_time = get_post_meta( $post_id, '_delivery_time', true );
194 +
195 + if ( $delivery_time ) {
196 + $sr_order['destination']['timeWindow'] = $delivery_time;
197 + }
198 + }
134 199 }
135 200
201 + if ( $m_service_type ) {
202 + $sr_order['services'] = array( 'serviceType' => $m_service_type );
203 + }
204 +
136 205 $shipping_request['orders'][] = $sr_order;
137 206 }
138 207 }
139 208
@@ -169,14 +238,10 @@
169 238 if ( !empty( $missing_ids ) ) {
170 239 $mk_err = sprintf( __( 'Orders %s did not have shipment ID attached so no labels was printed! Please register those packages if you think this is an error!', 'wc_makecommerce_domain' ), join( ', ', $missing_ids ) );
171 240 }
172 241
173 - if ( $hpos ) {
174 - $sendback = add_query_arg( ['page' => 'wc-orders', 'mk_pdf' => urlencode( $response->labelUrl ), 'mk_err' => urlencode( $mk_err ) ], '' );
175 - } else {
176 - $sendback = add_query_arg( ['post_type' => 'shop_order', 'mk_pdf' => urlencode( $response->labelUrl ), 'mk_err' => urlencode( $mk_err ) ], '' );
177 - }
178 -
242 + $sendback = add_query_arg( array( 'post_type' => 'shop_order', 'mk_pdf' => urlencode( $response->labelUrl ), 'mk_err' => urlencode( $mk_err ) ), '' );
243 +
179 244 wp_redirect( esc_url_raw( $sendback ) );
180 245
181 246 exit();
182 247 }
@@ -191,9 +256,9 @@
191 256 if ( !current_user_can( 'manage_woocommerce' ) ) {
192 257 die();
193 258 }
194 259
195 - echo $this->create_labels( [intval( $_POST['id'] )], true );
260 + echo $this->create_labels( array( intval( $_POST['id'] ) ), true );
196 261
197 262 die();
198 263 }
199 264
@@ -216,26 +281,17 @@
216 281 */
217 282 public function bulk_print_and_register() {
218 283
219 284 global $post_type;
220 - $enqueue = false;
221 -
285 +
222 286 //Should this even be done using JS???
223 287 if ( 'shop_order' === $post_type ) {
224 -
288 +
225 289 $args = [
226 - 'shipments_text' => __( 'Register parcel machine shipments', 'wc_makecommerce_domain' ),
227 - 'labels_text' => __( 'Print parcel machine labels', 'wc_makecommerce_domain' )
290 + 'shipments_text' => __( 'Register parcel machine shipments', 'wc_makecommerce_domain' ),
291 + 'labels_text' => __( 'Print parcel machine labels', 'wc_makecommerce_domain' )
228 292 ];
229 - $enqueue = true;
230 - }
231 - if ( !empty( $_GET['page'] ) && $_GET['page'] == 'wc-orders' ) {
232 - $args = [ 'hpos' => true ];
233 - $enqueue = true;
234 - }
235 293
236 - if ( $enqueue ) {
237 -
238 294 if ( !empty( $_REQUEST['mk_err'] ) ) {
239 295 $args["error"] = htmlspecialchars( $_REQUEST['mk_err'] );
240 296 }
241 297
@@ -271,11 +327,10 @@
271 327 *
272 328 * @since 3.0.0
273 329 */
274 330 public function print_button( $post_id ) {
275 - $order = wc_get_order( $post_id );
276 331
277 - if ( !$order->get_meta( '_parcel_machine_shipment_id', true ) ) {
332 + if ( !get_post_meta( $post_id, '_parcel_machine_shipment_id', true ) ) {
278 333 return;
279 334 }
280 335
281 336 echo '
@@ -293,23 +348,5 @@
293 348 ],
294 349 [ 'jquery' ]
295 350 );
296 351 }
297 -
298 - /**
299 - * Handles bulk actions when HPOS is enabled for WooCommerce
300 - *
301 - * @since 3.4.0
302 - */
303 - public function handle_bulk_action( $page ) {
304 - $ids = array_map( 'absint', ( array )$_REQUEST['id'] );
305 -
306 - if ( !empty( $ids ) ) {
307 -
308 - if ( $_GET['action'] == 'parcel_machine_register_orders' ) {
309 - $this->register_shipment( $ids );
310 - } elseif ( $_GET['action'] == 'parcel_machine_print_labels') {
311 - $this->create_labels( $ids, false, true );
312 - }
313 - }
314 - }
315 -}
352 +}