PluginProbe
YayMail – WooCommerce Email Customizer / trunk
YayMail – WooCommerce Email Customizer vtrunk
4.4.4 4.4.3 4.4.2 4.4.1 trunk 1.9.6 2.1.4 2.1.5 3.2.2 3.2.6 3.2.7.1 3.2.8.1 3.2.9 3.3 3.3.1 3.3.4 3.3.5 3.3.6 3.3.7 3.3.8 3.3.9 3.4 3.4.1 3.4.2 3.4.3 All 55 releases
yaymail / src / Controllers / ProductController.php

ProductController.php in YayMail – WooCommerce Email Customizer trunk, at src/Controllers/ProductController.php

167 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace YayMail\Controllers;
4
5 use YayMail\Abstracts\BaseController;
6 use YayMail\Models\ProductModel;
7 use YayMail\Utils\SingletonTrait;
8
9 /**
10 * Product Controller
11 *
12 * @method static ProductController get_instance()
13 */
14 class ProductController extends BaseController {
15 use SingletonTrait;
16
17 private $model = null;
18
19 protected function __construct() {
20 $this->model = ProductModel::get_instance();
21 $this->init_hooks();
22 }
23
24 protected function init_hooks() {
25 register_rest_route(
26 YAYMAIL_REST_NAMESPACE,
27 '/product/categories',
28 [
29 [
30 'methods' => \WP_REST_Server::READABLE,
31 'callback' => [ $this, 'exec_get_categories' ],
32 'permission_callback' => [ $this, 'permission_callback' ],
33 ],
34 ]
35 );
36
37 register_rest_route(
38 YAYMAIL_REST_NAMESPACE,
39 '/product/tags',
40 [
41 [
42 'methods' => \WP_REST_Server::READABLE,
43 'callback' => [ $this, 'exec_get_tags' ],
44 'permission_callback' => [ $this, 'permission_callback' ],
45 ],
46 ]
47 );
48 register_rest_route(
49 YAYMAIL_REST_NAMESPACE,
50 '/product',
51 [
52 [
53 'methods' => \WP_REST_Server::READABLE,
54 'callback' => [ $this, 'exec_get_products' ],
55 'permission_callback' => [ $this, 'permission_callback' ],
56 ],
57 ]
58 );
59 }
60
61
62 /**
63 * Handle get cross up sells products
64 *
65 * @param \WP_REST_Request $request The request object.
66 * @return array The response data.
67 */
68 public function exec_get_cross_up_sells( \WP_REST_Request $request ) {
69 return $this->exec( [ $this, 'get_cross_up_sells' ], $request );
70 }
71
72 /**
73 * Get cross up sells products
74 *
75 * @param \WP_REST_Request $request The request object.
76 * @return array The cross up sells products data.
77 */
78 public function get_cross_up_sells( \WP_REST_Request $request ) {
79 $params['max_products_displayed'] = sanitize_text_field( $request->get_param( 'max_products_displayed' ) );
80 $params['linked_products_type'] = sanitize_text_field( $request->get_param( 'linked_products_type' ) );
81 $params['order_id'] = sanitize_text_field( $request->get_param( 'order_id' ) );
82
83 $result = $this->model->get_cross_up_sells_products( $params );
84
85 return $result;
86 }
87
88 /**
89 * Handle get product categories
90 *
91 * @param \WP_REST_Request $request The request object.
92 * @return array The response data.
93 */
94 public function exec_get_categories( \WP_REST_Request $request ) {
95 return $this->exec( [ $this, 'get_categories' ], $request );
96 }
97
98 /**
99 * Get product categories
100 *
101 * @param \WP_REST_Request $request The request object.
102 * @return array The product categories data.
103 */
104 public function get_categories( \WP_REST_Request $request ) {
105 $params['search_string'] = sanitize_text_field( $request->get_param( 'search_string' ) );
106 $params['page_num'] = sanitize_text_field( $request->get_param( 'page_num' ) );
107 $params['page_size'] = sanitize_text_field( $request->get_param( 'page_size' ) );
108 $params['term_type'] = 'product_cat';
109
110 $result = $this->model->get_terms( $params, [ 'id' => 'term_id' ] );
111
112 return $result;
113 }
114
115
116 /**
117 * Handle get product tags
118 *
119 * @param \WP_REST_Request $request The request object.
120 * @return array The response data.
121 */
122 public function exec_get_tags( \WP_REST_Request $request ) {
123 return $this->exec( [ $this, 'get_tags' ], $request );
124 }
125
126 /**
127 * Get product tags
128 *
129 * @param \WP_REST_Request $request The request object.
130 * @return array The product tags data.
131 */
132 public function get_tags( \WP_REST_Request $request ) {
133 $params['search_string'] = sanitize_text_field( $request->get_param( 'search_string' ) );
134 $params['page_num'] = sanitize_text_field( $request->get_param( 'page_num' ) );
135 $params['page_size'] = sanitize_text_field( $request->get_param( 'page_size' ) );
136 $params['term_type'] = 'product_tag';
137 $result = $this->model->get_terms( $params, [ 'id' => 'term_id' ] );
138
139 return $result;
140 }
141
142 /**
143 * Handle get products
144 *
145 * @param \WP_REST_Request $request The request object.
146 * @return array The response data.
147 */
148 public function exec_get_products( \WP_REST_Request $request ) {
149 return $this->exec( [ $this, 'get_products' ], $request );
150 }
151
152 /**
153 * Get products
154 *
155 * @param \WP_REST_Request $request The request object.
156 * @return array The products data.
157 */
158 public function get_products( \WP_REST_Request $request ) {
159 $params['search_string'] = sanitize_text_field( $request->get_param( 'search_string' ) );
160 $params['page_num'] = sanitize_text_field( $request->get_param( 'page_num' ) );
161 $params['page_size'] = sanitize_text_field( $request->get_param( 'page_size' ) );
162 $result = $this->model->get_terms( $params );
163
164 return $result;
165 }
166 }
167