plugin_info = $plugin_info; parent::__construct( $this->plugin_info ); } /** * Init base variables for plugin */ public function init_base_variables() { $this->plugin_url = $this->plugin_info->get_plugin_url(); $this->plugin_path = $this->plugin_info->get_plugin_dir(); $this->template_path = $this->plugin_info->get_text_domain(); $this->plugin_text_domain = $this->plugin_info->get_text_domain(); $this->plugin_namespace = $this->plugin_info->get_text_domain(); $this->template_path = $this->plugin_info->get_text_domain(); $this->settings_url = admin_url( 'admin.php?page=wc-settings&tab=shipping§ion=dpd' ); $this->default_settings_tab = 'main'; $this->default_view_args = [ 'plugin_url' => $this->get_plugin_url(), ]; } /** * Init classes */ public function init() { ( new WPDesk_DPD_Tracker() )->hooks(); TrackerInitializer::create_from_plugin_info_for_shipping_method( $this->plugin_info, WPDesk_WooCommerce_DPD_Shipping_Method::SHIPPING_METHOD_ID )->hooks(); add_action( 'plugins_loaded', function () { if ( class_exists( 'WPDesk_Flexible_Shipping_Shipment' ) ) { require_once $this->plugin_path . '/classes/class-flexible-shipping-shipment.php'; WPDesk_Flexible_Shipping_Shipment_dpd::$woocommerce_dpd_plugin = $this; } } ); add_action( 'plugins_loaded', [ $this, 'init_labels_builder' ] ); $this->init_renderer(); parent::init(); } /** * Init renderer. */ private function init_renderer() { $resolver = new ChainResolver(); $resolver->appendResolver( new WPThemeResolver( $this->template_path ) ); $resolver->appendResolver( new DirResolver( trailingslashit( $this->plugin_path ) . 'templates' ) ); $this->renderer = new SimplePhpRenderer( $resolver ); } /** * Init labels builder. */ public function init_labels_builder() { if ( class_exists( '\FSVendor\WPDesk\FS\Shipment\Label\LabelsBulkActionHandler' ) ) { $labels_bulk_actions_handler = LabelsBulkActionHandler::get_labels_bulk_actions_handler(); $labels_bulk_actions_handler->add_builder( new WPDesk_Flexible_Shipping_Dpd_Label_Builder( WPDesk_WooCommerce_DPD_Shipping_Method::SHIPPING_METHOD_ID ) ); } } /** * Fires hooks */ public function hooks() { parent::hooks(); add_action( 'plugins_loaded', [ $this, 'plugins_loaded' ] ); add_filter( 'flexible_printing_integrations', [ $this, 'flexible_printing_integrations' ] ); add_filter( 'flexible_shipping_has_manifests', '__return_true' ); add_action( 'woocommerce_init', [ $this, 'init_hookable_objects' ] ); } /** * @return void */ public function init_hookable_objects() { ( new HookableObjects( $this->get_plugin_assets_url(), $this->scripts_version, WC()->cart, $this->get_plugin_url(), WC()->session, $this->renderer ) )->hooks(); } /** * Load class */ public function plugins_loaded() { if ( function_exists( 'fs_get_order_shipments' ) ) { $this->dpd = WPDesk_WooCommerce_DPD::get_instance( $this ); new WPDesk_WooCommerce_DPD_FS_Hooks( $this ); } } /** * Add integration with Flexible Printing * * @param array $integrations Integrations list. * * @return array */ public function flexible_printing_integrations( array $integrations ) { $this->flexible_printing_integration = new WPDesk_WooCommerce_DPD_Flexible_Printing_Integration( $this ); $integrations[ $this->flexible_printing_integration->id ] = $this->flexible_printing_integration; return $integrations; } /** * Register/queue frontend scripts. */ public function wp_enqueue_scripts() { parent::wp_enqueue_scripts(); if ( is_checkout() ) { $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; wp_register_style( 'dpd_checkout_css', $this->get_plugin_assets_url() . 'css/checkout' . $suffix . '.css', [], $this->scripts_version ); wp_enqueue_style( 'dpd_checkout_css' ); wp_enqueue_script( 'dpd_checkout_js', $this->get_plugin_assets_url() . 'js/checkout' . $suffix . '.js', [ 'jquery' ], $this->scripts_version, true ); wp_localize_script( 'dpd_checkout_js', '__jsDpdVars', [ 'map_url' => trailingslashit( $this->plugin_url ) . 'pickup-point-map.php', 'l10n' => [ 'close_popup' => __( 'Zamknij mapÄ™', 'woocommerce-dpd' ), ], ] ); } } /** * Register/queue admin scripts. */ public function admin_enqueue_scripts() { $current_screen = get_current_screen(); $suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min'; if ( 'woocommerce_page_wc-settings' === $current_screen->id ) { $sender_address_assets = new Assets(); $sender_address_assets->enqueue( $this->get_plugin_assets_url() . '/../../vendor_prefixed/wpdesk/wp-settings-field-sender-address', $suffix, $this->scripts_version ); } if ( in_array( $current_screen->id, [ 'shop_order', 'edit-shop_order', 'woocommerce_page_wc-orders' ], true ) ) { wp_register_style( 'dpd_admin_css', $this->get_plugin_assets_url() . 'css/admin' . $suffix . '.css', [], $this->scripts_version ); wp_enqueue_style( 'dpd_admin_css' ); wp_enqueue_script( 'dpd_admin_order_js', $this->get_plugin_assets_url() . 'js/admin-order' . $suffix . '.js', [ 'jquery' ], $this->scripts_version, true ); wp_localize_script( 'dpd_admin_order_js', 'dpd_ajax_object', [ 'ajax_url' => admin_url( 'admin-ajax.php' ) ] ); } } /** * Add action links * * @param array $links Plugin action links. * * @return array */ public function links_filter( $links ) { $plugin_links = [ 'settings' => '' . __( 'Ustawienia', 'woocommerce-dpd' ) . '', 'docs' => '' . __( 'Dokumentacja', 'woocommerce-dpd' ) . '', 'support' => '' . __( 'Wsparcie', 'woocommerce-dpd' ) . '', ]; return array_merge( $plugin_links, $links ); } /** * Renders and returns selected template * * @param string $name name of the template. * @param string $path additional inner path to the template. * @param array $args args accesible from template. * * @return string */ public function load_template( $name, $path = '', $args = [] ) { $plugin_template_path = trailingslashit( $this->plugin_path ) . 'templates/'; // Look within passed path within the theme - this is priority. $template = locate_template( [ trailingslashit( $this->get_template_path() ) . trailingslashit( $path ) . $name . '.php', ] ); if ( ! $template ) { $template = $plugin_template_path . trailingslashit( $path ) . $name . '.php'; } extract( $args ); // phpcs:ignore ob_start(); include $template; return ob_get_clean(); } /** * Get template path * * @return string */ public function get_template_path() { return trailingslashit( $this->template_path ); } }