mirror of
https://github.com/wp-graphql/wp-graphql-woocommerce.git
synced 2026-08-14 12:53:44 +02:00
Automatically get and set data from the specified product ID (#947)
* always calculate; default quantity of 1 * fill the name; complete order item data * dont introduce new requirement; leave as is * fix: auto-fill line item data from product, add format arg to LineItem pricing fields, fix isPaid check (#946) * devops: upload coverage XML and JSON as debug artifacts after Coveralls push * chore: Lintercompliances met --------- Co-authored-by: Geoff Taylor <geoff@axistaylor.com>
This commit is contained in:
co-authored by
Geoff Taylor
parent
974393aeeb
commit
5792d76344
@@ -246,10 +246,10 @@ class OrderItemQueriesTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGrap
|
||||
variationId
|
||||
quantity
|
||||
taxClass
|
||||
subtotal
|
||||
subtotalTax
|
||||
total
|
||||
totalTax
|
||||
subtotal(format: RAW)
|
||||
subtotalTax(format: RAW)
|
||||
total(format: RAW)
|
||||
totalTax(format: RAW)
|
||||
itemDownloads {
|
||||
downloadId
|
||||
}
|
||||
|
||||
@@ -180,10 +180,10 @@ class OrderMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
|
||||
variationId
|
||||
quantity
|
||||
taxClass
|
||||
subtotal
|
||||
subtotalTax
|
||||
total
|
||||
totalTax
|
||||
subtotal(format: RAW)
|
||||
subtotalTax(format: RAW)
|
||||
total(format: RAW)
|
||||
totalTax(format: RAW)
|
||||
taxStatus
|
||||
product {
|
||||
node {
|
||||
@@ -1413,4 +1413,66 @@ class OrderMutationsTest extends \Tests\WPGraphQL\WooCommerce\TestCase\WooGraphQ
|
||||
'Stock should remain at 45 when status is explicitly set alongside isPaid.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that createOrder auto-fills line item name, subtotal, and total
|
||||
* when only productId is provided.
|
||||
*
|
||||
* @see https://github.com/wp-graphql/wp-graphql-woocommerce/issues/946
|
||||
*/
|
||||
public function testCreateOrderWithProductIdOnlyLineItems() {
|
||||
$product_id = $this->factory->product->createSimple(
|
||||
[
|
||||
'regular_price' => '25',
|
||||
'name' => 'Test Widget',
|
||||
]
|
||||
);
|
||||
|
||||
$this->loginAsShopManager();
|
||||
|
||||
$query = '
|
||||
mutation ($input: CreateOrderInput!) {
|
||||
createOrder(input: $input) {
|
||||
order {
|
||||
lineItems {
|
||||
nodes {
|
||||
productId
|
||||
quantity
|
||||
total(format: RAW)
|
||||
subtotal(format: RAW)
|
||||
product {
|
||||
node {
|
||||
... on SimpleProduct {
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
';
|
||||
|
||||
$variables = [
|
||||
'input' => [
|
||||
'clientMutationId' => 'create-order-minimal',
|
||||
'paymentMethod' => 'bacs',
|
||||
'lineItems' => [
|
||||
[ 'productId' => $product_id ],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$response = $this->graphql( compact( 'query', 'variables' ) );
|
||||
$expected = [
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.productId', $product_id ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.quantity', 1 ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.total', '25' ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.subtotal', '25' ),
|
||||
$this->expectedField( 'createOrder.order.lineItems.nodes.0.product.node.name', 'Test Widget' ),
|
||||
];
|
||||
|
||||
$this->assertQuerySuccessful( $response, $expected );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user