From 721cac3474b14a63206979f9ee6586dc5f4c98b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20K=C3=B6n=C3=B6nen?= Date: Tue, 18 Feb 2020 11:06:30 +0200 Subject: [PATCH 1/3] Version hike --- readme.txt | 7 +++++-- sizeme-for-woocommerce.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/readme.txt b/readme.txt index e0d13ae..00fb05a 100644 --- a/readme.txt +++ b/readme.txt @@ -3,10 +3,10 @@ Contributors: sizeme Tags: sizeme, measurements, size guide, size recommendations Requires at least: 3.8 Tested up to: 5.3.2 -Stable tag: 2.0.8 +Stable tag: 2.0.9 Requires PHP: 5.2.4 WC requires at least: 2.5 -WC tested up to: 3.8.1 +WC tested up to: 3.9.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html @@ -83,6 +83,9 @@ To install and take into use the SizeMe for WooCommerce plugin, follow the instr == Changelog == += 2.0.9 = +* Fixed sizeme_product object if the product's attribute is not global (product-specific) + = 2.0.8 = * Fixed sizeme_product object (used to communicate with our product database) creation when the product doesn't have proper SKU's diff --git a/sizeme-for-woocommerce.php b/sizeme-for-woocommerce.php index c69be88..bf5a20e 100644 --- a/sizeme-for-woocommerce.php +++ b/sizeme-for-woocommerce.php @@ -9,7 +9,7 @@ * @wordpress-plugin * Plugin Name: SizeMe for WooCommerce * Description: SizeMe is a web store plugin that enables your consumers to input their measurements and get personalised fit recommendations based on actual product data. - * Version: 2.0.8 + * Version: 2.0.9 * Author: SizeMe Ltd * Author URI: https://www.sizeme.com/ * Text Domain: sizeme @@ -50,7 +50,7 @@ class WC_SizeMe_for_WooCommerce { * * @var string VERSION The plugin version. */ - const VERSION = '2.0.8'; + const VERSION = '2.0.9'; /** * Minimum WordPress version this plugin works with, used for dependency checks. From ca627af7f7cb68d0b70417fc4ed90287d17f21a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20K=C3=B6n=C3=B6nen?= Date: Tue, 18 Feb 2020 21:38:06 +0200 Subject: [PATCH 2/3] Fix for sizeme_product if there is no global size attribute * is not perfect, as it only uses the first product attribute --- sizeme-for-woocommerce.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/sizeme-for-woocommerce.php b/sizeme-for-woocommerce.php index bf5a20e..c88d548 100644 --- a/sizeme-for-woocommerce.php +++ b/sizeme-for-woocommerce.php @@ -458,6 +458,7 @@ protected function load_skus( WC_Product_Variable $product ) { if ( is_array( $variation_meta ) && count( $variation_meta ) > 0 ) { $size_attribute = $this->get_size_attribute( $product ); + foreach ( $variation_meta as $attribute => $value ) { if ( ! is_array( $value ) || ! isset( $value[0] ) ) { continue; @@ -466,17 +467,25 @@ protected function load_skus( WC_Product_Variable $product ) { if ( isset( $variation['attributes'][ 'attribute_pa_' . $size_attribute ] ) ) { // The attribute code value here is the attribute_pa_size, which is "small","extra-small","large", or whatever the slug is. $attribute_code = $variation['attributes'][ 'attribute_pa_' . $size_attribute ]; - if ( ! isset( self::$attributes[ $product->get_id() ][ $attribute_code ] ) ) { - self::$attributes[ $product->get_id() ][ $attribute_code ] = (string)($variation[ 'sku' ] ? $variation[ 'sku' ] : substr($this->get_client_key(), 0, 16).'-'.$variation[ 'variation_id' ]); + } else { + // the SizeMe global size attribute is not present for this product, try something else + $first_variation = reset( $variations ); + if ( isset( $first_variation['attributes'] ) ) { + $attribute_key = key( $first_variation['attributes'] ); + $attribute_code = $variation['attributes'][ $attribute_key ]; + } else { + continue; } } - + if ( ! isset( self::$attributes[ $product->get_id() ][ $attribute_code ] ) ) { + self::$attributes[ $product->get_id() ][ $attribute_code ] = (string)($variation[ 'sku' ] ? $variation[ 'sku' ] : substr($this->get_client_key(), 0, 16).'-'.$variation[ 'variation_id' ]); + } } } } } - return self::$attributes[ $product->get_id() ]; + return ( isset( self::$attributes[$product->get_id()] ) ? self::$attributes[$product->get_id()] : NULL ); } From b3a2c8be4822e5e3e611ddbb76c4c09688d8f275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20K=C3=B6n=C3=B6nen?= Date: Tue, 18 Feb 2020 22:04:40 +0200 Subject: [PATCH 3/3] Fix for missing (or strangely equal) skus in variations --- sizeme-for-woocommerce.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sizeme-for-woocommerce.php b/sizeme-for-woocommerce.php index c88d548..bb2a5b1 100644 --- a/sizeme-for-woocommerce.php +++ b/sizeme-for-woocommerce.php @@ -451,6 +451,7 @@ protected function load_skus( WC_Product_Variable $product ) { if ( empty( self::$attributes[ $product->get_id() ] ) ) { $variations = $product->get_available_variations(); + $parent_sku = $product->get_sku(); foreach ( $variations as $variation ) { @@ -478,7 +479,9 @@ protected function load_skus( WC_Product_Variable $product ) { } } if ( ! isset( self::$attributes[ $product->get_id() ][ $attribute_code ] ) ) { - self::$attributes[ $product->get_id() ][ $attribute_code ] = (string)($variation[ 'sku' ] ? $variation[ 'sku' ] : substr($this->get_client_key(), 0, 16).'-'.$variation[ 'variation_id' ]); + $attribute_value = (string)$variation[ 'sku' ]; + if ( (!$variation[ 'sku' ]) || ( $variation[ 'sku' ] === $parent_sku ) ) $attribute_value = substr($this->get_client_key(), 0, 16).'-'.$variation[ 'variation_id' ]; + self::$attributes[ $product->get_id() ][ $attribute_code ] = $attribute_value; } } }