config.php
158 lines
| 1 | <?php |
| 2 | namespace ShopPress\Elementor\Widgets\LoopBuilder; |
| 3 | |
| 4 | use ShopPress\Elementor\ShopPressWidgets; |
| 5 | use Elementor\Controls_Manager; |
| 6 | |
| 7 | defined( 'ABSPATH' ) || exit; |
| 8 | |
| 9 | class Rating extends ShopPressWidgets { |
| 10 | |
| 11 | public function get_name() { |
| 12 | return 'sp-item-rating'; |
| 13 | } |
| 14 | |
| 15 | public function get_title() { |
| 16 | return __( 'Product Rating', 'shop-press' ); |
| 17 | } |
| 18 | |
| 19 | public function get_icon() { |
| 20 | return 'sp-widget sp-eicon-product-rating'; |
| 21 | } |
| 22 | |
| 23 | public function get_categories() { |
| 24 | return array( 'sp_woo_loop' ); |
| 25 | } |
| 26 | |
| 27 | public function setup_styling_options() { |
| 28 | |
| 29 | $this->register_group_styler( |
| 30 | 'wrapper', |
| 31 | __( 'Wrapper', 'shop-press' ), |
| 32 | array( |
| 33 | 'wrapper' => array( |
| 34 | 'label' => esc_html__( 'Wrapper', 'shop-press' ), |
| 35 | 'type' => 'styler', |
| 36 | 'selector' => '.sp-loop-rating', |
| 37 | ), |
| 38 | ) |
| 39 | ); |
| 40 | |
| 41 | $this->register_group_styler( |
| 42 | 'modern_rating', |
| 43 | __( 'Rating', 'shop-press' ), |
| 44 | array( |
| 45 | 'modern_container' => array( |
| 46 | 'label' => esc_html__( 'Container', 'shop-press' ), |
| 47 | 'type' => 'styler', |
| 48 | 'selector' => '.sp-rating', |
| 49 | 'wrapper' => '{{WRAPPER}} .sp-loop-rating.sp-modern-rating', |
| 50 | ), |
| 51 | |
| 52 | 'star' => array( |
| 53 | 'label' => esc_html__( 'Star', 'shop-press' ), |
| 54 | 'type' => 'styler', |
| 55 | 'selector' => '.sp-rating-star', |
| 56 | 'wrapper' => '{{WRAPPER}} .sp-loop-rating.sp-modern-rating .sp-rating', |
| 57 | ), |
| 58 | ), |
| 59 | array( |
| 60 | 'rating_type' => 'modern' ?? array(), |
| 61 | ) |
| 62 | ); |
| 63 | |
| 64 | $this->register_group_styler( |
| 65 | 'classic_rating', |
| 66 | __( 'Rating', 'shop-press' ), |
| 67 | array( |
| 68 | 'classic_container' => array( |
| 69 | 'label' => esc_html__( 'Container', 'shop-press' ), |
| 70 | 'type' => 'styler', |
| 71 | 'selector' => '.star-rating', |
| 72 | 'wrapper' => '{{WRAPPER}} .sp-loop-rating.sp-classic-rating', |
| 73 | ), |
| 74 | |
| 75 | 'empty_stars' => array( |
| 76 | 'label' => esc_html__( 'Empty Stars', 'shop-press' ), |
| 77 | 'type' => 'styler', |
| 78 | 'selector' => '.star-rating::before', |
| 79 | 'wrapper' => '{{WRAPPER}} .sp-loop-rating.sp-classic-rating', |
| 80 | ), |
| 81 | |
| 82 | 'full_stars' => array( |
| 83 | 'label' => esc_html__( 'Stars', 'shop-press' ), |
| 84 | 'type' => 'styler', |
| 85 | 'selector' => 'span', |
| 86 | 'wrapper' => '{{WRAPPER}} .sp-loop-rating.sp-classic-rating .star-rating', |
| 87 | ), |
| 88 | ), |
| 89 | array( |
| 90 | 'rating_type' => 'classic' ?? array(), |
| 91 | ) |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | protected function register_controls() { |
| 96 | |
| 97 | $this->start_controls_section( |
| 98 | 'section_content', |
| 99 | array( |
| 100 | 'label' => __( 'General', 'shop-press' ), |
| 101 | ) |
| 102 | ); |
| 103 | |
| 104 | $this->add_control( |
| 105 | 'rating_type', |
| 106 | array( |
| 107 | 'label' => __( 'Type', 'shop-press' ), |
| 108 | 'type' => Controls_Manager::SELECT, |
| 109 | 'default' => 'modern', |
| 110 | 'options' => array( |
| 111 | 'modern' => __( 'Modern', 'shop-press' ), |
| 112 | 'classic' => __( 'Classic', 'shop-press' ), |
| 113 | ), |
| 114 | ) |
| 115 | ); |
| 116 | |
| 117 | $this->end_controls_section(); |
| 118 | |
| 119 | $this->setup_styling_options(); |
| 120 | |
| 121 | do_action( 'shoppress/elementor/widget/register_controls_init', $this ); |
| 122 | } |
| 123 | |
| 124 | protected function render() { |
| 125 | $settings = $this->get_settings_for_display(); |
| 126 | |
| 127 | do_action( 'shoppress/widget/before_render', $this->get_settings_for_display() ); |
| 128 | |
| 129 | $args = array( |
| 130 | 'rating_type' => $settings['rating_type'], |
| 131 | ); |
| 132 | |
| 133 | if ( $this->editor_preview() ) { |
| 134 | sp_load_builder_template( 'loop/loop-rating', $args ); |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | protected function content_template() { |
| 139 | ?> |
| 140 | |
| 141 | <# if ( 'modern' === settings.rating_type ) { #> |
| 142 | <div class="woocommerce-product-rating sp-loop-rating sp-modern-rating"> |
| 143 | <?php echo '<div class="sp-rating"><span class="sp-rating-star">S</span>4.5</div>'; ?> |
| 144 | </div> |
| 145 | <# } #> |
| 146 | |
| 147 | <# if ( 'classic' === settings.rating_type ) { #> |
| 148 | <div class="woocommerce-product-rating sp-loop-rating sp-classic-rating"> |
| 149 | <div class="star-rating" role="img" aria-label="Rated 4 out of 5"> |
| 150 | <span style="width:80%"></span> |
| 151 | </div> |
| 152 | </div> |
| 153 | <# } #> |
| 154 | |
| 155 | <?php |
| 156 | } |
| 157 | } |
| 158 |