@@ -25,6 +25,7 @@ class Cart_Type {
2525 */
2626 public static function register () {
2727 self ::register_cart_fee ();
28+ self ::register_cart_tax ();
2829 self ::register_cart_item ();
2930 self ::register_cart ();
3031 }
@@ -50,7 +51,7 @@ public static function register_cart() {
5051 'type ' => 'String ' ,
5152 'description ' => __ ( 'Cart subtotal tax ' , 'wp-graphql-woocommerce ' ),
5253 'resolve ' => function ( $ source ) {
53- $ price = is_null ( $ source ->get_subtotal_tax () ) ? $ source ->get_subtotal_tax () : 0 ;
54+ $ price = ! is_null ( $ source ->get_subtotal_tax () ) ? $ source ->get_subtotal_tax () : 0 ;
5455 return \wc_graphql_price ( $ price );
5556 },
5657 ),
@@ -172,6 +173,14 @@ public static function register_cart() {
172173 return \wc_graphql_price ( $ price );
173174 },
174175 ),
176+ 'totalTaxes ' => array (
177+ 'type ' => array ( 'list_of ' => 'CartTax ' ),
178+ 'description ' => __ ( 'Cart total taxes itemized ' , 'wp-graphql-woocommerce ' ),
179+ 'resolve ' => function ( $ source ) {
180+ $ taxes = $ source ->get_tax_totals ();
181+ return ! empty ( $ taxes ) ? array_values ( $ taxes ) : null ;
182+ },
183+ ),
175184 'isEmpty ' => array (
176185 'type ' => 'Boolean ' ,
177186 'description ' => __ ( 'Is cart empty ' , 'wp-graphql-woocommerce ' ),
@@ -343,4 +352,45 @@ public static function register_cart_fee() {
343352 )
344353 );
345354 }
355+ /**
356+ * Registers CartTax type
357+ */
358+ public static function register_cart_tax () {
359+ register_graphql_object_type (
360+ 'CartTax ' ,
361+ array (
362+ 'description ' => __ ( 'An itemized cart tax item ' , 'wp-graphql-woocommerce ' ),
363+ 'fields ' => array (
364+ 'id ' => array (
365+ 'type ' => array ( 'non_null ' => 'ID ' ),
366+ 'description ' => __ ( 'Tax Rate ID ' , 'wp-graphql-woocommerce ' ),
367+ 'resolve ' => function ( $ source ) {
368+ return ! empty ( $ source ->tax_rate_id ) ? $ source ->tax_rate_id : null ;
369+ },
370+ ),
371+ 'label ' => array (
372+ 'type ' => array ( 'non_null ' => 'String ' ),
373+ 'description ' => __ ( 'Tax label ' , 'wp-graphql-woocommerce ' ),
374+ 'resolve ' => function ( $ source ) {
375+ return ! empty ( $ source ->label ) ? $ source ->label : null ;
376+ },
377+ ),
378+ 'isCompound ' => array (
379+ 'type ' => 'Boolean ' ,
380+ 'description ' => __ ( 'Is tax compound? ' , 'wp-graphql-woocommerce ' ),
381+ 'resolve ' => function ( $ source ) {
382+ return ! empty ( $ source ->is_compound ) ? $ source ->is_compound : null ;
383+ },
384+ ),
385+ 'amount ' => array (
386+ 'type ' => 'String ' ,
387+ 'description ' => __ ( 'Tax amount ' , 'wp-graphql-woocommerce ' ),
388+ 'resolve ' => function ( $ source ) {
389+ return ! empty ( $ source ->amount ) ? \wc_graphql_price ( $ source ->amount ) : null ;
390+ },
391+ ),
392+ ),
393+ )
394+ );
395+ }
346396}
0 commit comments