'; protected function __construct() { add_filter( 'brandy_extra_localize', array( $this, 'add_localize_data' ) ); $this->default_currencies = $this->get_available_currencies(); parent::__construct(); } protected function register_components() { $typo = TypographyService::get_default_typography_value(); return array( 'list_currencies' => array( 'value_path' => array(), 'default_value' => array(), 'type' => 'ListCurrencies', ), 'currency_icon_enabled' => array( 'value_path' => array( 'currency_flag_enabled' ), 'title' => array( 'text' => __( 'Show currency flag', 'brandy' ), 'type' => 'bold', ), 'default_value' => true, 'type' => 'Switcher', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'custom_variables', 'selector' => '.brandy-currency-flag', 'value_path' => array( 'currency_icon_enabled' ), 'mapping_variables' => array( array( 'condition' => array( 'value' => true, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'flex', ), ), ), array( 'condition' => array( 'value' => false, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'none', ), ), ), ), ), ), ), ), 'currency_icon_position' => array( 'title' => array( 'text' => __( 'Icon Position', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'currency_icon_position' ), 'type' => 'Position', 'default_value' => 'left', 'available_positions' => array( 'left', 'right' ), 'render_options' => array( 'type' => 'data_attribute', 'data' => array( array( 'selector' => '.brandy-currency-box', 'value_path' => array( 'currency_icon_position' ), 'name' => 'flag-position', ), ), ), ), 'arrow_icon_enabled' => array( 'value_path' => array( 'show_arrow_icon' ), 'title' => array( 'text' => __( 'Show arrow icon', 'brandy' ), 'type' => 'bold', ), 'default_value' => true, 'type' => 'Switcher', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'custom_variables', 'selector' => '.brandy-currency-arrow', 'value_path' => array( 'show_arrow_icon' ), 'mapping_variables' => array( array( 'condition' => array( 'value' => true, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'block', ), ), ), array( 'condition' => array( 'value' => false, 'operator' => 'equal', ), 'path' => array(), 'mapping' => array( 'desktop' => array( 'display' => 'none', ), ), ), ), ), ), ), ), //design 'design_symbol_reset' => array( 'title' => array( 'text' => __( 'Currency flag', 'brandy' ), 'type' => 'bold', 'show_devices' => true, ), 'type' => 'Reset', 'reset_paths' => array( array( 'design_symbol' ), ), ), 'design_symbol_size' => array( 'title' => array( 'text' => __( 'Flag size', 'brandy' ), 'type' => 'normal', ), 'value_path' => array( 'design_symbol', 'size' ), 'default_value' => array( 'desktop' => ElementsLoader::get_default_icon_size(), 'tablet' => null, 'mobile' => null, ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--symbol-size', 'value_path' => array( 'design_symbol', 'size' ), ), ), ), ), 'design_margin' => array( 'value_path' => array( 'design_margin' ), 'title' => array( 'text' => 'Margin', 'type' => 'bold', ), 'default_value' => array( 'unit' => 'px', 'top' => 0, 'right' => 0, 'bottom' => 0, 'left' => 0, 'is_constraints' => false, ), 'type' => 'Spacing', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'spacing', 'selector' => '.brandy-currency-element', 'name' => 'margin', 'value_path' => array( 'design_margin' ), ), ), ), ), 'currency_item_reset' => array( 'type' => 'Reset', 'title' => array( 'text' => __( 'Currency item', 'brandy' ), 'type' => 'bold', 'show_devices' => true, ), 'reset_paths' => array( array( 'currency_item' ), ), ), 'currency_item_color' => array( 'value_path' => array( 'currency_item', 'color' ), 'title' => array( 'text' => 'Text color', 'type' => 'normal', ), 'default_value' => array( 'normal' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), 'active' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), ), 'is_responsive' => true, 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--currency-item-color', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'color' ), ), ), ), 'visible_conditions' => array( array( 'value_path' => array( 'flag_name', 'display' ), 'value' => true, ), ), ), 'currency_item_typography' => array( 'value_path' => array( 'currency_item', 'typography' ), 'title' => array( 'text' => 'Typography', 'type' => 'normal', ), 'default_value' => TypographyService::get_value( array( 'font_size' => array( 'desktop' => array( 'unit' => 'px', 'value' => 14, ), ), ) ), 'type' => 'Typography', 'is_responsive' => true, 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'typography', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'typography' ), ), ), ), ), 'currency_item_activator_typography' => array( 'value_path' => array( 'currency_item', 'activator_typography' ), 'title' => array( 'text' => __( 'Active typography', 'brandy' ), 'type' => 'normal', ), 'default_value' => TypographyService::get_value( array( 'font_size' => array( 'desktop' => array( 'unit' => 'px', 'value' => 14, ), ), 'font_style' => array( 'desktop' => array( 'weight' => 600, ), ), ) ), 'type' => 'Typography', 'is_responsive' => true, 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'typography', 'selector' => '.brandy-currency-option.current-currency', 'value_path' => array( 'currency_item', 'activator_typography' ), ), ), ), ), 'currency_item_background' => array( 'value_path' => array( 'currency_item', 'background' ), 'title' => array( 'text' => 'Background', 'type' => 'normal', ), 'default_value' => array( 'normal' => array( 'desktop' => '#ffffff00', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => '#f1f3f7', 'tablet' => null, 'mobile' => null, ), 'active' => array( 'desktop' => '#f1f3f7', 'tablet' => null, 'mobile' => null, ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--currency-item-background', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'background' ), ), ), ), ), 'currency_item_stroke_color' => array( 'value_path' => array( 'currency_item', 'stroke_color' ), 'title' => array( 'text' => 'Stroke color', 'type' => 'normal', ), 'default_value' => array( 'normal' => array( 'desktop' => '#ffffff00', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => '#2170b038', 'tablet' => null, 'mobile' => null, ), 'active' => array( 'desktop' => '#2170b038', 'tablet' => null, 'mobile' => null, ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--currency-item-stroke-color', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'stroke_color' ), ), ), ), ), 'currency_item_stroke_width' => array( 'value_path' => array( 'currency_item', 'stroke_width' ), 'title' => array( 'text' => 'Stroke width', 'type' => 'normal', ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'value' => 0, 'min' => 0, 'max' => 30, ), 'tablet' => null, 'mobile' => null, ), 'units' => array( 'px' ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--currency-item-stroke-width', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'stroke_width' ), ), ), ), ), 'currency_item_border_radius' => array( 'value_path' => array( 'currency_item', 'border_radius' ), 'title' => array( 'text' => 'Border radius', 'type' => 'normal', ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'value' => 0, 'min' => 0, 'max' => 100, ), 'tablet' => null, 'mobile' => null, ), 'units' => array( 'px', '%' ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--currency-item-border-radius', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'border_radius' ), ), ), ), ), 'currency_item_spacing' => array( 'value_path' => array( 'currency_item', 'spacing' ), 'title' => array( 'text' => 'Item Spacing', 'type' => 'normal', ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'value' => 0, 'min' => 0, 'max' => 24, ), 'tablet' => null, 'mobile' => null, ), 'units' => array( 'px' ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => 'gap', 'selector' => '.brandy-currency-options', 'value_path' => array( 'currency_item', 'spacing' ), ), ), ), ), 'currency_item_padding' => array( 'value_path' => array( 'currency_item', 'padding' ), 'title' => array( 'text' => __( 'Item padding', 'brandy' ), 'type' => 'normal', ), 'units' => array( 'px' ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'top' => 8, 'right' => 16, 'bottom' => 8, 'left' => 16, 'is_constraints' => false, ), 'tablet' => null, 'mobile' => null, ), 'type' => 'Spacing', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'spacing', 'name' => 'padding', 'selector' => '.brandy-currency-option', 'value_path' => array( 'currency_item', 'padding' ), ), ), ), ), 'dropdown_reset' => array( 'title' => array( 'text' => __( 'Dropdown', 'brandy' ), 'type' => 'bold', 'show_devices' => true, ), 'type' => 'Reset', 'reset_paths' => array( array( 'dropdown_padding', 'activator', ), array( 'activator', ), ), ), 'activator_background' => array( 'value_path' => array( 'activator', 'background' ), 'title' => array( 'text' => __( 'Background', 'brandy' ), 'type' => 'normal', ), 'default_value' => array( 'normal' => array( 'desktop' => '#ffffff00', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => '#ffffff00', 'tablet' => null, 'mobile' => null, ), // 'active' => array( // 'desktop' => '#2170b014', // 'tablet' => null, // 'mobile' => null, // ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--activator-background', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'background' ), ), ), ), ), 'activator_stroke_color' => array( 'value_path' => array( 'activator', 'stroke_color' ), 'title' => array( 'text' => __( 'Stroke color', 'brandy' ), 'type' => 'normal', ), 'default_value' => array( 'normal' => array( 'desktop' => '#ffffff', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => '#2170b038', 'tablet' => null, 'mobile' => null, ), // 'active' => array( // 'desktop' => '#2170b038', // 'tablet' => null, // 'mobile' => null, // ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--activator-stroke-color', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'stroke_color' ), ), ), ), ), 'activator_stroke_width' => array( 'value_path' => array( 'activator', 'stroke_width' ), 'title' => array( 'text' => __( 'Stroke width', 'brandy' ), 'type' => 'normal', ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'value' => 0, 'min' => 0, 'max' => 30, ), 'tablet' => null, 'mobile' => null, ), 'units' => array( 'px' ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--activator-stroke-width', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'stroke_width' ), ), ), ), ), 'activator_border_radius' => array( 'value_path' => array( 'activator', 'border_radius' ), 'title' => array( 'text' => __( 'Border radius', 'brandy' ), 'type' => 'normal', ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'value' => 0, 'min' => 0, 'max' => 100, ), 'tablet' => null, 'mobile' => null, ), 'units' => array( 'px', '%' ), 'type' => 'Dimension', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'dimension', 'name' => '--activator-border-radius', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'border_radius' ), ), ), ), ), 'activator_padding' => array( 'value_path' => array( 'activator', 'padding' ), 'title' => array( 'text' => __( 'Padding', 'brandy' ), 'type' => 'normal', ), 'units' => array( 'px' ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'top' => 0, 'right' => 0, 'bottom' => 0, 'left' => 0, 'is_constraints' => false, ), 'tablet' => null, 'mobile' => null, ), 'type' => 'Spacing', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'spacing', 'name' => 'padding', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'padding' ), ), ), ), ), 'activator_typography' => array( 'value_path' => array( 'activator', 'typography' ), 'title' => array( 'text' => __( 'Typography', 'brandy' ), 'type' => 'normal', ), 'default_value' => TypographyService::get_value( array( 'font_size' => array( 'desktop' => array( 'unit' => 'px', 'value' => 14, ), ), 'font_style' => array( 'desktop' => array( 'weight' => 500, ), ), ) ), 'is_responsive' => true, 'type' => 'Typography', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'typography', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'typography' ), ), ), ), ), 'activator_color' => array( 'value_path' => array( 'activator', 'color' ), 'title' => array( 'text' => __( 'Text color', 'brandy' ), 'type' => 'normal', ), 'default_value' => array( 'normal' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), 'hover' => array( 'desktop' => 'var(--wp--preset--color--brandy-primary-text)', 'tablet' => null, 'mobile' => null, ), ), 'type' => 'ColorGroup', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'color', 'name' => '--activator-color', 'selector' => '.brandy-currency-switcher__placeholder', 'value_path' => array( 'activator', 'color' ), ), ), ), ), 'dropdown_padding' => array( 'value_path' => array( 'dropdown_padding' ), 'title' => array( 'text' => __( 'Dropdown padding', 'brandy' ), 'type' => 'normal', ), 'units' => array( 'px' ), 'default_value' => array( 'desktop' => array( 'unit' => 'px', 'top' => 3, 'right' => 0, 'bottom' => 3, 'left' => 0, 'is_constraints' => false, ), 'tablet' => null, 'mobile' => null, ), 'type' => 'Spacing', 'render_options' => array( 'type' => 'variable', 'data' => array( array( 'type' => 'spacing', 'selector' => '.brandy-currency-options', 'name' => 'padding', 'value_path' => array( 'dropdown_padding' ), ), ), ), ), ); } public function add_layout( $layouts = array() ) { $layout = array( 'general' => array( 'sections' => array( array( 'components' => array( 'list_currencies', ), ), array( 'components' => array( 'currency_icon_enabled', 'currency_icon_position', ), ), array( 'components' => array( 'arrow_icon_enabled', ), ), ), ), 'designs' => array( 'sections' => array( array( 'components' => array( 'design_symbol_reset', 'design_symbol_size', ), ), array( 'components' => array( 'dropdown_reset', 'dropdown_padding', 'activator_background', 'activator_stroke_color', 'activator_stroke_width', 'activator_border_radius', 'activator_padding', 'activator_typography', 'activator_color', ), ), array( 'components' => array( 'currency_item_reset', 'currency_item_typography', 'currency_item_activator_typography', 'currency_item_background', 'currency_item_stroke_color', 'currency_item_stroke_width', 'currency_item_border_radius', 'currency_item_spacing', 'currency_item_padding', ), ), array( 'components' => array( 'design_margin', ), ), ), ), ); $mapped_layout = $this->map_layout( $layout ); $layouts[ $this->element_id ] = $mapped_layout; return $layouts; } public function add_localize_data( $localize_data ) { $localize_data['currency'] = array( 'list' => $this->get_available_currencies(), ); return $localize_data; } public function get_available_currencies() { if ( class_exists( 'Yay_Currency\Helpers\Helper' ) ) { $currencies = apply_filters( 'yay_currency_get_currencies_posts', \Yay_Currency\Helpers\Helper::get_currencies_post_type() ); $res = array(); foreach ( $currencies as $currency ) { $code = $currency->post_title; $res[] = array( 'id' => $code, 'name' => $currency->post_title, 'flag' => self::get_currency_flag( $code ), 'symbol' => get_woocommerce_currency_symbol( $code ), 'yay_id' => $currency->ID, ); } return $res; } return null; } public static function get_currency_flag( $code ) { $countries_code = array(); $flag = ''; if ( class_exists( '\Yay_Currency\Helpers\Helper' ) ) { if ( is_callable( array( '\Yay_Currency\Helpers\Helper', 'currency_code_by_country_code' ) ) ) { $countries_code = \Yay_Currency\Helpers\Helper::currency_code_by_country_code(); } if ( is_callable( array( '\Yay_Currency\Helpers\CountryHelper', 'currency_code_by_country_code' ) ) ) { $countries_code = \Yay_Currency\Helpers\CountryHelper::currency_code_by_country_code(); } $selected_country_code = $countries_code[ $code ] ?? null; if ( ! empty( $selected_country_code ) && is_callable( array( '\Yay_Currency\Helpers\Helper', 'get_flag_by_country_code' ) ) ) { $flag = \Yay_Currency\Helpers\Helper::get_flag_by_country_code( $selected_country_code ); } if ( ! empty( $selected_country_code ) && is_callable( array( '\Yay_Currency\Helpers\CountryHelper', 'get_flag_by_country_code' ) ) ) { $flag = \Yay_Currency\Helpers\CountryHelper::get_flag_by_country_code( $selected_country_code ); } } return $flag; } }