Skip to content

Commit

Permalink
Merge pull request #17 from skyverge/release-2.3.5
Browse files Browse the repository at this point in the history
Release v2.3.5
  • Loading branch information
ChaseWiseman authored Jun 12, 2019
2 parents 613f18e + d61a29d commit 55c7f8a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tags: woocommerce, sku, product sku, sku generator
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_xclick&business=paypal@skyverge.com&item_name=Donation+for+WooCommerce+SKU+Generator
Requires at least: 4.4
Tested up to: 4.9.7
Stable Tag: 2.3.4
Stable Tag: 2.3.5-dev.1
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html

Expand Down Expand Up @@ -154,6 +154,10 @@ add_filter( 'wc_sku_generator_force_attribute_sorting', '__return_true' );

== Changelog ==

= 2019.nn.nn - version 2.3.5-dev.1 =
* Tweak - Ensure generated SKUs are unique before saving
* Fix - Prevent errors when saving invalid SKUs

= 2018.07.17 - version 2.3.4 =
* Misc - Remove support for WooCommerce 2.5

Expand Down
32 changes: 25 additions & 7 deletions woocommerce-product-sku-generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* Text Domain: woocommerce-product-sku-generator
* Domain Path: /i18n/languages/
*
* Copyright: (c) 2014-2018 SkyVerge, Inc. (info@skyverge.com)
* Copyright: (c) 2014-2019 SkyVerge, Inc. (info@skyverge.com)
*
* License: GNU General Public License v3.0
* License URI: http://www.gnu.org/licenses/gpl-3.0.html
*
* @package WC-Product-SKU-Generator
* @author SkyVerge
* @category Admin
* @copyright Copyright (c) 2014-2018, SkyVerge, Inc.
* @copyright Copyright (c) 2014-2019, SkyVerge, Inc.
* @license http://www.gnu.org/licenses/gpl-3.0.html GNU General Public License v3.0
*
* WC requires at least: 2.6.14
Expand Down Expand Up @@ -63,7 +63,7 @@ class WC_SKU_Generator {


/** plugin version number */
const VERSION = '2.3.4';
const VERSION = '2.3.5-dev.1';

/** required WooCommerce version number */
const MIN_WOOCOMMERCE_VERSION = '2.6.14';
Expand Down Expand Up @@ -421,9 +421,18 @@ public function maybe_save_sku( $product ) {
if ( 'never' !== get_option( 'wc_sku_generator_simple' ) ) {

if ( self::is_wc_version_gte_3_0() ) {
$product->set_sku( $product_sku );
$product->save();

$product_sku = wc_product_generate_unique_sku( $product->get_id(), $product_sku );

try {

$product->set_sku( $product_sku );
$product->save();

} catch ( WC_Data_Exception $exception ) {}

} else {

update_post_meta( $product->get_id(), '_sku', $product_sku );
}
}
Expand Down Expand Up @@ -461,9 +470,18 @@ protected function maybe_save_variation_sku( $variation_id, $parent, $parent_sku
$sku = apply_filters( 'wc_sku_generator_variation_sku_format', $sku, $parent_sku, $variation_sku );

if ( self::is_wc_version_gte_3_0() ) {
$variation->set_sku( $sku );
$variation->save();

try {

$sku = wc_product_generate_unique_sku( $variation_id, $sku );

$variation->set_sku( $sku );
$variation->save();

} catch ( WC_Data_Exception $exception ) {}

} else {

update_post_meta( $variation_id, '_sku', $sku );
}
}
Expand Down

0 comments on commit 55c7f8a

Please sign in to comment.