Merge pull request #13118 from woocommerce/fix-12955

Fix type setting in API
This commit is contained in:
Claudio Sanches 2017-02-08 16:14:05 -02:00 committed by GitHub
commit 3f2f313161
1 changed files with 10 additions and 5 deletions

View File

@ -678,14 +678,19 @@ class WC_REST_Products_Controller extends WC_REST_Posts_Controller {
* @return WP_Error|stdClass $data Post object.
*/
protected function prepare_item_for_database( $request ) {
if ( isset( $request['id'] ) ) {
$product = wc_get_product( absint( $request['id'] ) );
} else {
$classname = WC_Product_Factory::get_classname_from_product_type( $request['type'] );
// Type is the most important part here because we need to be using the correct class and methods.
if ( isset( $request['type'] ) ) {
$classname = WC_Product_Factory::get_classname_from_product_type( $request['type'] );
if ( ! class_exists( $classname ) ) {
$classname = 'WC_Product_Simple';
}
$product = new $classname();
$product = new $classname( absint( $request['id'] ) );
} elseif ( isset( $request['id'] ) ) {
$product = wc_get_product( absint( $request['id'] ) );
} else {
$product = new WC_Product_Simple();
}
// Post title.