Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v0.1.1 #81

Merged
merged 19 commits into from
Jun 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
150783d
.travis.yml updated
kidunot89 Jun 1, 2019
cbe3fb2
README.md updated.
kidunot89 Jun 2, 2019
7a011bf
Product type pricing field resolvers updated.
kidunot89 Jun 2, 2019
2f256f1
Variable-type product formatting added.
kidunot89 Jun 2, 2019
766bf3e
ProductQueriesTest updated
kidunot89 Jun 2, 2019
9d3147d
Product Variation pricing field resolvers updated.
kidunot89 Jun 2, 2019
7c5097c
ProductVariationHelper::print_query updated.
kidunot89 Jun 2, 2019
a57becf
Order type pricing field resolvers updated. OrderHelper::print_query …
kidunot89 Jun 3, 2019
5ed89fc
Cart type pricing field resolvers updated. CartHelper::print_query up…
kidunot89 Jun 3, 2019
d2a7e74
CartItem type pricing field resolvers updated. CartHelper::print_quer…
kidunot89 Jun 3, 2019
606832a
Formatting functionality implemented for Product and ProductVariation…
kidunot89 Jun 3, 2019
83d648a
Formatting functionality implemented for Order type. OrderHelper::pri…
kidunot89 Jun 3, 2019
7b0fe1b
Merge pull request #82 from kidunot89/bugfix/pricing-fields-format
kidunot89 Jun 3, 2019
a430dc4
ProductToTerm connection and TermToProduct connections tests added.
kidunot89 Jun 5, 2019
78964db
ProductToMediaItem connections tested.
kidunot89 Jun 5, 2019
b70c551
ProductDownload tested. ProductRatingCounter removed. Unused tests st…
kidunot89 Jun 5, 2019
c60814f
More tests added to Product and ProductVariation.
kidunot89 Jun 5, 2019
e13ddce
More tests modifications for Product and ProductVariation code coverage.
kidunot89 Jun 5, 2019
6baf963
Merge pull request #83 from kidunot89/feature/more-tests
kidunot89 Jun 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ branches:
only:
- develop
- release-v0.1.0
- release-v0.1.1

cache:
apt: true
Expand Down Expand Up @@ -55,13 +56,13 @@ before_script:
if [ ! -z "$WP_VERSION" ]; then
# Install and config Codeception
cp .env.dist .env
COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install-wp-tests
composer install-wp-tests
COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-source --no-interaction
if [ "$COVERAGE" == "1" ]; then
# Install Coveralls
mkdir -p build/logs
COMPOSER_MEMORY_LIMIT=-1 travis_retry composer require php-coveralls/php-coveralls
fi
COMPOSER_MEMORY_LIMIT=-1 travis_retry composer install --prefer-source --no-interaction
ls -al
fi
# Install PHP CodeSniffer and WPCS.
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ It adds WooCommerce functionality to the WPGraphQL schema using WooCommerce's [C
- Public/Customer mutations, Eg. Manipulating the cart and checking out.
View [Roadmap](https://github.com/wp-graphql/wp-graphql-woocommerce/projects/1) to see progress...

## Playground
Feel free to test out the extension using the [playground](https://docs.wpgraphql.com/extensions/wpgraphql-woocommerce/). The playground allows you to execute queries and mutations, as well as view the schema.

## Unit Tests
Until the documentation is in full effect, it's recommended that a [GraphiQL](https://github.com/graphql/graphiql)-based tool like [WPGraphiQL](https://github.com/wp-graphql/wp-graphiql) be used to view the GraphQL schema, an alternative to this is viewing the unit tests located in `tests/wpunit` directory. Which are constantly updated along with the project. If you're interested in contributing when I begin accepting contribution or simply want to run the tests. Follow the instruction below.

Expand Down
78 changes: 78 additions & 0 deletions access-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,81 @@ function wc_graphql_get_order_statuses() {
}
return $order_statuses;
}

/**
* Format the price with a currency symbol.
*
* @param float $price Raw price.
* @param array $args Arguments to format a price {
* Array of arguments.
* Defaults to empty array.
*
* @type string $currency Currency code.
* Defaults to empty string (Use the result from get_woocommerce_currency()).
* @type string $decimal_separator Decimal separator.
* Defaults the result of wc_get_price_decimal_separator().
* @type string $thousand_separator Thousand separator.
* Defaults the result of wc_get_price_thousand_separator().
* @type string $decimals Number of decimals.
* Defaults the result of wc_get_price_decimals().
* @type string $price_format Price format depending on the currency position.
* Defaults the result of get_woocommerce_price_format().
* }
* @return string
*/
function wc_graphql_price( $price, $args = array() ) {
$args = apply_filters(
'wc_price_args',
wp_parse_args(
$args,
array(
'currency' => '',
'decimal_separator' => wc_get_price_decimal_separator(),
'thousand_separator' => wc_get_price_thousand_separator(),
'decimals' => wc_get_price_decimals(),
'price_format' => get_woocommerce_price_format(),
)
)
);

$unformatted_price = $price;
$negative = $price < 0;
$price = apply_filters( 'raw_woocommerce_price', floatval( $negative ? $price * -1 : $price ) );
$price = apply_filters( 'formatted_woocommerce_price', number_format( $price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator'] ), $price, $args['decimals'], $args['decimal_separator'], $args['thousand_separator'] );

if ( apply_filters( 'woocommerce_price_trim_zeros', false ) && $args['decimals'] > 0 ) {
$price = wc_trim_zeros( $price );
}

$symbol = html_entity_decode( get_woocommerce_currency_symbol( $args['currency'] ) );
$return = ( $negative ? '-' : '' ) . sprintf( $args['price_format'], $symbol, $price );

/**
* Filters the string of price markup.
*
* @param string $return Price HTML markup.
* @param string $price Formatted price.
* @param array $args Pass on the args.
* @param float $unformatted_price Price as float to allow plugins custom formatting. Since 3.2.0.
*/
return apply_filters( 'wc_graphql_price', $return, $price, $args, $unformatted_price, $symbol );
}

/**
* Format a price range for display.
*
* @param string $from Price from.
* @param string $to Price to.
* @return string
*/
function wc_graphql_price_range( $from, $to ) {
$price = sprintf(
/* translators: 1: price from 2: price to */
_x( '%1$s %2$s %3$s', 'Price range: from-to', 'wp-graphql-woocommerce' ),
is_numeric( $from ) ? wc_graphql_price( $from ) : $from,
apply_filters( 'graphql_format_price_range_separator', '-', $from, $to ),
is_numeric( $to ) ? wc_graphql_price( $to ) : $to
);

return apply_filters( 'graphql_format_price_range', $price, $from, $to );
}
4 changes: 2 additions & 2 deletions includes/class-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use WPGraphQL\Extensions\WooCommerce\Type\WPEnum\Tax_Status;
use WPGraphQL\Extensions\WooCommerce\Type\WPEnum\WC_Connection_Orderby_Enum;
use WPGraphQL\Extensions\WooCommerce\Type\WPEnum\Tax_Rate_Connection_Orderby_Enum;
use WPGraphQL\Extensions\WooCommerce\Type\WPEnum\Pricing_Field_Format;
use WPGraphQL\Extensions\WooCommerce\Type\WPInputObject\Customer_Address_Input;
use WPGraphQL\Extensions\WooCommerce\Type\WPInputObject\Product_Attribute_Input;
use WPGraphQL\Extensions\WooCommerce\Type\WPInputObject\WC_Connection_Orderby_Input;
Expand All @@ -35,7 +36,6 @@
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Variation_Type;
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Attribute_Type;
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Download_Type;
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Product_Rating_Counter_Type;
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Customer_Type;
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Customer_Address_Type;
use WPGraphQL\Extensions\WooCommerce\Type\WPObject\Tax_Rate_Type;
Expand Down Expand Up @@ -103,6 +103,7 @@ public static function graphql_register_types() {
Tax_Status::register();
WC_Connection_Orderby_Enum::register();
Tax_Rate_Connection_Orderby_Enum::register();
Pricing_Field_Format::register();

// InputObjects.
Customer_Address_Input::register();
Expand All @@ -119,7 +120,6 @@ public static function graphql_register_types() {
Refund_Type::register();
Product_Attribute_Type::register();
Product_Download_Type::register();
Product_Rating_Counter_Type::register();
Customer_Type::register();
Customer_Address_Type::register();
Tax_Rate_Type::register();
Expand Down
88 changes: 72 additions & 16 deletions includes/model/class-order.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,85 @@ protected function init() {
return ! empty( $this->data->get_date_paid() ) ? $this->data->get_date_paid() : null;
},
'discountTotal' => function() {
return ! empty( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0;
},
$price = ! empty( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'discountTotalRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_discount_total() ) ? $this->data->get_discount_total() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'discountTax' => function() {
return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0;
},
$price = ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'discountTaxRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_discount_tax() ) ? $this->data->get_discount_tax() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'shippingTotal' => function() {
return ! empty( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0;
},
$price = ! empty( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'shippingTotalRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_shipping_total() ) ? $this->data->get_shipping_total() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'shippingTax' => function() {
return ! empty( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0;
},
$price = ! empty( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'shippingTaxRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_shipping_tax() ) ? $this->data->get_shipping_tax() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'cartTax' => function() {
return ! empty( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0;
},
$price = ! empty( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'cartTaxRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_cart_tax() ) ? $this->data->get_cart_tax() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'total' => function() {
return ! empty( $this->data->get_total() ) ? $this->data->get_total() : 0;
},
$price = ! empty( $this->data->get_total() ) ? $this->data->get_total() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'totalRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_total() ) ? $this->data->get_total() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'totalTax' => function() {
return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : 0;
},
$price = ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : 0;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'totalTaxRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_total_tax() ) ? $this->data->get_total_tax() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'subtotal' => function() {
return ! empty( $this->data->get_subtotal() ) ? $this->data->get_subtotal() : 0;
},
$price = ! empty( $this->data->get_subtotal() ) ? $this->data->get_subtotal() : null;
return \wc_graphql_price( $price, array( 'currency' => $this->data->get_currency() ) );
},
'subtotalRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_subtotal() ) ? $this->data->get_subtotal() : 0;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'orderNumber' => function() {
return ! empty( $this->data->get_order_number() ) ? $this->data->get_order_number() : null;
},
Expand Down
36 changes: 30 additions & 6 deletions includes/model/class-product-variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,38 @@ protected function init() {
return ! empty( $this->data->get_sku() ) ? $this->data->get_sku() : null;
},
'price' => function() {
return ! empty( $this->data->get_price() ) ? $this->data->get_price() : null;
},
return ! empty( $this->data->get_price() )
? \wc_graphql_price( $this->data->get_price() )
: null;
},
'priceRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_price() ) ? $this->data->get_price() : null;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'salePrice' => function() {
return ! empty( $this->data->get_sale_price() ) ? $this->data->get_sale_price() : null;
},
return ! empty( $this->data->get_sale_price() )
? \wc_graphql_price( $this->data->get_sale_price() )
: null;
},
'salePriceRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_sale_price() ) ? $this->data->get_sale_price() : null;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'regularPrice' => function() {
return ! empty( $this->data->get_regular_price() ) ? $this->data->get_regular_price() : null;
},
return ! empty( $this->data->get_regular_price() ) ?
\wc_graphql_price( $this->data->get_regular_price() )
: null;
},
'regularPriceRaw' => array(
'callback' => function() {
return ! empty( $this->data->get_regular_price() ) ? $this->data->get_regular_price() : null;
},
'capability' => $this->post_type_object->cap->edit_posts,
),
'dateOnSaleFrom' => function() {
return ! empty( $this->data->get_date_on_sale_from() ) ? $this->data->get_date_on_sale_from() : null;
},
Expand Down
Loading