assets
7 months ago
comparison-cookie.php
2 years ago
comparison-field-value.php
9 months 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
route.php
114 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Modules\Comparison; |
| 4 | |
| 5 | use ShopEngine\Base\Api; |
| 6 | use ShopEngine\Utils\Helper; |
| 7 | |
| 8 | class Route extends Api { |
| 9 | |
| 10 | public function config() { |
| 11 | |
| 12 | $this->prefix = 'comparison'; |
| 13 | $this->param = ""; |
| 14 | } |
| 15 | |
| 16 | |
| 17 | public function get_comparison_table() { |
| 18 | $data = $this->request->get_params(); |
| 19 | $product_id = !empty($data['pid']) ? $data['pid'] : ""; |
| 20 | |
| 21 | if( $product_id ) Comparison_Cookie::add_product_id($product_id); |
| 22 | $product_ids = Comparison_Cookie::get_product_ids($product_id); |
| 23 | |
| 24 | Comparison_Helper::get_html($product_ids); |
| 25 | exit(); |
| 26 | } |
| 27 | |
| 28 | public function post_remove() { |
| 29 | |
| 30 | $data = $this->request->get_params(); |
| 31 | $pid = $data['pid']; |
| 32 | |
| 33 | Comparison_Cookie::remove_product_id($pid); |
| 34 | |
| 35 | $product_ids = Comparison_Cookie::get_product_ids(); |
| 36 | if (($key = array_search($pid, $product_ids)) !== false) { |
| 37 | unset($product_ids[$key]); |
| 38 | } |
| 39 | $share_url = home_url( '?comparison=yes&product_ids=' . implode( ',', $product_ids ) ); |
| 40 | |
| 41 | wp_send_json([ |
| 42 | "status" => "Success", |
| 43 | "share_url" => $product_ids ? $share_url : home_url( '?comparison=yes' ), |
| 44 | ]); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | |
| 49 | public function get_comparison_bar_data() { |
| 50 | |
| 51 | $product_ids = Comparison_Cookie::get_product_ids(); |
| 52 | |
| 53 | $content = ''; |
| 54 | if ( empty( $product_ids ) ) { |
| 55 | $content .= '<h1 class="shopengine-no-comparison-product-for-bar">' . esc_html__( 'No product is added for comparison, please add some product to compare', |
| 56 | 'shopengine' ) . '</h1>'; |
| 57 | return $content; |
| 58 | } |
| 59 | |
| 60 | $title = esc_html__("Remove Product For Comparison", "shopengine"); |
| 61 | |
| 62 | $args = [ |
| 63 | 'post_type' => 'product', |
| 64 | 'post__in' => $product_ids |
| 65 | ]; |
| 66 | |
| 67 | $productQuery = new \WP_Query($args); |
| 68 | |
| 69 | if ($productQuery->have_posts()) { |
| 70 | while ($productQuery->have_posts()) { |
| 71 | $productQuery->the_post(); |
| 72 | $product = wc_get_product(get_the_ID()); |
| 73 | $content .= '<div class="comparison-for-bottom-bar-item"> |
| 74 | <a title="' . $title . '" class="shopengine-comparison-bar-action badge-comparison" data-pid="'.esc_attr( get_the_ID() ).'"><i class="eicon-close"></i></a> |
| 75 | '.$product->get_image('woocommerce_thumbnail').'</div>'; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | return $content; |
| 80 | } |
| 81 | |
| 82 | |
| 83 | |
| 84 | public function get_attributes() { |
| 85 | global $wpdb; |
| 86 | |
| 87 | $attributes = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}woocommerce_attribute_taxonomies"); |
| 88 | |
| 89 | $formatted_attributes = []; |
| 90 | foreach ($attributes as $attribute){ |
| 91 | $formatted_attributes[$attribute->attribute_name] = $attribute->attribute_label; |
| 92 | } |
| 93 | |
| 94 | wp_send_json([ |
| 95 | "status" => "success", |
| 96 | "result" => $formatted_attributes, |
| 97 | "message" => "Available attributes" |
| 98 | ] ); |
| 99 | } |
| 100 | |
| 101 | |
| 102 | public function get_custom_meta() { |
| 103 | |
| 104 | wp_send_json([ |
| 105 | "status" => "success", |
| 106 | "result" => Comparison_Helper::get_products_meta_keys(), |
| 107 | "message" => "Products Meta keys" |
| 108 | ] ); |
| 109 | } |
| 110 | |
| 111 | |
| 112 | |
| 113 | } |
| 114 |