From ad487ed8faa5684ab47b555877359fe520b1103e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alda=20Vigd=C3=ADs=20Skarph=C3=A9=C3=B0insd=C3=B3ttir?= Date: Wed, 10 Jul 2024 14:00:32 +0200 Subject: [PATCH] Fixing a bug that prevented products with a single attribute to be read in properly --- src/Import/ProductVariations.php | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/Import/ProductVariations.php b/src/Import/ProductVariations.php index 8952e42..a9e1d7d 100644 --- a/src/Import/ProductVariations.php +++ b/src/Import/ProductVariations.php @@ -352,19 +352,24 @@ public static function parse_variations_json( $variation_json ): array { $variations = array(); foreach ( $variation_json as $vj ) { + $variation = array(); $code = $vj->CODE; $description = $vj->DESCRIPTION; - $attribute_1 = $vj->SUBGROUP1; - $attribute_2 = $vj->SUBGROUP2; - $variations[ $code ] = (object) array( + $variations[ $code ] = array( 'code' => $code, 'description' => $description, - 'attributes' => array( - $attribute_1 => self::get_attribute( $attribute_1 ), - $attribute_2 => self::get_attribute( $attribute_2 ), - ), ); + + if ( property_exists( $vj, 'SUBGROUP1' ) ) { + $variation['attributes'][ $vj->SUBGROUP1 ] = self::get_attribute( $vj->SUBGROUP1 ); + } + + if ( property_exists( $vj, 'SUBGROUP2' ) ) { + $variation['attributes'][ $vj->SUBGROUP2 ] = self::get_attribute( $vj->SUBGROUP2 ); + } + + $variations[ $code ] = (object) $variation; } return $variations;