manifest = $manifest ?? []; } /** * Asset-URL basierend auf relativen Pfaden aus manifest.json zurückgeben. * * @param string $src Der relative Pfad des Assets. * @return string */ private function get_asset_url($src) { return plugins_url($src, IPSCMI_ORDER_CART_FILE); } /** * Frontend-Assets einbinden. */ public function enqueue_frontend_assets() { $this->conditionally_enqueue_frontend_assets(); } /** * Assets Frontend registrieren. */ public function register_frontend_assets() { $this->load_manifest('frontend'); // Frontend-Assets registrieren if (!empty($this->manifest['frontend'])) { foreach ($this->manifest['frontend']['scripts'] as $handle => $src) { if ($handle === 'ips-bootstrap-js') { wp_register_script('ipscmi-order-cart-bootstrap', $this->get_asset_url($src), [], IPSCMI_ORDER_CART_VERSION, true); } else { wp_register_script("ipscmi-order-cart-frontend-{$handle}", $this->get_asset_url($src), ['jquery'], IPSCMI_ORDER_CART_VERSION, true); } } foreach ($this->manifest['frontend']['styles'] as $handle => $src) { wp_register_style("ipscmi-order-cart-frontend-{$handle}", $this->get_asset_url($src), [], IPSCMI_ORDER_CART_VERSION, 'all'); } } } //############################################################################################################ //============================================================================================================ //############################################################################################################ /** * @return array,styles?:array}> */ private function frontend_asset_groups(): array { return [ 'sidecart' => [ // The React bundle owns the Sidecart UI. Only the shared icon // font is needed outside the bundle. 'scripts' => [], 'styles' => [ 'ips-woogeneralall-css' ], ], 'cartgate' => [ // Cart Gate's React notice reads product facts from the hidden // context field; variable-product facts must follow Woo events. 'scripts' => [ 'ips-cartgate-product-context-js' ], 'styles' => [ 'ips-woogeneralall-css' ], ], ]; } /** * @return array */ private function active_frontend_asset_groups(): array { $toggles = ModuleToggles::instance(); $groups = []; if ( $toggles->is_enabled( 'sidecart' ) ) { $groups[] = 'sidecart'; } if ( $toggles->is_enabled( 'cartgate' ) ) { $groups[] = 'cartgate'; } return $groups; } private function enqueue_frontend_asset_group( string $group ): bool { $asset_groups = $this->frontend_asset_groups(); if ( ! isset( $asset_groups[ $group ] ) || ! $this->asset_group_has_assets( $asset_groups[ $group ] ) ) { return false; } $this->enqueue_assets( $asset_groups[ $group ], 'frontend' ); return true; } private function asset_group_has_assets( array $assets ): bool { return ! empty( $assets['scripts'] ) || ! empty( $assets['styles'] ); } /** * Hilfsmethode, um Scripts und Styles zu enqueuen. */ private function enqueue_assets($assets, $type) { // Scripts if (!empty($assets['scripts'])) { foreach ($assets['scripts'] as $script) { if ( '' === $script ) { continue; } if ($script === 'ips-bootstrap-js') { // Spezielle Behandlung: Bootstrap wird über den Handle 'ipscmi-order-cart-bootstrap' enqueued. wp_enqueue_script('ipscmi-order-cart-bootstrap'); } else { wp_enqueue_script("ipscmi-order-cart-{$type}-{$script}"); } } } // Styles if (!empty($assets['styles'])) { foreach ($assets['styles'] as $style) { if ( '' === $style ) { continue; } wp_enqueue_style("ipscmi-order-cart-{$type}-{$style}"); } } } /** * Dynamisches Enqueue für Frontend-Assets. */ public function conditionally_enqueue_frontend_assets() { if ( ! ModuleToggles::instance()->any_frontend_module_enabled() ) { return; } $asset_groups = $this->active_frontend_asset_groups(); if ( [] === $asset_groups ) { return; } $this->register_frontend_assets(); foreach ( $asset_groups as $group ) { $this->enqueue_frontend_asset_group( $group ); } } /** * Generiert benutzerdefiniertes CSS basierend auf den Einstellungen. * * @return string Generierter CSS-Code. */ public function inline_style(){ $button_custom_css = $table_custom_css = ''; // CUSTOM BUTTON STYLE if ('custom' === wooordercart_get_option('button_style', 'wooorder_style_settings_tabs', 'default') ){ $btn_padding = wooorder_dimensions( 'btn_custom_padding', 'wooorder_style_settings_tabs', 'padding'); $btn_margin = wooorder_dimensions( 'button_custom_margin', 'wooorder_style_settings_tabs','margin'); $btn_border_radius = wooorder_dimensions('button_custom_border_radius','wooorder_style_settings_tabs', 'border-radius'); $btn_color = wooorder_generate_css('button_color', 'wooorder_style_settings_tabs', 'color'); $btn_bg_color = wooorder_generate_css('background_color','wooorder_style_settings_tabs', 'background-color'); // HOVER Button $btn_hover_color = wooorder_generate_css('button_hover_color', 'wooorder_style_settings_tabs', 'color'); $btn_hover_bg_color = wooorder_generate_css('hover_background_color', 'wooorder_style_settings_tabs','background-color'); // Generierter CSS-Code für den benutzerdefinierten Button-Stil $button_custom_css = " .wooorder-button{ {$btn_padding} {$btn_margin} {$btn_color} {$btn_bg_color} {$btn_border_radius} } .wooorder-button:hover{ {$btn_hover_color} {$btn_hover_bg_color} } "; } // Wooorder Wishlist Table STYLE if( 'custom' === wooordercart_get_option('table_style', 'wooorder_style_settings_tabs', 'default')){ $header_color = wooorder_generate_css('table_heading_color','wooorder_style_settings_tabs','color'); $heading_bg_color = wooorder_generate_css('table_heading_bg_color', 'wooorder_style_settings_tabs','background-color'); $heading_border_color = wooorder_generate_css('table_border_color', 'wooorder_style_settings_tabs', 'border-color'); $border_color = wooorder_generate_css('table_border_color','wooorder_style_settings_tabs', 'border-color'); // BUTTON - ADD TO CART $button_color = wooorder_generate_css('table_cart_button_color', 'wooorder_style_settings_tabs', 'color'); $button_bg_color = wooorder_generate_css('table_cart_button_bg_color', 'wooorder_style_settings_tabs', 'background-color'); $button_hover_color = wooorder_generate_css('table_cart_button_hover_color', 'wooorder_style_settings_tabs', 'color'); $button_hover_bg_color = wooorder_generate_css('table_cart_button_hover_bg_color', 'wooorder_style_settings_tabs', 'background-color'); // Generierter CSS-Code für den benutzerdefinierten Tabellenstil $table_custom_css = " .wooorder-table-content table thead > tr{ {$heading_border_color} } .wooorder-table-content table, .wooorder-table-content table tbody > tr{ {$border_color} } "; if ($button_color || $button_bg_color){ $table_custom_css .= " .wooorder-table-content table .wooorder-addtocart{ {$button_color} {$button_bg_color} } "; } if ($button_hover_color || $button_hover_bg_color){ $table_custom_css .= " .wooorder-table-content table .wooorder-addtocart:hover{ {$button_hover_color} {$button_hover_bg_color} } "; } } return $button_custom_css . $table_custom_css; } }