Skip to content

Commit

Permalink
fix: Several minor obscured syntax errors fix (#771)
Browse files Browse the repository at this point in the history
* fix: Several minor obscured syntax errors fix

* fix: more fixes.

* fix: attribute "name" and "label" inconsistencies resolved.
  • Loading branch information
kidunot89 authored Jul 19, 2023
1 parent 920d0b2 commit e6be30e
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion includes/admin/class-general.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function get_fields() {
$account_url_hardcoded = defined( 'ACCOUNT_URL_NONCE_PARAM' ) && ! empty( constant( 'ACCOUNT_URL_NONCE_PARAM' ) );
$add_payment_method_url_hardcoded = defined( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) && ! empty( constant( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) );

$enable_auth_urls_hardcoded = defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) && ! empty( constant( 'ADD_PAYMENT_METHOD_URL_NONCE_PARAM' ) );
$enable_auth_urls_hardcoded = defined( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) && ! empty( constant( 'WPGRAPHQL_WOOCOMMERCE_ENABLE_AUTH_URLS' ) );

return [
[
Expand Down
5 changes: 3 additions & 2 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,9 @@ public static function register_post_types( $args, $post_type ) {
$args['graphql_resolve_type'] = static function ( $value ) {
$type_registry = \WPGraphQL::get_type_registry();
$possible_types = WooGraphQL::get_enabled_product_types();
if ( isset( $possible_types[ $value->type ] ) ) {
return $type_registry->get_type( $possible_types[ $value->type ] );
$product_type = $value->get_type();
if ( isset( $possible_types[ $product_type ] ) ) {
return $type_registry->get_type( $possible_types[ $product_type ] );
} elseif ( 'on' === woographql_setting( 'enable_unsupported_product_type', 'off' ) ) {
$unsupported_type = WooGraphQL::get_supported_product_type();
return $type_registry->get_type( $unsupported_type );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static function product_attributes_to_data_array( $attrs, $product_id ) {
if ( ! is_a( $attribute, 'WC_Product_Attribute' ) ) {
continue;
}
$name = wc_attribute_label( $attribute->get_name() );
$name = $attribute->get_name();

if ( $attribute->is_taxonomy() ) {
$attribute_taxonomy = $attribute->get_taxonomy_object();
Expand Down
2 changes: 1 addition & 1 deletion includes/type/interface/class-attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
class Attribute {
/**
* Registers the "Product" interface.
* Registers the "Attribute" interface.
*
* @return void
*/
Expand Down
2 changes: 1 addition & 1 deletion includes/type/interface/class-product-attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static function get_fields() {
'type' => 'String',
'description' => __( 'Attribute label', 'wp-graphql-woocommerce' ),
'resolve' => static function ( $attribute ) {
return ! empty( $attribute->get_name() ) ? ucwords( $attribute->get_name() ) : null;
return ! empty( $attribute->get_name() ) ? ucwords( preg_replace( '/(-|_)/', ' ', $attribute->get_name() ) ) : null;
},
],
'options' => [
Expand Down
4 changes: 1 addition & 3 deletions includes/type/object/class-product-attribute-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,7 @@ public static function register() {
'type' => 'String',
'description' => __( 'Product attribute name', 'wp-graphql-woocommerce' ),
'resolve' => static function ( $attribute ) {
$taxonomy = get_taxonomy( $attribute->get_name() );

return $taxonomy ? $taxonomy->labels->singular_name : null;
return $attribute->get_name();
},
],
'slug' => [
Expand Down
5 changes: 3 additions & 2 deletions includes/type/object/class-variation-attribute-type.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ public static function register() {
return null;
}

$slug = \wc_attribute_taxonomy_slug( $source['name'] );
return ucwords( str_replace( '_', ' ', $slug ) );
$slug = \wc_attribute_taxonomy_slug( $source['name'] );
$label = preg_replace( '/(-|_)/', ' ', $slug );
return ! empty( $label ) ? ucwords( $label ) : null;
},
],
'name' => [
Expand Down
4 changes: 2 additions & 2 deletions includes/utils/class-transfer-session-handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public function get_client_session_id() {
$session_data = 0 !== $session_id ? $this->get_session( (string) $session_id ) : null;

if ( ! empty( $session_data ) ) {
$client_session_id = $session_data['client_session_id'];
$client_session_id_expiration = $session_data['client_session_id_expiration'];
$client_session_id = ! empty( $session_data['client_session_id'] ) ? $session_data['client_session_id'] : false;
$client_session_id_expiration = ! empty( $session_data['client_session_id_expiration'] ) ? $session_data['client_session_id_expiration'] : 0;
} else {
$client_session_id = $this->get( 'client_session_id', false );
$client_session_id_expiration = absint( $this->get( 'client_session_id_expiration', 0 ) );
Expand Down
4 changes: 2 additions & 2 deletions tests/wpunit/ProductAttributeQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public function expectedProductAttributeData( $product_id, $path ) {
[
$this->expectedField( 'id', base64_encode( $attribute_name . ':' . $product_id . ':' . $attribute->get_name() ) ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
$this->expectedField( 'attributeId', $attribute->get_id() ),
$this->expectedField( 'name', str_replace( 'pa_', '', $attribute->get_name() ) ),
$this->expectedField( 'name', $attribute->get_name() ),
$this->expectedField(
'label',
$attribute->is_taxonomy()
? ucwords( get_taxonomy( $attribute->get_name() )->labels->singular_name )
: ucfirst( $attribute->get_name() )
: ucwords( preg_replace( '/(-|_)/', ' ', $attribute->get_name() ) )
),
$this->expectedField( 'options', $attribute->get_slugs() ),
$this->expectedField( 'position', $attribute->get_position() ),
Expand Down
2 changes: 1 addition & 1 deletion tests/wpunit/VariationAttributeQueriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function expectedDefaultAttributes( $id ) {

$expected = [];
foreach ( $attributes as $attribute ) {
$name = wc_attribute_label( $attribute->get_name() );
$name = $attribute->get_name();
if ( $attribute->is_taxonomy() ) {
$attribute_values = wc_get_product_terms( $id, $attribute->get_name(), [ 'fields' => 'all' ] );
foreach ( $attribute_values as $attribute_value ) {
Expand Down

0 comments on commit e6be30e

Please sign in to comment.