[API] Added parent_id in products endpoint, closes #6786

This commit is contained in:
Claudio Sanches 2014-12-10 16:28:30 -02:00
parent 130ddb2b56
commit 53b1c66427
2 changed files with 7 additions and 0 deletions

View File

@ -567,6 +567,7 @@ class WC_API_Products extends WC_API_Resource {
'related_ids' => array_map( 'absint', array_values( $product->get_related() ) ), 'related_ids' => array_map( 'absint', array_values( $product->get_related() ) ),
'upsell_ids' => array_map( 'absint', $product->get_upsells() ), 'upsell_ids' => array_map( 'absint', $product->get_upsells() ),
'cross_sell_ids' => array_map( 'absint', $product->get_cross_sells() ), 'cross_sell_ids' => array_map( 'absint', $product->get_cross_sells() ),
'parent_id' => $product->post->post_parent,
'categories' => wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ), 'categories' => wp_get_post_terms( $product->id, 'product_cat', array( 'fields' => 'names' ) ),
'tags' => wp_get_post_terms( $product->id, 'product_tag', array( 'fields' => 'names' ) ), 'tags' => wp_get_post_terms( $product->id, 'product_tag', array( 'fields' => 'names' ) ),
'images' => $this->get_images( $product ), 'images' => $this->get_images( $product ),
@ -871,6 +872,11 @@ class WC_API_Products extends WC_API_Resource {
} }
} }
// Product parent ID for groups
if ( isset( $data['parent_id'] ) ) {
wp_update_post( array( 'ID' => $id, 'post_parent' => absint( $data['parent_id'] ) ) );
}
// Update parent if grouped so price sorting works and stays in sync with the cheapest child // Update parent if grouped so price sorting works and stays in sync with the cheapest child
$_product = wc_get_product( $id ); $_product = wc_get_product( $id );
if ( $_product->post->post_parent > 0 || $product_type == 'grouped' ) { if ( $_product->post->post_parent > 0 || $product_type == 'grouped' ) {

View File

@ -162,6 +162,7 @@ Yes you can! Join in on our [GitHub repository](http://github.com/woothemes/wooc
* Tweak - Added 'stupidtable' script to allow order item sorting on the order screen (by name, cost, qty). * Tweak - Added 'stupidtable' script to allow order item sorting on the order screen (by name, cost, qty).
* Tweak - In the cart, add variation selected data to the permalink. * Tweak - In the cart, add variation selected data to the permalink.
* Dev - API - Look up product by sku. * Dev - API - Look up product by sku.
* Dev - API - New parent_id param for products API.
* Dev - Made template debug mode set WC_TEMPLATE_DEBUG_MODE constant and remove all overrides for all template loading functions. * Dev - Made template debug mode set WC_TEMPLATE_DEBUG_MODE constant and remove all overrides for all template loading functions.
* Dev - Switched to .scss from .less for all styles. * Dev - Switched to .scss from .less for all styles.
* Dev - Included bourbon for scss mixins. * Dev - Included bourbon for scss mixins.