PluginProbe ʕ •ᴥ•ʔ
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution / 0.1.4-beta
ShopEngine Elementor WooCommerce Builder Addon – All in One WooCommerce Solution v0.1.4-beta
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 / route.php
shopengine / modules / comparison Last commit date
assets 5 years ago comparison.php 5 years ago route.php 5 years ago
route.php
247 lines
1 <?php
2
3 namespace ShopEngine\Modules\Comparison;
4
5 use ShopEngine\Base\Api;
6
7 class Route extends Api
8 {
9
10 public function config() {
11
12 $this->prefix = 'comparison';
13 $this->param = "";
14 }
15
16
17 private function prepare_html($content = []) {
18
19 $attr = [];
20 $ids = [];
21
22 foreach($content as $pid) {
23
24 if(empty($pid)) {
25 continue;
26 }
27
28 $prod = wc_get_product($pid);
29 $ids[] = $pid;
30
31 $attr['name'][$pid] = $prod->get_name();
32 $attr['image'][$pid] = $prod->get_image();
33
34
35 $attr['stock'][$pid] = $prod->get_stock_status();
36 $attr['sku'][$pid] = $prod->get_sku();
37 //$attr['type'][$pid] = $prod->get_type();
38
39 $attr['price'][$pid]['regular'] = $prod->get_regular_price();
40 $attr['price'][$pid]['sale'] = $prod->get_sale_price();
41 $attr['price'][$pid]['price'] = $prod->get_price();
42 $attr['price'][$pid]['htm'] = $prod->get_price_html();
43
44
45 if($prod->get_rating_counts()) {
46
47 $attr['rating_count'][$pid] = $prod->get_rating_counts();
48 }
49
50 if($prod->get_average_rating()) {
51
52 $attr['rating'][$pid] = $prod->get_average_rating();
53 }
54
55 if($prod->get_review_count()) {
56
57 $attr['review_count'][$pid] = $prod->get_review_count();
58 }
59
60 if($prod->has_weight()) {
61
62 $attr['weight'][$pid] = $prod->get_weight();
63 }
64
65 if($prod->has_attributes()) {
66
67 $ats = $prod->get_attributes();
68
69 foreach($ats as $at) {
70
71 $attr['attr'][$pid][$at->get_id()]['name'] = wc_attribute_label($at->get_name());
72
73 if($at->is_taxonomy()) {
74
75 $terms = get_terms($at->get_name());
76 foreach($terms as $term) {
77 $attr['attr'][$pid][$at->get_id()]['val'][$term->term_id] = $term->name;
78 }
79
80 } else {
81
82 $terms = $at->get_options();
83
84 foreach($terms as $idx => $term) {
85 $attr['attr'][$pid][$at->get_id()]['val'][$idx] = $term;
86 }
87 }
88 }
89 }
90
91 if($prod->has_dimensions()) {
92
93 $attr['dim'][$pid]['len'] = $prod->get_length();
94 $attr['dim'][$pid]['wd'] = $prod->get_width();
95 $attr['dim'][$pid]['ht'] = $prod->get_height();
96
97 }
98 }
99
100 ?>
101
102 <div>
103 <div class="shopengine-comparison-container">
104 <div class="shopengine-comparison">
105 <h2><?php echo __('Product comparison', 'shopengine') ?></h2>
106
107 <table class="table table-bordered">
108
109 <thead>
110 <tr>
111 <th> # </th>
112
113 <?php
114
115 foreach($ids as $id) {
116
117 echo '<th><a class="shopengine-remove-action badge-comparison" data-pid="'.$id.'">'.__('X', 'shopengine').'</a></th>';
118 }
119
120 ?>
121 </tr>
122 </thead>
123
124 <tbody> <?php
125
126 foreach($attr as $key => $info) { ?>
127
128 <tr> <?php
129
130 if(
131 $key === 'name' ||
132 $key === 'image' ||
133 $key === 'rating' ||
134 $key === 'stock' ||
135 $key === 'weight' ||
136 $key === 'sku'
137 ) {
138
139 echo '<td>' . ucfirst($key) . ' :</td>';
140
141 foreach($ids as $id) {
142
143 echo '<td> ' . $info[$id] . ' </td>';
144 }
145
146 } elseif($key === 'price') {
147
148 echo '<td>' . ucfirst($key) . ' :</td>';
149
150 foreach($ids as $id) {
151
152 echo '<td>' . $info[$id]['htm'] . '</td>';
153 }
154
155 } elseif($key === 'dim') {
156
157 echo '<td> '.__('Dimensions', 'shopengine').' :</td>';
158
159 foreach($ids as $id) {
160
161 if(!isset($info[$id])) {
162
163 echo '<td> </td>';
164
165 continue;
166 }
167
168 echo '<td>' . implode(' * ', $info[$id]) . '</td>';
169 }
170
171 } elseif($key === 'attr') {
172
173 echo '<td>' . __('Available options', 'shopengine') . ' :</td>';
174
175 foreach($ids as $id) {
176
177 if(!isset($info[$id])) {
178
179 echo '<td> </td>';
180
181 continue;
182 }
183
184 echo '<td>';
185
186 foreach($info[$id] as $item) {
187
188 echo $item['name'] . ' : ' . implode(', ', $item['val']);
189
190 echo '<br/>';
191 }
192 echo '</td>';
193 }
194 } ?>
195
196 </tr> <?php
197 } ?>
198
199 </tbody>
200 </table>
201 </div>
202 </div>
203 </div>
204 <?php
205
206 }
207
208 public function get_comparison_table() {
209
210 $data = $this->request->get_params();
211 $idd = $data['pid'];
212
213 $cck = empty($_COOKIE[Comparison::COOKIE_KEY]) ? '' : $_COOKIE[Comparison::COOKIE_KEY];
214 $cck = explode(',', $cck);
215 $content = array_combine($cck, $cck);
216 $content[$idd] = $idd;
217
218 $val = implode(',', $content);
219
220 setcookie(Comparison::COOKIE_KEY, $val, strtotime('+'.Comparison::COOKIE_TIME_IN_DAYS.' days'), '/');
221
222 $this->prepare_html($content);
223
224 exit();
225 }
226
227 public function post_remove() {
228
229 $data = $this->request->get_params();
230 $idd = $data['pid'];
231
232 $cck = empty($_COOKIE[Comparison::COOKIE_KEY]) ? '' : $_COOKIE[Comparison::COOKIE_KEY];
233 $cck = explode(',', $cck);
234 $content = array_combine($cck, $cck);
235
236 unset($content[$idd], $content['']);
237
238 $val = implode(',', $content);
239
240 setcookie(Comparison::COOKIE_KEY, $val, strtotime('+'.Comparison::COOKIE_TIME_IN_DAYS.' days'), '/');
241
242 $this->prepare_html($content);
243
244 exit();
245 }
246 }
247