Skip to content

Commit

Permalink
Changed wc_get_product_classname function name to wc_get_product_object
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiosanches committed Dec 4, 2019
1 parent ba0773d commit 8033d57
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public static function save_variations( $post_id, $post ) {
continue;
}
$variation_id = absint( $_POST['variable_post_id'][ $i ] );
$variation = wc_get_product_classname( 'variation', $variation_id );
$variation = wc_get_product_object( 'variation', $variation_id );
$stock = null;

// Handle stock changes.
Expand Down
4 changes: 2 additions & 2 deletions includes/class-wc-ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,8 @@ public static function add_variation() {
$product_id = intval( $_POST['post_id'] );
$post = get_post( $product_id ); // phpcs:ignore
$loop = intval( $_POST['loop'] );
$product_object = wc_get_product_classname( 'variable', $product_id ); // Forces type to variable in case product is unsaved.
$variation_object = wc_get_product_classname( 'variation' );
$product_object = wc_get_product_object( 'variable', $product_id ); // Forces type to variable in case product is unsaved.
$variation_object = wc_get_product_object( 'variation' );
$variation_object->set_parent_id( $product_id );
$variation_object->set_attributes( array_fill_keys( array_map( 'sanitize_title', array_keys( $product_object->get_variation_attributes() ) ), '' ) );
$variation_id = $variation_object->save();
Expand Down
2 changes: 1 addition & 1 deletion includes/class-wc-shortcodes.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ public static function product_page( $atts ) {
// Check if sku is a variation.
if ( isset( $atts['sku'] ) && $single_product->have_posts() && 'product_variation' === $single_product->post->post_type ) {

$variation = wc_get_product_classname( 'variation', $single_product->post->ID );
$variation = wc_get_product_object( 'variation', $single_product->post->ID );
$attributes = $variation->get_attributes();

// Set preselected id to be used by JS to provide context.
Expand Down
2 changes: 1 addition & 1 deletion includes/data-stores/class-wc-product-data-store-cpt.php
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ public function create_all_product_variations( $product, $limit = -1 ) {
if ( in_array( $possible_attribute, $existing_attributes ) ) { // phpcs:ignore WordPress.PHP.StrictInArray.MissingTrueStrict
continue;
}
$variation = wc_get_product_classname( 'variation' );
$variation = wc_get_product_object( 'variation' );
$variation->set_parent_id( $product->get_id() );
$variation->set_attributes( $possible_attribute );
$variation_id = $variation->save();
Expand Down
4 changes: 2 additions & 2 deletions includes/import/abstract-wc-product-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected function get_product_object( $data ) {
return new WP_Error( 'woocommerce_product_importer_invalid_type', __( 'Invalid product type.', 'woocommerce' ), array( 'status' => 401 ) );
}

$product = wc_get_product_classname( $data['type'], $id );
$product = wc_get_product_object( $data['type'], $id );
} elseif ( ! empty( $data['id'] ) ) {
$product = wc_get_product( $id );

Expand All @@ -189,7 +189,7 @@ protected function get_product_object( $data ) {
);
}
} else {
$product = wc_get_product_classname( 'simple', $id );
$product = wc_get_product_object( 'simple', $id );
}

return apply_filters( 'woocommerce_product_import_get_product_object', $product, $data );
Expand Down
6 changes: 3 additions & 3 deletions includes/import/class-wc-product-csv-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function parse_relative_field( $value ) {

// If we're not updating existing posts, we may need a placeholder product to map to.
if ( ! $this->params['update_existing'] ) {
$product = wc_get_product_classname( 'simple' );
$product = wc_get_product_object( 'simple' );
$product->set_name( 'Import placeholder for ' . $id );
$product->set_status( 'importing' );
$product->add_meta_data( '_original_id', $id, true );
Expand All @@ -200,7 +200,7 @@ public function parse_relative_field( $value ) {
}

try {
$product = wc_get_product_classname( 'simple' );
$product = wc_get_product_object( 'simple' );
$product->set_name( 'Import placeholder for ' . $value );
$product->set_status( 'importing' );
$product->set_sku( $value );
Expand Down Expand Up @@ -254,7 +254,7 @@ public function parse_id_field( $value ) {
return $id_from_sku;
}

$product = wc_get_product_classname( 'simple' );
$product = wc_get_product_object( 'simple' );
$product->set_name( 'Import placeholder for ' . $id );
$product->set_status( 'importing' );
$product->add_meta_data( '_original_id', $id, true );
Expand Down
6 changes: 3 additions & 3 deletions includes/wc-product-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ function wc_get_product( $the_product = false, $deprecated = array() ) {
}

/**
* Get product class name.
* Get a product object.
*
* @see WC_Product_Factory::get_product_classname
* @since 3.9.0
* @param string $product_type Product type.
* @param string $product_type Product type. If used an invalid type a WC_Product_Simple instance will be returned.
* @param int $product_id Product ID.
* @return WC_Product
*/
function wc_get_product_classname( $product_type, $product_id = 0 ) {
function wc_get_product_object( $product_type, $product_id = 0 ) {
$classname = WC_Product_Factory::get_product_classname( $product_id, $product_type );

return new $classname( $product_id );
Expand Down
16 changes: 8 additions & 8 deletions tests/unit-tests/product/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,19 @@ public function test_wc_get_product() {
}

/**
* Test wc_get_product_classname().
* Test wc_get_product_object().
*
* @since 3.9.0
*/
public function test_wc_get_product_classname() {
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_classname( 'simple' ) );
$this->assertInstanceOf( 'WC_Product_Grouped', wc_get_product_classname( 'grouped' ) );
$this->assertInstanceOf( 'WC_Product_External', wc_get_product_classname( 'external' ) );
$this->assertInstanceOf( 'WC_Product_Variable', wc_get_product_classname( 'variable' ) );
$this->assertInstanceOf( 'WC_Product_Variation', wc_get_product_classname( 'variation' ) );
public function test_wc_get_product_object() {
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_object( 'simple' ) );
$this->assertInstanceOf( 'WC_Product_Grouped', wc_get_product_object( 'grouped' ) );
$this->assertInstanceOf( 'WC_Product_External', wc_get_product_object( 'external' ) );
$this->assertInstanceOf( 'WC_Product_Variable', wc_get_product_object( 'variable' ) );
$this->assertInstanceOf( 'WC_Product_Variation', wc_get_product_object( 'variation' ) );

// Test incorrect type.
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_classname( 'foo+bar' ), 10 );
$this->assertInstanceOf( 'WC_Product_Simple', wc_get_product_object( 'foo+bar' ) );
}

/**
Expand Down

0 comments on commit 8033d57

Please sign in to comment.