Let product CRUD handle terms IDs

This commit is contained in:
Claudio Sanches 2017-03-03 16:21:27 -03:00
parent a4b7cc5f0d
commit 8d28e966c4
4 changed files with 4 additions and 10 deletions

View File

@ -1134,7 +1134,6 @@ class WC_REST_Products_Controller extends WC_REST_Legacy_Products_Controller {
*/
protected function save_taxonomy_terms( $product, $terms, $taxonomy = 'cat' ) {
$term_ids = wp_list_pluck( $terms, 'id' );
$term_ids = array_unique( array_map( 'intval', $term_ids ) );
if ( 'cat' === $taxonomy ) {
$product->set_category_ids( $term_ids );

View File

@ -1182,14 +1182,12 @@ class WC_API_Products extends WC_API_Resource {
// Product categories
if ( isset( $data['categories'] ) && is_array( $data['categories'] ) ) {
$term_ids = array_unique( array_map( 'intval', $data['categories'] ) );
$product->set_category_ids( $term_ids );
$product->set_category_ids( $data['categories'] );
}
// Product tags
if ( isset( $data['tags'] ) && is_array( $data['tags'] ) ) {
$term_ids = array_unique( array_map( 'intval', $data['tags'] ) );
$product->set_tag_ids( $term_ids );
$product->set_tag_ids( $data['tags'] );
}
// Downloadable

View File

@ -1671,14 +1671,12 @@ class WC_API_Products extends WC_API_Resource {
// Product categories.
if ( isset( $data['categories'] ) && is_array( $data['categories'] ) ) {
$term_ids = array_unique( array_map( 'intval', $data['categories'] ) );
$product->set_category_ids( $term_ids );
$product->set_category_ids( $data['categories'] );
}
// Product tags.
if ( isset( $data['tags'] ) && is_array( $data['tags'] ) ) {
$term_ids = array_unique( array_map( 'intval', $data['tags'] ) );
$product->set_tag_ids( $term_ids );
$product->set_tag_ids( $data['tags'] );
}
// Downloadable.

View File

@ -982,7 +982,6 @@ class WC_REST_Products_V1_Controller extends WC_REST_Posts_Controller {
*/
protected function save_taxonomy_terms( $product, $terms, $taxonomy = 'cat' ) {
$term_ids = wp_list_pluck( $terms, 'id' );
$term_ids = array_unique( array_map( 'intval', $term_ids ) );
if ( 'cat' === $taxonomy ) {
$product->set_category_ids( $term_ids );