route.php
95 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ShopEngine\Widgets\Init; |
| 4 | |
| 5 | use ShopEngine\Base\Api; |
| 6 | defined('ABSPATH') || exit; |
| 7 | class Route extends Api |
| 8 | { |
| 9 | |
| 10 | public function config() { |
| 11 | |
| 12 | $this->prefix = 'widgets_partials'; |
| 13 | $this->param = ""; |
| 14 | } |
| 15 | |
| 16 | public function get_filter_cat_products() { |
| 17 | |
| 18 | $data = $this->request->get_params(); |
| 19 | |
| 20 | $products = $data['products']; |
| 21 | $order = isset($data['order']) ? $data['order'] : 'DESC'; |
| 22 | $order_by = isset($data['order_by']) ? $data['order_by'] : 'date'; |
| 23 | $settings = isset($data['settings']) ? $data['settings'] : null; |
| 24 | |
| 25 | if(empty($products)) { |
| 26 | |
| 27 | echo "<p class='error'>" . esc_html__('No products were found.', 'shopengine') . "</p>"; |
| 28 | |
| 29 | exit(); |
| 30 | } |
| 31 | |
| 32 | $args = array( |
| 33 | 'post_type' => 'product', |
| 34 | 'order' => $order, |
| 35 | 'orderby' => $order_by, |
| 36 | 'post__in' => $products, |
| 37 | 'posts_per_page' => 50 |
| 38 | ); |
| 39 | |
| 40 | |
| 41 | $query = new \WP_Query($args); |
| 42 | |
| 43 | if($query->have_posts()) : |
| 44 | while($query->have_posts()) : $query->the_post(); |
| 45 | |
| 46 | $default_content = [ |
| 47 | 'image' => 0, |
| 48 | 'category' => 0, |
| 49 | 'title' => 0, |
| 50 | 'rating' => 0, |
| 51 | 'price' => 0, |
| 52 | 'description' => 0, |
| 53 | 'buttons' => 0, |
| 54 | ]; |
| 55 | |
| 56 | |
| 57 | |
| 58 | $content = (!empty($view) ? $view : $default_content); |
| 59 | asort($content, SORT_NUMERIC); |
| 60 | |
| 61 | if( $settings['shopengine_is_cats'] != 'yes' ) unset($content['category']); |
| 62 | if( $settings['shopengine_is_details'] != 'yes' ) { |
| 63 | unset($content['description']); |
| 64 | } |
| 65 | if( $settings['shopengine_is_product_rating'] != 'yes' ) unset($content['rating']); |
| 66 | |
| 67 | |
| 68 | ?> <div class='shopengine-single-product-item'> <?php |
| 69 | foreach($content as $key => $value) { |
| 70 | $function = '_product_' . $key; |
| 71 | \ShopEngine\Utils\Helper::$function($settings); |
| 72 | } |
| 73 | ?> </div> <?php |
| 74 | |
| 75 | endwhile; |
| 76 | endif; |
| 77 | |
| 78 | wp_reset_postdata(); |
| 79 | |
| 80 | exit(); |
| 81 | } |
| 82 | |
| 83 | public function post_checkout_login() { |
| 84 | $data = $this->request->get_params(); |
| 85 | if(isset($data['rememberme'])) { |
| 86 | $data['rememberme'] = $data['rememberme'] == 'true' ? true : false; |
| 87 | } |
| 88 | $user = wp_signon($data); |
| 89 | if(is_wp_error($user)) { |
| 90 | return new \WP_Error('failed_login', $user->get_error_message(), ['status' => 404]); |
| 91 | } |
| 92 | return true; |
| 93 | } |
| 94 | } |
| 95 |