Fixed deprecated `set_stock` notice

This commit is contained in:
Claudio Sanches 2017-05-26 18:42:07 -03:00
parent 1d394f41a7
commit 780ce1a4e6
2 changed files with 23 additions and 10 deletions

View File

@ -408,7 +408,7 @@ class WC_Product_CSV_Importer_Controller {
'date_on_sale_to' => __( 'Date sale price ends', 'woocommerce' ), 'date_on_sale_to' => __( 'Date sale price ends', 'woocommerce' ),
'tax_status' => __( 'Tax Class', 'woocommerce' ), 'tax_status' => __( 'Tax Class', 'woocommerce' ),
'stock_status' => __( 'In stock?', 'woocommerce' ), 'stock_status' => __( 'In stock?', 'woocommerce' ),
'stock' => __( 'Stock', 'woocommerce' ), 'stock_quantity' => __( 'Stock', 'woocommerce' ),
'backorders' => __( 'Backorders allowed?', 'woocommerce' ), 'backorders' => __( 'Backorders allowed?', 'woocommerce' ),
'sold_individually' => __( 'Sold individually?', 'woocommerce' ), 'sold_individually' => __( 'Sold individually?', 'woocommerce' ),
'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ), 'weight' => sprintf( __( 'Weight (%s)', 'woocommerce' ), $weight_unit ),
@ -531,7 +531,7 @@ class WC_Product_CSV_Importer_Controller {
'purchase_note' => __( 'Purchase Note', 'woocommerce' ), 'purchase_note' => __( 'Purchase Note', 'woocommerce' ),
'sale_price' => __( 'Sale Price', 'woocommerce' ), 'sale_price' => __( 'Sale Price', 'woocommerce' ),
'regular_price' => __( 'Regular Price', 'woocommerce' ), 'regular_price' => __( 'Regular Price', 'woocommerce' ),
'stock' => __( 'Stock', 'woocommerce' ), 'stock_quantity' => __( 'Stock', 'woocommerce' ),
'category_ids' => __( 'Categories', 'woocommerce' ), 'category_ids' => __( 'Categories', 'woocommerce' ),
'tag_ids' => __( 'Tags', 'woocommerce' ), 'tag_ids' => __( 'Tags', 'woocommerce' ),
'shipping_class_id' => __( 'Shipping Class', 'woocommerce' ), 'shipping_class_id' => __( 'Shipping Class', 'woocommerce' ),

View File

@ -134,7 +134,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
/** /**
* Prepare a single product for create or update. * Prepare a single product for create or update.
* *
* @param array $data Row data. * @param array $data Item data.
* @return WC_Product|WP_Error * @return WC_Product|WP_Error
*/ */
protected function get_product_object( $data ) { protected function get_product_object( $data ) {
@ -192,7 +192,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
unset( $data['manage_stock'], $data['stock_status'], $data['backorders'] ); unset( $data['manage_stock'], $data['stock_status'], $data['backorders'] );
} }
$result = $object->set_props( array_diff_key( $data, array_flip( array( 'meta_data', 'raw_image_id', 'raw_gallery_image_ids', 'raw_attributes' ) ) ) ); $result = $object->set_props( array_diff_key( $data, array_flip( array( 'meta_data', 'raw_image_id', 'raw_gallery_image_ids', 'raw_attributes', 'stock_quantity' ) ) ) );
if ( is_wp_error( $result ) ) { if ( is_wp_error( $result ) ) {
throw new Exception( $result->get_error_message() ); throw new Exception( $result->get_error_message() );
@ -205,6 +205,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
} }
$this->set_image_data( $object, $data ); $this->set_image_data( $object, $data );
$this->set_stock_quantity( $object, $data );
$this->set_meta_data( $object, $data ); $this->set_meta_data( $object, $data );
if ( 'importing' === $object->get_status() ) { if ( 'importing' === $object->get_status() ) {
@ -226,8 +227,8 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
/** /**
* Convert raw image URLs to IDs and set. * Convert raw image URLs to IDs and set.
* *
* @param WC_Product $product * @param WC_Product $product Product instance.
* @param array $data * @param array $data Item data.
*/ */
protected function set_image_data( &$product, $data ) { protected function set_image_data( &$product, $data ) {
// Image URLs need converting to IDs before inserting. // Image URLs need converting to IDs before inserting.
@ -246,11 +247,23 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
} }
} }
/**
* Set stock quantity.
*
* @param WC_Product $product Product instance.
* @param array $data Item data.
*/
protected function set_stock_quantity( &$product, $data ) {
if ( isset( $data['stock_quantity'] ) && $product->get_manage_stock() ) {
wc_update_product_stock( $product, $data['stock_quantity'] );
}
}
/** /**
* Append meta data. * Append meta data.
* *
* @param WC_Product $product * @param WC_Product $product Product instance.
* @param array $data * @param array $data Item data.
*/ */
protected function set_meta_data( &$product, $data ) { protected function set_meta_data( &$product, $data ) {
if ( isset( $data['meta_data'] ) ) { if ( isset( $data['meta_data'] ) ) {
@ -264,7 +277,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
* Set product data. * Set product data.
* *
* @param WC_Product $product Product instance. * @param WC_Product $product Product instance.
* @param array $data Row data. * @param array $data Item data.
* *
* @return WC_Product|WP_Error * @return WC_Product|WP_Error
* @throws Exception * @throws Exception
@ -352,7 +365,7 @@ abstract class WC_Product_Importer implements WC_Importer_Interface {
* Set variation data. * Set variation data.
* *
* @param WC_Product $variation Product instance. * @param WC_Product $variation Product instance.
* @param array $data Row data. * @param array $data Item data.
* *
* @return WC_Product|WP_Error * @return WC_Product|WP_Error
* @throws Exception * @throws Exception