config.php
200 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopPress\Elementor\Widgets\LoopBuilder; |
| 4 | |
| 5 | use Elementor\Controls_Manager; |
| 6 | use ShopPress\Elementor\ShopPressWidgets; |
| 7 | |
| 8 | defined( 'ABSPATH' ) || exit; |
| 9 | |
| 10 | class Attributes extends ShopPressWidgets { |
| 11 | |
| 12 | public function get_name() { |
| 13 | return 'sp-item-attributes'; |
| 14 | } |
| 15 | |
| 16 | public function get_title() { |
| 17 | return __( 'Product Attributes', 'shop-press' ); |
| 18 | } |
| 19 | |
| 20 | public function get_icon() { |
| 21 | return 'sp-widget sp-eicon-product-loop-attributes'; |
| 22 | } |
| 23 | |
| 24 | public function get_categories() { |
| 25 | return array( 'sp_woo_loop' ); |
| 26 | } |
| 27 | |
| 28 | public function get_script_depends() { |
| 29 | return array( 'sp-variation-swatches' ); |
| 30 | } |
| 31 | |
| 32 | public function get_style_depends() { |
| 33 | if ( is_rtl() ) { |
| 34 | return array( 'sp-variation-swatches', 'sp-variation-swatches-rtl' ); |
| 35 | } else { |
| 36 | return array( 'sp-variation-swatches' ); |
| 37 | } |
| 38 | } |
| 39 | |
| 40 | protected function register_controls() { |
| 41 | |
| 42 | $attribute_taxonomies = wc_get_attribute_taxonomies(); |
| 43 | $attribute_taxonomy_options = array(); |
| 44 | foreach ( $attribute_taxonomies as $attribute_taxonomy ) { |
| 45 | |
| 46 | if ( 'select' === $attribute_taxonomy->attribute_type ) { |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | $attribute_taxonomy_options[ $attribute_taxonomy->attribute_id ] = $attribute_taxonomy->attribute_label; |
| 51 | $attribute_taxonomy_group_by_type[ $attribute_taxonomy->attribute_type ][] = $attribute_taxonomy->attribute_id; |
| 52 | } |
| 53 | |
| 54 | $this->start_controls_section( |
| 55 | 'section_content', |
| 56 | array( |
| 57 | 'label' => __( 'General', 'shop-press' ), |
| 58 | ) |
| 59 | ); |
| 60 | |
| 61 | $this->add_control( |
| 62 | 'attribute_taxonomy', |
| 63 | array( |
| 64 | 'label' => __( 'Attribute', 'shop-press' ), |
| 65 | 'type' => Controls_Manager::SELECT, |
| 66 | 'default' => key( $attribute_taxonomy_options ), |
| 67 | 'options' => $attribute_taxonomy_options, |
| 68 | 'description' => __( 'Please note that you must specify the type of the attributes for them to be available in the option above.', 'shop-press' ), |
| 69 | ) |
| 70 | ); |
| 71 | |
| 72 | $this->end_controls_section(); |
| 73 | |
| 74 | $this->register_group_styler( |
| 75 | 'wrapper', |
| 76 | __( 'Wrapper', 'shop-press' ), |
| 77 | array( |
| 78 | 'wrapper' => array( |
| 79 | 'label' => esc_html__( 'Wrapper', 'shop-press' ), |
| 80 | 'type' => 'styler', |
| 81 | 'selector' => '.sp-product-attributes', |
| 82 | 'wrapper' => '{{WRAPPER}}', |
| 83 | ), |
| 84 | 'items_wrapper' => array( |
| 85 | 'label' => esc_html__( 'Items Wrapper', 'shop-press' ), |
| 86 | 'type' => 'styler', |
| 87 | 'selector' => '.sp-wrapper-ul', |
| 88 | 'wrapper' => '{{WRAPPER}} .sp-product-attributes', |
| 89 | ), |
| 90 | 'item_wrapper' => array( |
| 91 | 'label' => esc_html__( 'Item Wrapper', 'shop-press' ), |
| 92 | 'type' => 'styler', |
| 93 | 'selector' => '.sp-wrapper-item-li', |
| 94 | 'wrapper' => '{{WRAPPER}} .sp-product-attributes .sp-wrapper-ul', |
| 95 | ), |
| 96 | ) |
| 97 | ); |
| 98 | |
| 99 | $this->register_group_styler( |
| 100 | 'attribute_colors', |
| 101 | __( 'Item', 'shop-press' ), |
| 102 | array( |
| 103 | 'color_item' => array( |
| 104 | 'label' => esc_html__( 'Color Item', 'shop-press' ), |
| 105 | 'type' => 'styler', |
| 106 | 'selector' => '.sp-item-span-color', |
| 107 | 'wrapper' => '{{WRAPPER}} .sp-product-attributes .sp-wrapper-ul .sp-wrapper-item-li', |
| 108 | ), |
| 109 | ), |
| 110 | array( |
| 111 | 'attribute_taxonomy' => $attribute_taxonomy_group_by_type['color'] ?? array(), |
| 112 | ) |
| 113 | ); |
| 114 | |
| 115 | $this->register_group_styler( |
| 116 | 'attribute_labels', |
| 117 | __( 'Item', 'shop-press' ), |
| 118 | array( |
| 119 | 'label_item' => array( |
| 120 | 'label' => esc_html__( 'Label Item', 'shop-press' ), |
| 121 | 'type' => 'styler', |
| 122 | 'selector' => '.sp-item-span.item-span-text', |
| 123 | 'wrapper' => '{{WRAPPER}} .sp-product-attributes .sp-wrapper-ul .sp-wrapper-item-li', |
| 124 | ), |
| 125 | ), |
| 126 | array( |
| 127 | 'attribute_taxonomy' => $attribute_taxonomy_group_by_type['label'] ?? array(), |
| 128 | ) |
| 129 | ); |
| 130 | |
| 131 | $this->register_group_styler( |
| 132 | 'attribute_images', |
| 133 | __( 'Item', 'shop-press' ), |
| 134 | array( |
| 135 | 'image_item' => array( |
| 136 | 'label' => esc_html__( 'Image Item', 'shop-press' ), |
| 137 | 'type' => 'styler', |
| 138 | 'selector' => '.swatch-preview.swatch-image', |
| 139 | 'wrapper' => '{{WRAPPER}} .sp-product-attributes .sp-wrapper-ul .sp-wrapper-item-li', |
| 140 | ), |
| 141 | ), |
| 142 | array( |
| 143 | 'attribute_taxonomy' => $attribute_taxonomy_group_by_type['image'] ?? array(), |
| 144 | ) |
| 145 | ); |
| 146 | |
| 147 | do_action( 'shoppress/elementor/widget/register_controls_init', $this ); |
| 148 | } |
| 149 | |
| 150 | protected function render() { |
| 151 | $settings = $this->get_settings_for_display(); |
| 152 | |
| 153 | do_action( 'shoppress/widget/before_render', $settings ); |
| 154 | |
| 155 | $args = array( |
| 156 | 'attribute_taxonomy' => $settings['attribute_taxonomy'], |
| 157 | ); |
| 158 | |
| 159 | if ( $this->editor_preview() ) { |
| 160 | sp_load_builder_template( 'loop/loop-attributes', $args ); |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | protected function content_template() { |
| 165 | |
| 166 | $attribute_taxonomies = wc_get_attribute_taxonomies(); |
| 167 | $attribute_taxonomy_group_by_type = array(); |
| 168 | foreach ( $attribute_taxonomies as $attribute_taxonomy ) { |
| 169 | |
| 170 | if ( 'select' === $attribute_taxonomy->attribute_type ) { |
| 171 | continue; |
| 172 | } |
| 173 | |
| 174 | $attribute_taxonomy_group_by_type[ $attribute_taxonomy->attribute_id ] = $attribute_taxonomy->attribute_type; |
| 175 | } |
| 176 | ?> |
| 177 | <# |
| 178 | var attribute_type = settings.attribute_taxonomy; |
| 179 | var attribute_taxonomy_group_by_type = <?php echo json_encode( $attribute_taxonomy_group_by_type ); ?>; |
| 180 | #> |
| 181 | <div class="sp-product-attributes"> |
| 182 | <ul class="sp-wrapper-ul"> |
| 183 | <# if( 'color' === attribute_taxonomy_group_by_type[attribute_type] ){ #> |
| 184 | <li class="sp-wrapper-item-li sp-color-li sp-div sp-checkbox attribute_attribute_4-221 blue attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_4-221" data-value="blue" title="blue"><span class="sp-item-span sp-item-span-color" style="background-color:#1e73be;"> </span></li> |
| 185 | <li class="sp-wrapper-item-li sp-color-li sp-div sp-checkbox attribute_attribute_4-221 green attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_4-221" data-value="green" title="green"><span class="sp-item-span sp-item-span-color" style="background-color:#81d742;"> </span></li> |
| 186 | <li class="sp-wrapper-item-li sp-color-li sp-div sp-checkbox attribute_attribute_4-221 red attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_4-221" data-value="red" title="red"><span class="sp-item-span sp-item-span-color" style="background-color:#dd3333;"> </span></li> |
| 187 | <# } else if( 'image' === attribute_taxonomy_group_by_type[attribute_type] ){ #> |
| 188 | <li class="sp-wrapper-item-li sp-image-li sp-div sp-checkbox attribute_attribute_6-221 image-1 attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_6-221" data-value="image-1" title="image 1"><img class="swatch-preview swatch-image " src="<?php echo esc_url( SHOPPRESS_URL . '/Elementor/widgets/loop/thumbnail/image/' ); ?>t-shirt-with-logo.jpg" width="44px" height="44px" alt="image 1"></li> |
| 189 | <li class="sp-wrapper-item-li sp-image-li sp-div sp-checkbox attribute_attribute_6-221 image-2 attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_6-221" data-value="image-2" title="image 2"><img class="swatch-preview swatch-image " src="<?php echo esc_url( SHOPPRESS_URL . '/Elementor/widgets/loop/thumbnail/image/' ); ?>t-shirt-with-logo.jpg" width="44px" height="44px" alt="image 2"></li> |
| 190 | <li class="sp-wrapper-item-li sp-image-li sp-div sp-checkbox attribute_attribute_6-221 image-3 attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_6-221" data-value="image-3" title="image 3"><img class="swatch-preview swatch-image " src="<?php echo esc_url( SHOPPRESS_URL . '/Elementor/widgets/loop/thumbnail/image/' ); ?>t-shirt-with-logo.jpg" width="44px" height="44px" alt="image 3"></li> |
| 191 | <# } else if( 'label' === attribute_taxonomy_group_by_type[attribute_type] ){ #> |
| 192 | <li class="sp-wrapper-item-li sp-label-li sp-div sp-checkbox attribute_attribute_8-221 label-1 attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_8-221" data-value="label-1" title="label 1"><span class=" sp-item-span item-span-text ">label 1</span></li> |
| 193 | <li class="sp-wrapper-item-li sp-label-li sp-div sp-checkbox attribute_attribute_8-221 label-2 attr_swatch_design_default sp-tooltip" data-attribute_name="attribute_attribute_8-221" data-value="label-2" title="label 2"><span class=" sp-item-span item-span-text ">label 2</span></li> |
| 194 | <# } #> |
| 195 | </ul> |
| 196 | </div> |
| 197 | <?php |
| 198 | } |
| 199 | } |
| 200 |