PluginProbe
AliNext – WooCommerce Dropshipping Plugin for AliExpress / trunk
AliNext – WooCommerce Dropshipping Plugin for AliExpress vtrunk
ali2woo-lite / includes / classes / controller / SearchStoreProductsPageController.php

SearchStoreProductsPageController.php in AliNext – WooCommerce Dropshipping Plugin for AliExpress trunk, at includes/classes/controller/SearchStoreProductsPageController.php

171 lines 6.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Description of SearchStoreProductsPageController
5 *
6 * @author Ali2Woo Team
7 *
8 * @autoload: a2wl_admin_init
9 */
10 namespace AliNext_Lite;;
11
12 use Pages;
13
14 class SearchStoreProductsPageController extends AbstractAdminPage
15 {
16
17 public function __construct(
18 protected Aliexpress $AliexpressModel,
19 protected Country $CountryModel,
20 protected PermanentAlertService $PermanentAlertService,
21 protected TipOfDayService $TipOfDayService,
22
23 protected PromoService $PromoService,
24
25 ) {
26 parent::__construct(
27 Pages::getLabel(Pages::STORE),
28 Pages::getLabel(Pages::STORE),
29 Capability::pluginAccess(),
30 Pages::STORE,
31 10
32 );
33
34 add_filter('a2wl_configure_lang_data', [$this, 'configure_lang_data']);
35 }
36
37 public function configure_lang_data($lang_data)
38 {
39 $lang_data['advance'] = _x('Advance', 'Button', 'ali2woo');
40 $lang_data['simple'] = _x('Simple', 'Button', 'ali2woo');
41 $lang_data['imported_successfully'] = _x('Imported successfully.', 'Status', 'ali2woo');
42 $lang_data['removed_successfully'] = _x('Removed successfully.', 'Status', 'ali2woo');
43 $lang_data['import_failed'] = _x('Import failed.', 'Status', 'ali2woo');
44
45 return $lang_data;
46 }
47
48 public function render($params = array()): void
49 {
50 if (!empty($_POST)) {
51 check_admin_referer(self::AJAX_NONCE_ACTION, self::NONCE);
52 }
53
54 if (!PageGuardHelper::canAccessPage(Pages::STORE)) {
55 wp_die($this->getErrorTextNoPermissions());
56 }
57
58 $filter = array();
59 if (!empty($_GET['a2wl_search'])) {
60 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
61
62 $filter = array_merge($filter, $_GET);
63 if (isset($filter['cur_page'])) {
64 unset($filter['cur_page']);
65 }
66 if (isset($filter['page'])) {
67 unset($filter['page']);
68 }
69 }
70
71 $adv_search_field = array('min_price', 'max_price', 'min_feedback', 'max_feedback', 'volume_from', 'volume_to');
72 $adv_search = false;
73 foreach ($filter as $key => $val) {
74 $new_key = preg_replace('/a2wl_/', '', $key, 1);
75 unset($filter[$key]);
76 $filter[$new_key] = wp_unslash($val);
77 if (in_array($new_key, $adv_search_field)) {
78 $adv_search = true;
79 }
80 }
81
82 if (!isset($filter['sort'])) {
83 $filter['sort'] = "volumeDown";
84 }
85
86 $page = isset($_GET['cur_page']) && intval($_GET['cur_page']) ? intval($_GET['cur_page']) : 1;
87 $per_page = 20;
88 if (a2wl_check_defined('A2WL_STORE_PRODUCT_SEARCH_LIMIT')) {
89 $per_page = intval(A2WL_STORE_PRODUCT_SEARCH_LIMIT);
90 }
91
92 if (!empty($_REQUEST['a2wl_search'])) {
93 check_admin_referer(self::PAGE_NONCE_ACTION, self::NONCE);
94
95 $load_products_result = $this->AliexpressModel->load_store_products($filter, $page, $per_page);
96 } else {
97 $load_products_result = ResultBuilder::buildError(esc_html__('Please enter some store id and seller id!', 'ali2woo'));
98 }
99
100 if ($load_products_result['state'] == 'error' || $load_products_result['state'] == 'warn') {
101 add_settings_error('a2wl_products_list', esc_attr('settings_updated'), $load_products_result['message'], 'error');
102 }
103
104 if ($load_products_result['state'] != 'error') {
105 $pages_list = [];
106 $links = 4;
107 $last = ceil($load_products_result['total'] / $per_page);
108 $load_products_result['total_pages'] = $last;
109 $start = (($load_products_result['page'] - $links) > 0) ? $load_products_result['page'] - $links : 1;
110 $end = (($load_products_result['page'] + $links) < $last) ? $load_products_result['page'] + $links : $last;
111 if ($start > 1) {
112 $pages_list[] = 1;
113 $pages_list[] = '';
114 }
115 for ($i = $start; $i <= $end; $i++) {
116 $pages_list[] = $i;
117 }
118 if ($end < $last) {
119 $pages_list[] = '';
120 $pages_list[] = $last;
121 }
122 $load_products_result['pages_list'] = $pages_list;
123
124 a2wl_set_transient('a2wl_search_store_result', $load_products_result['products']);
125 }
126
127 $localizator = AliexpressLocalizator::getInstance();
128
129 $page = esc_attr(((isset($_GET['page'])) ? $_GET['page'] : ''));
130 $curPage = esc_attr(((isset($_GET['cur_page'])) ? $_GET['cur_page'] : ''));;
131
132 $this->model_put('filter', $filter);
133 $this->model_put('adv_search', $adv_search);
134 $this->model_put('categories', $this->get_categories());
135 $this->model_put('countries', $this->CountryModel->get_countries());
136 $this->model_put('locale', $localizator->getLangCode());
137 $this->model_put('currency', $localizator->currency);
138 $this->model_put('chrome_ext_import', a2wl_check_defined('A2WL_CHROME_EXT_IMPORT'));
139 $this->model_put('load_products_result', $load_products_result);
140 $this->model_put('page', $page);
141 $this->model_put('curPage', $curPage);
142
143
144 $this->model_put('promo_data', $this->PromoService->getPromoData());
145
146
147 $this->model_put("PermanentAlerts", $this->PermanentAlertService->getAll());
148 $this->model_put("TipOfDay", $this->TipOfDayService->getNextTip());
149
150 $search_version = 'v1';
151 $this->include_view('search_store_products_' . $search_version . '.php');
152 }
153
154 protected function get_categories()
155 {
156 if (file_exists(A2WL()->plugin_path() . '/assets/data/user_aliexpress_categories.json')) {
157 $result = json_decode(
158 // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
159 file_get_contents(A2WL()->plugin_path() . '/assets/data/user_aliexpress_categories.json'),
160 true
161 );
162 } else {
163 $result = array('categories' => get_option('a2wl_all_categories', array()));
164 }
165 $result = isset($result["categories"]) && is_array($result["categories"]) ? $result["categories"] : array();
166 array_unshift($result, array("id" => "0", "name" => "All categories", "level" => 1));
167 return $result;
168 }
169
170 }
171