Skip to content

Commit

Permalink
Merge pull request #12 from nomasi/fix-for-product-specific-attributes
Browse files Browse the repository at this point in the history
Fix for product specific attributes
  • Loading branch information
nomasi authored Mar 9, 2020
2 parents 98782f6 + b3a2c8b commit 5e0c52f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
7 changes: 5 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
24 changes: 18 additions & 6 deletions sizeme-for-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -451,13 +451,15 @@ 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 ) {

$variation_meta = get_post_meta( $variation['variation_id'] );

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;
Expand All @@ -466,17 +468,27 @@ 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 ] ) ) {
$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;
}
}
}
}
}

return self::$attributes[ $product->get_id() ];
return ( isset( self::$attributes[$product->get_id()] ) ? self::$attributes[$product->get_id()] : NULL );
}


Expand Down

0 comments on commit 5e0c52f

Please sign in to comment.