Skip to content

Commit f8be1fc

Browse files
committed
Fix: customer select in settings
1 parent a2f3064 commit f8be1fc

File tree

17 files changed

+733
-292
lines changed

17 files changed

+733
-292
lines changed

includes/API/Settings.php

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ class Settings extends Settings_Controller {
9191
/**
9292
* Settings constructor.
9393
*/
94-
public function __construct() { }
94+
public function __construct() {
95+
add_filter( 'option_woocommerce_pos_settings_payment_gateways', array( $this, 'payment_gateways_settings' ) );
96+
}
9597

9698
/**
9799
* @return void
@@ -306,9 +308,15 @@ public function get_checkout_endpoint_args(): array {
306308
*
307309
*/
308310
public function get_license_settings() {
311+
$settings = array();
312+
313+
if ( class_exists( '\WCPOS\WooCommercePOSPro' ) ) {
314+
$settings = get_option( self::$db_prefix . 'license', array() );
315+
}
316+
309317
$license_settings = array_replace_recursive(
310318
self::$default_settings['license'],
311-
get_option( self::$db_prefix . 'license', array() )
319+
$settings
312320
);
313321

314322
/**
@@ -328,9 +336,16 @@ public function get_license_settings() {
328336
/**
329337
* @return array
330338
*/
331-
public function get_barcodes(): array {
339+
public function get_barcodes( WP_REST_Request $request ): array {
332340
global $wpdb;
333341

342+
// Get 'search' parameter from request
343+
$search = $request->get_param( 'search' );
344+
345+
// maybe add custom barcode field
346+
$custom_field = woocommerce_pos_get_settings( 'general', 'barcode_field' );
347+
348+
// Prepare the basic query
334349
$result = $wpdb->get_col(
335350
"
336351
SELECT DISTINCT(pm.meta_key)
@@ -342,12 +357,17 @@ public function get_barcodes(): array {
342357
"
343358
);
344359

345-
// maybe add custom barcode field
346-
$custom_field = woocommerce_pos_get_settings( 'general', 'barcode_field' );
347360
if ( ! empty( $custom_field ) ) {
348361
$result[] = $custom_field;
349362
}
350363

364+
// Filter the results
365+
if ( ! empty( $search ) ) {
366+
$result = array_filter( $result, function( $item ) use ( $search ) {
367+
return stripos( $item, $search ) !== false;
368+
});
369+
}
370+
351371
sort( $result );
352372

353373
return array_unique( $result );
@@ -601,4 +621,19 @@ public function update_permission_check() {
601621
public function access_permission_check() {
602622
return current_user_can( 'promote_users' );
603623
}
624+
625+
/**
626+
*
627+
*/
628+
public function payment_gateways_settings( $options ) {
629+
foreach ( $options['gateways'] as $gateway_id => &$gateway_data ) {
630+
if ( ! in_array( $gateway_id, array( 'pos_cash', 'pos_card' ) ) ) {
631+
$gateway_data['enabled'] = false;
632+
}
633+
}
634+
if ( ! in_array( $options['default_gateway'], array( 'pos_cash', 'pos_card' ) ) ) {
635+
$options['default_gateway'] = 'pos_cash';
636+
}
637+
return $options;
638+
}
604639
}

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@wcpos/woocommerce-pos",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "A simple front-end for taking WooCommerce orders at the Point of Sale.",
55
"main": "index.js",
66
"workspaces": {
@@ -25,7 +25,7 @@
2525
"settings": "yarn workspace @wcpos/settings",
2626
"analytics": "yarn workspace @wcpos/analytics",
2727
"edit-product": "yarn workspace @wcpos/edit-product",
28-
"build:js": "yarn workspace @wcpos/settings build && yarn workspace @wcpos/edit-product build"
28+
"build:js": "yarn workspace @wcpos/settings build && yarn workspace @wcpos/edit-product build && yarn workspace @wcpos/analytics build"
2929
},
3030
"repository": {
3131
"type": "git",

packages/analytics/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"start": "../../node_modules/.bin/webpack --watch"
66
},
77
"dependencies": {
8-
"@tanstack/react-query": "^4.29.14",
8+
"@tanstack/react-query": "^4.29.15",
99
"@transifex/native": "^5.3.0",
1010
"@transifex/react": "^5.3.0",
1111
"@woocommerce/components": "^12.0.0",
@@ -28,16 +28,16 @@
2828
"@babel/preset-typescript": "7.22.5",
2929
"@babel/runtime": "7.22.5",
3030
"@svgr/webpack": "8.0.1",
31-
"@tanstack/react-query-devtools": "^4.29.14",
31+
"@tanstack/react-query-devtools": "^4.29.15",
3232
"@transifex/cli": "^5.3.0",
3333
"@types/jest": "29.5.2",
3434
"@types/lodash": "4.14.195",
35-
"@types/react": "18.2.12",
35+
"@types/react": "18.2.13",
3636
"@types/react-beautiful-dnd": "13.1.4",
37-
"@types/react-dom": "18.2.5",
37+
"@types/react-dom": "18.2.6",
3838
"@types/wordpress__components": "^23.0.1",
39-
"@typescript-eslint/eslint-plugin": "5.59.11",
40-
"@typescript-eslint/parser": "5.59.11",
39+
"@typescript-eslint/eslint-plugin": "5.60.0",
40+
"@typescript-eslint/parser": "5.60.0",
4141
"@wcpos/eslint-config": "*",
4242
"@wordpress/env": "8.1.1",
4343
"autoprefixer": "10.4.14",

packages/eslint/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
},
1313
"dependencies": {
1414
"@rushstack/eslint-patch": "^1.3.2",
15-
"@typescript-eslint/eslint-plugin": "^5.59.11",
16-
"@typescript-eslint/parser": "5.59.11",
15+
"@typescript-eslint/eslint-plugin": "^5.60.0",
16+
"@typescript-eslint/parser": "5.60.0",
1717
"@wcpos/tsconfig": "*",
1818
"eslint": "8.43.0",
1919
"eslint-config-airbnb": "19.0.4",
2020
"eslint-config-prettier": "8.8.0",
21-
"eslint-config-universe": "^11.2.0",
21+
"eslint-config-universe": "^11.3.0",
2222
"eslint-plugin-import": "2.27.5",
23-
"eslint-plugin-jest": "27.2.1",
23+
"eslint-plugin-jest": "27.2.2",
2424
"eslint-plugin-jsx-a11y": "6.7.1",
2525
"eslint-plugin-prettier": "4.2.1",
2626
"eslint-plugin-react": "7.32.2",

packages/settings/assets/check.svg

Lines changed: 2 additions & 0 deletions
Loading
Lines changed: 1 addition & 0 deletions
Loading

packages/settings/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"start": "../../node_modules/.bin/webpack --watch"
66
},
77
"dependencies": {
8-
"@tanstack/react-query": "^4.29.14",
8+
"@headlessui/react": "^1.7.15",
9+
"@headlessui/tailwindcss": "^0.1.3",
10+
"@tanstack/react-query": "^4.29.15",
911
"@transifex/native": "^5.3.0",
1012
"@transifex/react": "^5.3.0",
1113
"@wordpress/api-fetch": "6.32.0",
@@ -27,16 +29,16 @@
2729
"@babel/preset-typescript": "7.22.5",
2830
"@babel/runtime": "7.22.5",
2931
"@svgr/webpack": "8.0.1",
30-
"@tanstack/react-query-devtools": "^4.29.14",
32+
"@tanstack/react-query-devtools": "^4.29.15",
3133
"@transifex/cli": "^5.3.0",
3234
"@types/jest": "29.5.2",
3335
"@types/lodash": "4.14.195",
34-
"@types/react": "18.2.12",
36+
"@types/react": "18.2.13",
3537
"@types/react-beautiful-dnd": "13.1.4",
36-
"@types/react-dom": "18.2.5",
38+
"@types/react-dom": "18.2.6",
3739
"@types/wordpress__components": "^23.0.1",
38-
"@typescript-eslint/eslint-plugin": "5.59.11",
39-
"@typescript-eslint/parser": "5.59.11",
40+
"@typescript-eslint/eslint-plugin": "5.60.0",
41+
"@typescript-eslint/parser": "5.60.0",
4042
"@wcpos/eslint-config": "*",
4143
"@wordpress/env": "8.1.1",
4244
"autoprefixer": "10.4.14",

0 commit comments

Comments
 (0)