PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets / 3.0.0
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution with eCommerce Templates & Woo Widgets v3.0.0
4.9.5 4.9.4 4.9.3 4.9.2 4.9.1 4.9.0 2.0.0 2.1.0 2.2.0 2.2.1 2.2.2 2.3.0 2.4.0 2.5.0 2.5.1 3.0.0 3.1.0 3.1.1 4.0.0 4.0.1 4.1.0 4.1.1 4.2.0 4.2.1 4.3.0 4.3.1 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.6.8 4.6.9 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.8.1 4.8.2 4.8.3 4.8.4 4.8.5 4.8.6 4.8.7 4.8.8 4.8.9 trunk 0.1.2-beta 0.1.3-beta 0.1.4-beta 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.5.0 1.5.1 1.6.0 1.6.1 1.7.0 1.8.0 1.8.1 1.9.0
shopengine / modules / comparison / comparison-helper.php
shopengine / modules / comparison Last commit date
assets 3 years ago comparison-cookie.php 3 years ago comparison-field-value.php 3 years ago comparison-helper.php 3 years ago comparison-share.php 3 years ago comparison.php 3 years ago group-meta.php 3 years ago route.php 3 years ago
comparison-helper.php
176 lines
1 <?php
2
3
4 namespace ShopEngine\Modules\Comparison;
5
6
7 use ShopEngine\Core\Register\Module_List;
8 use ShopEngine\Utils\Helper;
9
10 class Comparison_Helper {
11
12 public static function get_html($content = [], $comparison_page = false) {
13
14 if(empty($content)) {
15 return '<h1 class="shopengine-no-comparison-product">'.esc_html__('No product is added for comparison, please add some product to compare', 'shopengine').'</h1>';
16 }
17
18 $settings = Module_List::instance()->get_active_settings( 'comparison' );
19 $attributes_fields = $settings['attribute_fields']['value'] ?? [] ;
20
21 $default_fields = [ 'url', 'image', 'price' ];
22 if( class_exists('ShopEngine_Pro') ) {
23 $default_fields['attributes'] = $attributes_fields;
24 }
25
26 $fields = array_merge($default_fields, $settings['shop_field_in_table']['value'] ?? []);
27
28 $fields['attributes'] = $attributes_fields;
29
30 $share_buttons = $settings['share_button']['value'] ?? [];
31
32 $field_value_manager = new Comparison_Field_Value();
33 $field_value_manager->product_ids = $content;
34
35 $displayable_fields = [];
36
37 foreach ( $content as $pid ) {
38 if ( empty( $pid ) ) {
39 continue;
40 }
41
42 $product = wc_get_product( $pid );
43 if(!$product || $product->get_status() !== 'publish' ) {
44 continue;
45 }
46
47
48 if ( empty( $product ) ) {
49 continue;
50 }
51
52 foreach ( $fields as $key => $field ) {
53
54 if(gettype($field) != 'string'){
55 $slug = $key;
56 }else{
57 $slug = $field ;
58 }
59
60 $displayable_fields[ $slug ][ $pid ] = $field_value_manager->get_value( $product,
61 $slug, $field );
62 }
63 }
64
65 $format_attributes = [];
66 if(isset($displayable_fields['attributes'])){
67 foreach ($displayable_fields['attributes'] as $product_id => $attribute_data){
68
69 foreach ($attribute_data[$product_id] as $key => $attributes){
70 $format_attributes[$key][$product_id] = $attributes;
71 }
72 }
73 }
74
75
76 $displayable_fields['attributes'] = $format_attributes;
77
78 // group first tr values
79 $first_tr = [];
80 $first_tr['first_tr']['url'] = $displayable_fields['url'] ?? [];
81 $first_tr['first_tr']['image'] = $displayable_fields['image'] ?? [];
82 $first_tr['first_tr']['title'] = $displayable_fields['title'] ?? [];
83 $first_tr['first_tr']['price'] = $displayable_fields['price'] ?? [];
84
85 $displayable_fields = $first_tr + $displayable_fields ;
86 if( class_exists('ShopEngine_Pro') ) {
87 $displayable_fields['custom_meta'] = $settings['custom_meta_fields']['value'] ?? [];
88 }
89
90 unset($displayable_fields['url'], $displayable_fields['image'], $displayable_fields['title'], $displayable_fields['price']);
91
92 ?>
93 <div class="shopengine-modal-wrap">
94 <div class="shopengine-comparison-container">
95 <div class="shopengine-comparison">
96 <h2><?php echo esc_html__('Product comparison', 'shopengine') ?> </h2>
97
98 <?php if( class_exists('ShopEngine_Pro') && $share_buttons ) : ?>
99 <div class="social-share">
100 <?php
101 $share_url = home_url( '?comparison=yes&product_ids=' . implode( ',', $content ) );
102 $share = esc_html__("Share On Facebook","shopengine");
103 $twitter = esc_html__("Share On Twitter","shopengine");
104 $copy = esc_html__("Copy To Clipboard","shopengine");
105
106 foreach ( $share_buttons as $share_button ) {
107 switch ( $share_button ) {
108 case 'facebook':
109 echo sprintf(
110 '<a title="' . $share . '" href="%1$s" target="_blank" rel="noopener noreferrer nofollow "><i class="eicon-facebook"></i> <span>%2$s</span></a>',
111 'https://www.facebook.com/sharer.php?u=' . $share_url,
112 esc_html__('Share on Facebook', 'shopengine')
113 );
114 break;
115 case 'twitter':
116 echo sprintf(
117 '<a title="' . $twitter . '" href="%1$s" target="_blank" rel="noopener noreferrer nofollow "><i class="eicon-twitter"></i> <span>%2$s</span></a>',
118 'https://twitter.com/intent/tweet?url=' . $share_url,
119 esc_html__('Share on Twitter', 'shopengine')
120 );
121 break;
122 case 'copy_url':
123 echo sprintf(
124
125 '<button title="' . $copy . '" class="copy-comparison-share-url" data-share-url="%1$s" data-message="%2$s"> <i class="eicon-copy"></i> <span>%3$s</span> </button>',
126 $share_url,
127 esc_html__('Copied', 'shopengine'),
128 esc_html__('Copy', 'shopengine')
129 );
130 break;
131 }
132 }
133 ?>
134 </div>
135 <?php endif;?>
136
137 <div class="comparison-table-wrap">
138 <table class="table table-bordered <?php echo $comparison_page ? 'comparison-page' : '' ?>">
139 <tbody> <?php
140
141 foreach ($displayable_fields as $slug => $data){
142 $field_value_manager->get_html($slug, $data);
143 }
144 ?>
145 </tbody>
146 </table>
147 </div>
148 </div>
149 </div>
150 </div>
151 <?php
152 }
153
154 public static function generate_meta_keys_array( $keys ) {
155 /*$cache = get_transient( 'shopengine-all-products_meta_keys_array' );
156 if($cache){
157 return $cache;
158 }*/
159
160 $keys_array = [];
161 foreach ( $keys as $key ) {
162 $title = ucwords( preg_replace( '~([^a-z0-9\-])~i', ' ', $key ) );
163 $keys_array[ $key ] = $title;
164 }
165
166 // set_transient( 'shopengine-all-products_meta_keys_array', $keys_array, 60 * 60 * 0.01 );
167
168 return $keys_array;
169 }
170
171 public static function get_products_meta_keys() {
172 return static::generate_meta_keys_array(Helper::get_products_meta_keys());
173 }
174
175
176 }