plugin = $plugin; $this->id = 'paczkomaty_shipping_method'; $this->title = 'InPost'; add_action( 'paczkomaty_shipping_method_shipment_created', array( $this, 'paczkomaty_shipping_method_shipment_created' ) ); add_action( 'flexible_shipping_shipment_status_updated', array( $this, 'flexible_shipping_shipment_status_updated' ), 10, 3 ); add_action( 'flexible_shipping_shipping_actions_html', array( $this, 'flexible_shipping_shipping_actions_html' ) ); } /** * @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() == 'paczkomaty' ) { $all_shipping_methods = WC()->shipping()->get_shipping_methods(); /** @var WC_Paczkomaty_Shipping_Method $shipping_method */ $shipping_method = $all_shipping_methods['paczkomaty_shipping_method']; if ( $shipping_method->get_option( 'auto_print', 'no' ) == 'yes' ) { $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 ); } } } /** * @param $order * * @throws Exception */ public function paczkomaty_shipping_method_shipment_created( $order ) { $all_shipping_methods = WC()->shipping()->get_shipping_methods(); /** @var WC_Paczkomaty_Shipping_Method $shipping_method */ $shipping_method = $all_shipping_methods['paczkomaty_shipping_method']; if ( $shipping_method->get_option( 'auto_print', 'no' ) == 'yes' ) { $paczkomat_packcode = wpdesk_get_order_meta( $order, '_paczkomat_packcode', true ); $label_data = $this->plugin->paczkomaty->get_label( $order ); try { $content_type = 'application/pdf'; if ( $label_data['label_format'] ) { $content_type = 'application/' . $label_data['label_format']; } $this->do_print( 'inpost_' . $paczkomat_packcode, $label_data['content'], $content_type, false ); } catch ( Exception $e ) { error_log( sprintf( __( 'Blad drukowania: %s', 'woocommerce-paczkomaty-inpost' ), $e->getMessage() ) ); } } } /** * @return array */ public function options() { $options = array(); return $options; } /** * @param $args * * @throws Exception */ 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(); } else { $post_id = $args['data']['post_id']; $order = wc_get_order($post_id); $label_data = $this->plugin->paczkomaty->get_label($order); } $content_type = 'application/pdf'; if ( $label_data['label_format'] ) { $content_type = 'application/' . $label_data['label_format']; } $paczkomat_packcode = $args['data']['paczkomat_packcode']; $args = array( 'title' => 'inpost_' . $paczkomat_packcode, 'content' => $label_data['content'], 'content_type' => $content_type, 'silent' => false ); do_action( 'flexible_printing_print', 'paczkomaty_shipping_method', $args ); } /** * @param $shipping */ 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', '' ) == 'paczkomaty' ) { if ( $shipment->get_label_url() != null ) { echo apply_filters( 'flexible_printing_print_button', '', 'paczkomaty_shipping_method', array( 'content' => 'print', 'icon' => true, 'id' => $shipment->get_meta('_paczkomat_packcode' ), 'tip' => __( 'Drukuj na: %s', 'woocommerce-paczkomaty-inpost' ), 'data' => array( 'shippment_id' => $shipment->get_id(), 'paczkomat_packcode' => $shipment->get_meta('_paczkomat_packcode' ), ), ) ); } } } /* old solution */ if ( isset( $shipping['integration'] ) && $shipping['integration'] == 'paczkomaty_shipping_method' ) { if ( $shipping['status'] == 'confirmed' ) { echo apply_filters( 'flexible_printing_print_button', '', 'paczkomaty_shipping_method', array( 'content' => 'print', 'icon' => true, 'id' => $shipping['paczkomat_packcode'], 'tip' => __( 'Drukuj na: %s', 'woocommerce-paczkomaty-inpost' ), 'data' => array( 'post_id' => $shipping['order_id'], 'paczkomat_packcode' => $shipping['paczkomat_packcode'], ), ) ); } } } } }