Plugin Directory

Changeset 3173481


Ignore:
Timestamp:
10/22/2024 09:19:53 AM (5 months ago)
Author:
printess
Message:

Fixed broken variant handling during saving of designs while not being logged in (variant settings got lost during the login process when saving a design)

Location:
printess-editor/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • printess-editor/trunk/printess.php

    r3172716 r3173481  
    55 * Plugin URI: https://printess.com/kb/integrations/woo-commerce/index.html
    66 * Developer: Bastian Kröger ([email protected]); Alexander Oser ([email protected])
    7  * Version: 1.6.26
     7 * Version: 1.6.27
    88 * Author: Printess
    99 * Author URI: https://printess.com
     
    1313 * Requires PHP: 8.1
    1414 *
    15  * Woo: 10000:923988dfsfhsf8429842384wdff234sfd
     15 * Woo: 10000:923989dfsfhsf8429842384wdff234sfd
    1616 * WC requires at least: 5.8
    1717 * WC tested up to: 9.3.3
     
    41554155}
    41564156
     4157/***
     4158 * Returns a lookup for product option names and the correponding slug.
     4159 * @param mixed $product The woocmmerce product object (wp post).
     4160 *
     4161 * @return array Associative array that can be used as lookup for product option name -> slug
     4162 */
     4163function printess_get_product_options_and_slugs($product) {
     4164    $productAttributes = printess_get_product_attributes( $product );
     4165    $ret = array();
     4166
     4167    foreach ( $product->get_attributes() as $key => $attribute ) {
     4168        if(is_string($attribute)) {
     4169            if(array_key_exists($key, $productAttributes) ) {
     4170                $ret[$attribute] = $key;
     4171            }
     4172        } else {
     4173            if(method_exists($attribute, "get_data")) {
     4174                $data = $attribute->get_data();
     4175
     4176                if(array_key_exists("name", $data)) {
     4177                    $ret[$data["name"]] = $key;
     4178                }
     4179            }
     4180        }
     4181    }
     4182
     4183    return $ret;
     4184}
     4185
    41574186/**
    41584187 * Saves a design after login in case the user has not been logged in before
     
    41964225                printess_unexpire_save_token( $save_token, printess_create_new_unexpiration_date() );
    41974226
    4198                 $design_id = $repo->add_design( $user_id, $save_token, $thumbnail_url, intval( '' . $product_id ), $product->get_data()['name'], $display_name, json_decode( stripslashes( $options ), true ) );
     4227                $product_options = json_decode( stripslashes( $options ), true );
     4228                $product_attributes = printess_get_product_options_and_slugs($product);
     4229                $variant_options = array();
     4230
     4231                if ( isset( $product_options ) && !empty($options) ) {
     4232                    foreach ( $product_options as $key => $value ) {
     4233                        if ( strpos( $key, 'attribute_' ) === 0 ) {
     4234                            $variant_options[$key] = $value;
     4235                        } else if(array_key_exists($key, $product_attributes)) {
     4236                            $variant_options["attribute_" . $product_attributes[$key]] = $value;
     4237                        }
     4238                    }
     4239                }
     4240
     4241                $design_id = $repo->add_design( $user_id, $save_token, $thumbnail_url, intval( '' . $product_id ), $product->get_data()['name'], $display_name, $variant_options);
    41994242
    42004243                $design = $repo->get_design( $user_id, $design_id );
     
    42064249                $product_url = add_query_arg( 'design_id', '' . $design['id'], $product_url );
    42074250
    4208                 if ( null !== $options && '' !== $options ) {
    4209                     try {
    4210                         $options = json_decode( stripslashes( $options ), true );
    4211 
    4212                         if ( isset( $options ) ) {
    4213                             foreach ( $options as $key => $value ) {
    4214                                 if ( strpos( $key, 'attribute_' ) === 0 ) {
    4215                                     $product_url = $product_url . '&' . rawurlencode( $key ) . '=' . rawurlencode( $value );
    4216                                 }
    4217                             }
    4218                         }
    4219                     } catch ( \Exception $ex ) {
    4220                         // In case json is invalid, just ignore it.
    4221                     }
     4251                foreach ( $variant_options as $key => $value ) {
     4252                    $product_url = $product_url . '&' . rawurlencode( $key ) . '=' . rawurlencode( $value );
    42224253                }
    42234254
     
    42264257        }
    42274258    } catch ( Exception $ex ) {
    4228                     return $redirect;
    4229     }
    4230 
    4231                     return $redirect;
     4259        return $redirect;
     4260    }
     4261
     4262    return $redirect;
    42324263}
    42334264
  • printess-editor/trunk/readme.txt

    r3172716 r3173481  
    207207= 1.6.26 =
    208208* Added: Added support for dropship variables without having to create template form fields
     209
     210= 1.6.27 =
     211* Fixed: Fixed broken variant handling during saving of designs while not being logged in (variant settings got lost during the login process when saving a design)
Note: See TracChangeset for help on using the changeset viewer.