Skip to content

Commit e6be30e

Browse files
authored
fix: Several minor obscured syntax errors fix (#771)
* fix: Several minor obscured syntax errors fix * fix: more fixes. * fix: attribute "name" and "label" inconsistencies resolved.
1 parent 920d0b2 commit e6be30e

10 files changed

+16
-16
lines changed

includes/admin/class-general.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function get_fields() {
6565
$account_url_hardcoded = defined( 'ACCOUNT_URL_NONCE_PARAM' ) && ! empty( constant( 'ACCOUNT_URL_NONCE_PARAM' ) );
6666
$add_payment_method_url_hardcoded = defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) && ! empty( constant( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) );
6767

68-
$enable_auth_urls_hardcoded = defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) && ! empty( constant( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) );
68+
$enable_auth_urls_hardcoded = defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) && ! empty( constant( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) );
6969

7070
return [
7171
[

includes/class-core-schema-filters.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ public static function register_post_types( $args, $post_type ) {
144144
$args['graphql_resolve_type'] = static function ( $value ) {
145145
$type_registry = \WPGraphQL::get_type_registry();
146146
$possible_types = WooGraphQL::get_enabled_product_types();
147-
if ( isset( $possible_types[ $value->type ] ) ) {
148-
return $type_registry->get_type( $possible_types[ $value->type ] );
147+
$product_type = $value->get_type();
148+
if ( isset( $possible_types[ $product_type ] ) ) {
149+
return $type_registry->get_type( $possible_types[ $product_type ] );
149150
} elseif ( 'on' === woographql_setting( 'enable_unsupported_product_type', 'off' ) ) {
150151
$unsupported_type = WooGraphQL::get_supported_product_type();
151152
return $type_registry->get_type( $unsupported_type );

includes/data/connection/class-variation-attribute-connection-resolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static function product_attributes_to_data_array( $attrs, $product_id ) {
3535
if ( ! is_a( $attribute, 'WC_Product_Attribute' ) ) {
3636
continue;
3737
}
38-
$name = wc_attribute_label( $attribute->get_name() );
38+
$name = $attribute->get_name();
3939

4040
if ( $attribute->is_taxonomy() ) {
4141
$attribute_taxonomy = $attribute->get_taxonomy_object();

includes/type/interface/class-attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
class Attribute {
1515
/**
16-
* Registers the "Product" interface.
16+
* Registers the "Attribute" interface.
1717
*
1818
* @return void
1919
*/

includes/type/interface/class-product-attribute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static function get_fields() {
6565
'type' => 'String',
6666
'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ),
6767
'resolve' => static function ( $attribute ) {
68-
return ! empty( $attribute->get_name() ) ? ucwords( $attribute->get_name() ) : null;
68+
return ! empty( $attribute->get_name() ) ? ucwords( preg_replace( '/(-|_)/', ' ', $attribute->get_name() ) ) : null;
6969
},
7070
],
7171
'options' => [

includes/type/object/class-product-attribute-types.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,7 @@ public static function register() {
7878
'type' => 'String',
7979
'description' => __( 'Product attribute name', 'wp-graphql-woocommerce' ),
8080
'resolve' => static function ( $attribute ) {
81-
$taxonomy = get_taxonomy( $attribute->get_name() );
82-
83-
return $taxonomy ? $taxonomy->labels->singular_name : null;
81+
return $attribute->get_name();
8482
},
8583
],
8684
'slug' => [

includes/type/object/class-variation-attribute-type.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ public static function register() {
4848
return null;
4949
}
5050

51-
$slug = \wc_attribute_taxonomy_slug( $source['name'] );
52-
return ucwords( str_replace( '_', ' ', $slug ) );
51+
$slug = \wc_attribute_taxonomy_slug( $source['name'] );
52+
$label = preg_replace( '/(-|_)/', ' ', $slug );
53+
return ! empty( $label ) ? ucwords( $label ) : null;
5354
},
5455
],
5556
'name' => [

includes/utils/class-transfer-session-handler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ public function get_client_session_id() {
9595
$session_data = 0 !== $session_id ? $this->get_session( (string) $session_id ) : null;
9696

9797
if ( ! empty( $session_data ) ) {
98-
$client_session_id = $session_data['client_session_id'];
99-
$client_session_id_expiration = $session_data['client_session_id_expiration'];
98+
$client_session_id = ! empty( $session_data['client_session_id'] ) ? $session_data['client_session_id'] : false;
99+
$client_session_id_expiration = ! empty( $session_data['client_session_id_expiration'] ) ? $session_data['client_session_id_expiration'] : 0;
100100
} else {
101101
$client_session_id = $this->get( 'client_session_id', false );
102102
$client_session_id_expiration = absint( $this->get( 'client_session_id_expiration', 0 ) );

tests/wpunit/ProductAttributeQueriesTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ public function expectedProductAttributeData( $product_id, $path ) {
1313
[
1414
$this->expectedField( 'id', base64_encode( $attribute_name . ':' . $product_id . ':' . $attribute->get_name() ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
1515
$this->expectedField( 'attributeId', $attribute->get_id() ),
16-
$this->expectedField( 'name', str_replace( 'pa_', '', $attribute->get_name() ) ),
16+
$this->expectedField( 'name', $attribute->get_name() ),
1717
$this->expectedField(
1818
'label',
1919
$attribute->is_taxonomy()
2020
? ucwords( get_taxonomy( $attribute->get_name() )->labels->singular_name )
21-
: ucfirst( $attribute->get_name() )
21+
: ucwords( preg_replace( '/(-|_)/', ' ', $attribute->get_name() ) )
2222
),
2323
$this->expectedField( 'options', $attribute->get_slugs() ),
2424
$this->expectedField( 'position', $attribute->get_position() ),

tests/wpunit/VariationAttributeQueriesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function expectedDefaultAttributes( $id ) {
4343

4444
$expected = [];
4545
foreach ( $attributes as $attribute ) {
46-
$name = wc_attribute_label( $attribute->get_name() );
46+
$name = $attribute->get_name();
4747
if ( $attribute->is_taxonomy() ) {
4848
$attribute_values = wc_get_product_terms( $id, $attribute->get_name(), [ 'fields' => 'all' ] );
4949
foreach ( $attribute_values as $attribute_value ) {

0 commit comments

Comments
 (0)