plugin = $plugin; $this->id = 'dhl'; $this->title = 'DHL'; add_action( 'woocommerce_dhl_shipment_created', array( $this, 'woocommerce_dhl_shipment_created' ), 10, 2 ); add_action( 'flexible_shipping_shipping_actions_html', array( $this, 'flexible_shipping_shipping_actions_html' ) ); add_action( 'flexible_shipping_shipment_status_updated', array( $this, 'flexible_shipping_shipment_status_updated' ), 10, 3 ); } /** * @param $old_status string * @param $new_status string * @param $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */ public function flexible_shipping_shipment_status_updated( $old_status, $new_status, $shipment ) { if ( $new_status != $old_status && $new_status == 'fs-confirmed' && $shipment->get_integration() == 'dhl' ) { $all_shipping_methods = WC()->shipping()->get_shipping_methods(); $shipping_method = $all_shipping_methods['dhl']; if ( $shipping_method->get_option( 'auto_print', 'no' ) == 'yes' ) { try { $label_data = $shipment->get_label(); $content_type = 'application/pdf'; if ( $label_data['label_format'] ) { $content_type = 'application/' . $label_data['label_format']; } $this->do_print( $label_data['file_name'], $label_data['content'], $content_type, false ); } catch ( Exception $e) { error_log( 'DHL flexible_shipping_shipment_status_updated: ' . $e->getMessage() ); } } } } public function woocommerce_dhl_shipment_created( WC_Order $order, $shipment ) { $shipping_method = $this->plugin->dhl->get_shipping_method(); if ( $shipping_method->get_option( 'auto_print', 'no' ) == 'yes' ) { $label_data = $this->plugin->dhl->get_label( $shipment->createShipmentsResult->item->shipmentId ); try { $content_type = 'application/pdf'; if ( $label_data->getLabelsResult->item->labelType == 'zpl' ) { $content_type = 'application/zpl'; } $this->do_print( 'dhl_' . $label_data->getLabelsResult->item->labelType . '_' . $label_data->getLabelsResult->item->labelName, base64_decode( $label_data->getLabelsResult->item->labelData ), $content_type, false ); } catch ( Exception $e ) { error_log( sprintf( __( 'Blad drukowania: %s', 'woocommerce-dhl' ), $e->getMessage() ) ); } } } public function options() { $options = array(); /* $options[] = array( 'id' => 'auto_print', 'name' => __('Automatyczne drukowanie', 'woocommerce-dhl'), 'desc' => __('Włącz (po utworzeniu etykieta zostanie automatycznie wydrukowana)', 'woocommerce-dhl'), 'type' => 'checkbox', 'std' => '', ); */ return $options; } public function do_print_action( $args ) { if ( !empty( $args['data']['shippment_id'] ) ) { $shipment = fs_get_shipment( $args['data']['shippment_id'] ); /* @var $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */ $label_data = $shipment->get_label(); $args = array( 'title' => $label_data['file_name'], 'content' => $label_data['content'], 'content_type' => 'application/' . $label_data['label_format'], 'silent' => false ); } else { $shipment_id = $args['data']['shipment_id']; $label_data = $this->plugin->dhl->get_label( $shipment_id ); $content_type = 'application/pdf'; if ($label_data->getLabelsResult->item->labelType == 'ZBLP') { $content_type = 'application/zpl'; } $args = array( 'title' => 'dhl_' . $label_data->getLabelsResult->item->labelType . '_' . $label_data->getLabelsResult->item->labelName, 'content' => base64_decode($label_data->getLabelsResult->item->labelData), 'content_type' => $content_type, 'silent' => false ); } do_action( 'flexible_printing_print', 'dhl', $args ); } public function flexible_shipping_shipping_actions_html( $shipping ) { if ( !empty( $shipping['shipment'] ) ) { $shipment = $shipping['shipment']; /* @var $shipment WPDesk_Flexible_Shipping_Shipment|WPDesk_Flexible_Shipping_Shipment_Interface */ if ( $shipment->get_meta( '_integration', '' ) == 'dhl' ) { if ( $shipment->get_label_url() != null ) { echo apply_filters( 'flexible_printing_print_button', '', 'dhl', array( 'content' => 'print', 'icon' => true, 'id' => $shipment->get_meta('_dhl_package_number' ), 'tip' => __( 'Drukuj na: %s', 'woocommerce-dhl' ), 'data' => array( 'shippment_id' => $shipment->get_id(), 'dhl_package_number' => $shipment->get_meta('_dhl_package_number' ), ), ) ); } } } /* stare rozwiązanie */ else if ( isset( $shipping['integration'] ) && $shipping['integration'] == 'dhl' ) { $package = $shipping['integration_data']; if ( $package['dhl_status'] == 'ok' ) { echo apply_filters( 'flexible_printing_print_button', '', 'dhl', array( 'content' => 'print', 'icon' => true, 'id' => $package['dhl_package']->createShipmentsResult->item->shipmentId, 'tip' => __( 'Drukuj na: %s', 'woocommerce-dhl' ), 'data' => array( 'post_id' => $shipping['order_id'], 'count' => $shipping['count'], 'shipment_id' => $package['dhl_package']->createShipmentsResult->item->shipmentId, ), ) ); } } } } }