-
-
Notifications
You must be signed in to change notification settings - Fork 140
Automatically get and set data from the specified product ID #947
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -333,18 +333,21 @@ protected static function map_input_to_item( &$item, $input, $type ) { | |||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
// Calculate to subtotal/total for line items. | ||||||||||
if ( isset( $args['quantity'] ) ) { | ||||||||||
// If subtotal or total is not provided, calculate it based on the product price and quantity. | ||||||||||
// If name is not provided, use the actual product name. | ||||||||||
// ONLY IF $args is not empty. | ||||||||||
if ( ! empty( $args ) && ( empty( $args['subtotal'] ) || empty( $args['total'] ) || empty( $args['name'] ) ) ) { | ||||||||||
$product = ( ! empty( $item['product_id'] ) ) | ||||||||||
? wc_get_product( $item['product_id'] ) | ||||||||||
: wc_get_product( self::get_product_id( $args ) ); | ||||||||||
if ( ! is_object( $product ) ) { | ||||||||||
throw new \Exception( __( 'Failed to retrieve product connected to order item.', 'wp-graphql-woocommerce' ) ); | ||||||||||
} | ||||||||||
|
||||||||||
$total = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ] ); | ||||||||||
$total = wc_get_price_excluding_tax( $product, [ 'qty' => $args['quantity'] ?? 1 ] ); | ||||||||||
$args['subtotal'] = ! empty( $args['subtotal'] ) ? $args['subtotal'] : $total; | ||||||||||
$args['total'] = ! empty( $args['total'] ) ? $args['total'] : $total; | ||||||||||
$args['name'] = ! empty( $args['name'] ) ? $args['name'] : $product->get_name(); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent use of
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||||||
} | ||||||||||
|
||||||||||
// Set item props. | ||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition uses
empty()
which will treat '0' values as empty. For subtotal and total, '0' is a valid value that should not trigger automatic calculation. Use!isset()
or explicit null checks instead.Copilot uses AI. Check for mistakes.