Skip to content

Commit 5b13160

Browse files
authored
Merge pull request #182 from kidunot89/new-mutation/update-shipping-method
Improved shipping support
2 parents 22f3ad7 + b23ee2b commit 5b13160

27 files changed

+669
-81
lines changed

bin/testing-entrypoint.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,8 @@ chmod 777 ${TESTS_OUTPUT}
6868
# Run tests
6969
run_tests ${SUITES}
7070

71-
# Fix codecoverage permissions and clean coverage.xml
71+
# Clean coverage.xml and clean up PCOV configurations.
7272
if [ -f "${TESTS_OUTPUT}/coverage.xml" ] && [[ "$COVERAGE" == "1" ]]; then
73-
echo 'Setting "coverage.xml" permissions'.
74-
chmod 777 -R "$TESTS_OUTPUT"/coverage.xml
75-
7673
echo 'Cleaning coverage.xml for deployment'.
7774
pattern="$PROJECT_DIR/"
7875
sed -i "s~$pattern~~g" "$TESTS_OUTPUT"/coverage.xml
@@ -85,6 +82,14 @@ if [ -f "${TESTS_OUTPUT}/coverage.xml" ] && [[ "$COVERAGE" == "1" ]]; then
8582
fi
8683
fi
8784

85+
# Set public test result files permissions.
86+
if [ -n "$(ls "$TESTS_OUTPUT")" ]; then
87+
echo 'Setting result files permissions'.
88+
chmod 777 -R "$TESTS_OUTPUT"/*
89+
fi
90+
91+
92+
# Check results and exit accordingly.
8893
if [ -f "${TESTS_OUTPUT}/failed" ]; then
8994
echo "Uh oh, some went wrong."
9095
exit 1

includes/class-type-registry.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {
7272
\WPGraphQL\WooCommerce\Type\WPObject\Variation_Attribute_Type::register();
7373
\WPGraphQL\WooCommerce\Type\WPObject\Payment_Gateway_Type::register();
7474
\WPGraphQL\WooCommerce\Type\WPObject\Meta_Data_Type::register();
75+
\WPGraphQL\WooCommerce\Type\WPObject\Shipping_Package_Type::register();
76+
\WPGraphQL\WooCommerce\Type\WPObject\Shipping_Rate_Type::register();
7577

7678
// Object fields.
7779
\WPGraphQL\WooCommerce\Type\WPObject\Product_Category_Type::register_fields();
@@ -103,6 +105,7 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {
103105
\WPGraphQL\WooCommerce\Mutation\Cart_Apply_Coupon::register_mutation();
104106
\WPGraphQL\WooCommerce\Mutation\Cart_Remove_Coupons::register_mutation();
105107
\WPGraphQL\WooCommerce\Mutation\Cart_Add_Fee::register_mutation();
108+
\WPGraphQL\WooCommerce\Mutation\Cart_Update_Shipping_Method::register_mutation();
106109
\WPGraphQL\WooCommerce\Mutation\Order_Create::register_mutation();
107110
\WPGraphQL\WooCommerce\Mutation\Order_Update::register_mutation();
108111
\WPGraphQL\WooCommerce\Mutation\Order_Delete::register_mutation();

includes/connection/class-order-items.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ public static function register_connections() {
4949
register_graphql_connection(
5050
self::get_connection_config(
5151
array(
52-
'toType' => 'FeeLine',
5352
'toType' => 'CouponLine',
5453
'fromFieldName' => 'couponLines',
5554
)
@@ -69,7 +68,7 @@ public static function register_connections() {
6968
*
7069
* @return array
7170
*/
72-
public static function get_connection_config( $args = [] ) {
71+
public static function get_connection_config( $args = array() ) {
7372
$defaults = array(
7473
'fromType' => 'Order',
7574
'toType' => 'LineItem',

includes/connection/class-payment-gateways.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function register_connections() {
3232
*
3333
* @return array
3434
*/
35-
public static function get_connection_config( $args = [] ) {
35+
public static function get_connection_config( $args = array() ) {
3636
$defaults = array(
3737
'fromType' => 'RootQuery',
3838
'toType' => 'PaymentGateway',

includes/connection/class-products.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static function register_connections() {
118118
*
119119
* @return array
120120
*/
121-
public static function get_connection_config( $args = [] ) {
121+
public static function get_connection_config( $args = array() ) {
122122
$defaults = array(
123123
'fromType' => 'RootQuery',
124124
'toType' => 'Product',

includes/data/class-factory.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public static function resolve_customer( $id, AppContext $context ) {
5151
}
5252
$customer_id = absint( $id );
5353
$loader = $context->getLoader( 'wc_customer' );
54-
$loader->buffer( [ $customer_id ] );
54+
$loader->buffer( array( $customer_id ) );
5555
return new Deferred(
5656
function () use ( $loader, $customer_id ) {
5757
return $loader->load( $customer_id );
@@ -74,7 +74,7 @@ public static function resolve_crud_object( $id, AppContext $context ) {
7474
}
7575
$object_id = absint( $id );
7676
$loader = $context->getLoader( 'wc_post_crud' );
77-
$loader->buffer( [ $object_id ] );
77+
$loader->buffer( array( $object_id ) );
7878
return new Deferred(
7979
function () use ( $loader, $object_id ) {
8080
return $loader->load( $object_id );
@@ -166,6 +166,21 @@ public static function resolve_shipping_method( $id ) {
166166
return new Shipping_Method( $method );
167167
}
168168

169+
/**
170+
* Resolves woocommerce cart.
171+
*
172+
* @return \WC_Cart
173+
*/
174+
public static function resolve_cart() {
175+
do_action( 'woocommerce_before_calculate_totals', \WC()->cart );
176+
177+
new \WC_Cart_Totals( \WC()->cart );
178+
179+
do_action( 'woocommerce_after_calculate_totals', \WC()->cart );
180+
181+
return \WC()->cart;
182+
}
183+
169184
/**
170185
* Resolves a cart item by key.
171186
*
@@ -174,9 +189,7 @@ public static function resolve_shipping_method( $id ) {
174189
* @return object
175190
*/
176191
public static function resolve_cart_item( $id ) {
177-
$item = WC()->cart->get_cart_item( $id );
178-
179-
return $item;
192+
return self::resolve_cart()->get_cart_item( $id );
180193
}
181194

182195
/**
@@ -187,10 +200,8 @@ public static function resolve_cart_item( $id ) {
187200
* @return object
188201
*/
189202
public static function resolve_cart_fee( $id ) {
190-
$fees = WC()->cart->get_fees();
191-
192-
if ( ! empty( $fees[ $id ] ) ) {
193-
return $fees[ $id ];
203+
if ( ! empty( self::resolve_cart()->get_fees()[ $id ] ) ) {
204+
return self::resolve_cart()->get_fees()[ $id ];
194205
}
195206

196207
return null;

includes/data/connection/class-product-connection-resolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public function get_query_args() {
147147
/**
148148
* Collect the input_fields and sanitize them to prepare them for sending to the WP_Query
149149
*/
150-
$input_fields = [];
150+
$input_fields = array();
151151
if ( ! empty( $this->args['where'] ) ) {
152152
$input_fields = $this->sanitize_input_fields( $this->args['where'] );
153153
}

includes/data/connection/class-wc-terms-connection-resolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ public static function get_query_args( $query_args = array(), $source, $args, $c
4848
break;
4949
case is_a( $source, Product::class ):
5050
// @codingStandardsIgnoreLine
51-
if ( 'categories' === $info->fieldName ) {
51+
if ( 'productCategories' === $info->fieldName ) {
5252
$query_args['term_taxonomy_id'] = $source->category_ids;
5353
// @codingStandardsIgnoreLine
54-
} elseif ( 'tags' === $info->fieldName ) {
54+
} elseif ( 'productTags' === $info->fieldName ) {
5555
$query_args['term_taxonomy_id'] = $source->tag_ids;
5656
}
5757
break;

includes/model/class-coupon.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ class Coupon extends Crud_CPT {
2626
*/
2727
public function __construct( $id ) {
2828
$this->data = new \WC_Coupon( $id );
29-
$allowed_restricted_fields = [
29+
$allowed_restricted_fields = array(
3030
'isRestricted',
3131
'isPrivate',
3232
'isPublic',
3333
'id',
3434
'couponId',
35-
];
35+
);
3636

3737
parent::__construct( $allowed_restricted_fields, 'shop_coupon', $id );
3838
}

includes/model/class-customer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ class Customer extends Model {
2727
*/
2828
public function __construct( $id ) {
2929
$this->data = new \WC_Customer( $id );
30-
$allowed_restricted_fields = [
30+
$allowed_restricted_fields = array(
3131
'isRestricted',
3232
'isPrivate',
3333
'isPublic',
3434
'id',
3535
'customerId',
3636
'displayName',
37-
];
37+
);
3838

3939
$restricted_cap = apply_filters( 'customer_restricted_cap', 'list_users' );
4040

0 commit comments

Comments
 (0)