|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Defines the fields for manage product inventories. |
| 4 | + * |
| 5 | + * @package WPGraphQL\WooCommerce\Type\WPInterface |
| 6 | + * @since TBD |
| 7 | + */ |
| 8 | + |
| 9 | +namespace WPGraphQL\WooCommerce\Type\WPInterface; |
| 10 | + |
| 11 | +use WPGraphQL\WooCommerce\Core_Schema_Filters as Core; |
| 12 | + |
| 13 | +/** |
| 14 | + * Class Inventoried_Products |
| 15 | + */ |
| 16 | +class Inventoried_Products { |
| 17 | + /** |
| 18 | + * Registers the "InventoriedProducts" type |
| 19 | + * |
| 20 | + * @return void |
| 21 | + * @throws \Exception |
| 22 | + */ |
| 23 | + public static function register_interface(): void { |
| 24 | + register_graphql_interface_type( |
| 25 | + 'InventoriedProducts', |
| 26 | + [ |
| 27 | + 'description' => __( 'Products with stock information.', 'wp-graphql-woocommerce' ), |
| 28 | + 'interfaces' => [ 'Node' ], |
| 29 | + 'fields' => self::get_fields(), |
| 30 | + 'resolveType' => [ Core::class, 'resolve_product_type' ], |
| 31 | + ] |
| 32 | + ); |
| 33 | + } |
| 34 | + |
| 35 | + /** |
| 36 | + * Defines "InventoriedProducts" fields. |
| 37 | + * |
| 38 | + * @return array |
| 39 | + */ |
| 40 | + public static function get_fields() { |
| 41 | + return [ |
| 42 | + 'id' => [ |
| 43 | + 'type' => [ 'non_null' => 'ID' ], |
| 44 | + 'description' => __( 'Product or variation global ID', 'wp-graphql-woocommerce' ), |
| 45 | + ], |
| 46 | + 'databaseId' => [ |
| 47 | + 'type' => [ 'non_null' => 'Int' ], |
| 48 | + 'description' => __( 'Product or variation ID', 'wp-graphql-woocommerce' ), |
| 49 | + ], |
| 50 | + 'manageStock' => [ |
| 51 | + 'type' => 'Boolean', |
| 52 | + 'description' => __( 'If product manage stock', 'wp-graphql-woocommerce' ), |
| 53 | + ], |
| 54 | + 'stockQuantity' => [ |
| 55 | + 'type' => 'Int', |
| 56 | + 'description' => __( 'Number of items available for sale', 'wp-graphql-woocommerce' ), |
| 57 | + ], |
| 58 | + 'backorders' => [ |
| 59 | + 'type' => 'BackordersEnum', |
| 60 | + 'description' => __( 'Product backorders status', 'wp-graphql-woocommerce' ), |
| 61 | + ], |
| 62 | + 'soldIndividually' => [ |
| 63 | + 'type' => 'Boolean', |
| 64 | + 'description' => __( 'If should be sold individually', 'wp-graphql-woocommerce' ), |
| 65 | + ], |
| 66 | + 'backordersAllowed' => [ |
| 67 | + 'type' => 'Boolean', |
| 68 | + 'description' => __( 'Can product be backordered?', 'wp-graphql-woocommerce' ), |
| 69 | + ], |
| 70 | + 'stockStatus' => [ |
| 71 | + 'type' => 'StockStatusEnum', |
| 72 | + 'description' => __( 'Product stock status', 'wp-graphql-woocommerce' ), |
| 73 | + ], |
| 74 | + ]; |
| 75 | + } |
| 76 | +} |
0 commit comments