Merge pull request #13339 from woocommerce/fix-13335

Edit context when duplicating skus
This commit is contained in:
Claudio Sanches 2017-02-24 16:07:17 -03:00 committed by GitHub
commit 5383349a0a
2 changed files with 5 additions and 5 deletions

View File

@ -118,8 +118,8 @@ class WC_Admin_Duplicate_Product {
$duplicate = clone $product;
$duplicate->set_id( 0 );
$duplicate->set_total_sales( 0 );
if ( '' !== $product->get_sku() ) {
$duplicate->set_sku( wc_product_generate_unique_sku( 0, $product->get_sku() ) );
if ( '' !== $product->get_sku( 'edit' ) ) {
$duplicate->set_sku( wc_product_generate_unique_sku( 0, $product->get_sku( 'edit' ) ) );
}
$duplicate->set_status( 'draft' );
@ -140,8 +140,8 @@ class WC_Admin_Duplicate_Product {
$child_duplicate->set_parent_id( $duplicate->get_id() );
$child_duplicate->set_id( 0 );
if ( '' !== $child->get_sku() ) {
$child_duplicate->set_sku( wc_product_generate_unique_sku( 0, $child->get_sku() ) );
if ( '' !== $child->get_sku( 'edit' ) ) {
$child_duplicate->set_sku( wc_product_generate_unique_sku( 0, $child->get_sku( 'edit' ) ) );
}
foreach ( $meta_to_exclude as $meta_key ) {

View File

@ -554,7 +554,7 @@ function wc_product_has_unique_sku( $product_id, $sku ) {
function wc_product_force_unique_sku( $product_id ) {
$product = wc_get_product( $product_id );
if ( $product && ( $current_sku = $product->get_sku() ) ) {
if ( $product && ( $current_sku = $product->get_sku( 'edit' ) ) ) {
try {
$new_sku = wc_product_generate_unique_sku( $product_id, $current_sku );