Plugin Directory

Changeset 3280282


Ignore:
Timestamp:
04/23/2025 08:21:51 PM (12 months ago)
Author:
limbobp
Message:

limbo new update v 1.0.3

Location:
limbo/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • limbo/trunk/admin/export/limbo-export-functions.php

    r3253459 r3280282  
    213213
    214214            $attributes = limbo_get_product_attributes($product);
     215           
     216            // Format options according to the new structure
    215217            $options = array_map(function($attr) {
     218                $field_values = array_map(function($value) {
     219                    return [
     220                        'value' => $value,
     221                        'additionalPrice' => 0 // Default additional price is 0
     222                    ];
     223                }, (array)$attr['values']);
     224               
    216225                return [
    217226                    'fieldName' => $attr['name'],
    218                     'fieldValues' => (array)$attr['values']
     227                    'fieldValues' => $field_values
    219228                ];
    220229            }, $attributes);
  • limbo/trunk/admin/import/js/limbo-import.js

    r3253459 r3280282  
    170170            );
    171171
     172            // Log the data being sent to verify images are included
    172173            console.log('Selected products data:', selectedProductsData);
    173             console.log('Selected products count:', selectedProductsData.length);
     174           
     175            // Make sure each product has its images array
     176            selectedProductsData.forEach(product => {
     177                if (!product.images) {
     178                    product.images = [];
     179                }
     180            });
    174181
    175182            const response = await fetch(limboImportData.ajaxurl, {
  • limbo/trunk/admin/import/limbo-import-functions.php

    r3253459 r3280282  
    4949
    5050        // Get and decode products data with proper sanitization
    51         $products_raw = sanitize_text_field(wp_unslash($_POST['products']));
     51        $products_raw = wp_unslash($_POST['products']);
    5252        $products = json_decode($products_raw, true);
    5353
     
    158158
    159159    return array_map(function($option) {
    160         return array(
     160        $field_values = [];
     161       
     162        if (isset($option['fieldValues']) && is_array($option['fieldValues'])) {
     163            // Handle new format with value and additionalPrice
     164            foreach ($option['fieldValues'] as $field_value) {
     165                if (is_array($field_value) && isset($field_value['value'])) {
     166                    // New format
     167                    $field_values[] = [
     168                        'value' => sanitize_text_field($field_value['value']),
     169                        'additionalPrice' => isset($field_value['additionalPrice']) ? floatval($field_value['additionalPrice']) : 0
     170                    ];
     171                } else {
     172                    // Legacy format (just strings)
     173                    $field_values[] = [
     174                        'value' => sanitize_text_field($field_value),
     175                        'additionalPrice' => 0
     176                    ];
     177                }
     178            }
     179        }
     180       
     181        return [
    161182            'fieldName' => isset($option['fieldName']) ? sanitize_text_field($option['fieldName']) : '',
    162             'fieldValues' => isset($option['fieldValues']) && is_array($option['fieldValues'])
    163                 ? array_map('sanitize_text_field', $option['fieldValues'])
    164                 : []
    165         );
     183            'fieldValues' => $field_values
     184        ];
    166185    }, $options);
    167186}
     
    250269    foreach ($options as $option) {
    251270        $attribute_name = wc_sanitize_taxonomy_name($option['fieldName']);
    252         $attribute_slug = 'pa_' . $attribute_name;
    253        
    254         if (!taxonomy_exists($attribute_slug)) {
    255             limbo_register_product_attribute($attribute_name, $option['fieldName']);
    256         }
    257        
     271        // Remove the automatic 'pa_' prefix for custom attributes
     272        $attribute_slug = $attribute_name;
     273       
     274        // Create a non-taxonomy attribute
     275        $attribute = new WC_Product_Attribute();
     276        $attribute->set_name($attribute_name);
     277       
     278        // Extract values from the new structure
    258279        $attribute_values = array();
    259         foreach ($option['fieldValues'] as $value) {
    260             $term = get_term_by('name', $value, $attribute_slug);
    261             if (!$term) {
    262                 $term = wp_insert_term($value, $attribute_slug);
    263             }
    264             if (!is_wp_error($term)) {
    265                 $attribute_values[] = is_object($term) ? $term->name : $value;
    266             }
    267         }
    268        
    269         $attribute = new WC_Product_Attribute();
    270         $attribute->set_name($attribute_slug);
     280        foreach ($option['fieldValues'] as $field_value) {
     281            $attribute_values[] = $field_value['value'];
     282        }
     283       
    271284        $attribute->set_options($attribute_values);
    272285        $attribute->set_visible(true);
    273286        $attribute->set_variation(true);
     287        $attribute->set_position(count($attributes));
    274288       
    275289        $attributes[] = $attribute;
     
    427441           
    428442            $variation_attributes = array();
     443            $additional_price_total = 0;
     444           
    429445            foreach ($variation as $attr_name => $attr_value) {
    430                 $variation_attributes['pa_' . wc_sanitize_taxonomy_name($attr_name)] = $attr_value;
     446                // Use the attribute name directly without 'pa_' prefix
     447                $attribute_key = wc_sanitize_taxonomy_name($attr_name);
     448                $variation_attributes[$attribute_key] = $attr_value['value'];
     449                $additional_price_total += floatval($attr_value['additionalPrice']);
    431450            }
     451           
    432452            $variation_product->set_attributes($variation_attributes);
    433453           
    434454            $variation_product->set_status('publish');
    435             $variation_product->set_regular_price($base_price);
     455            // Set price as base price plus any additional price from options
     456            $variation_price = $base_price + $additional_price_total;
     457            $variation_product->set_regular_price($variation_price);
    436458            $variation_product->set_manage_stock(false);
    437459            $variation_product->set_stock_status('instock');
  • limbo/trunk/limbo.php

    r3253459 r3280282  
    44Plugin URI: https://www.uselimbo.com
    55Description: A WooCommerce extension to manage connections and products via a custom admin interface.
    6 Version: 1.0.1
     6Version: 1.0.3
    77Author: Bruno Pastorelli
    88Author URI: http://brunopastorelli.com
     
    1717
    1818// Define plugin constants
    19 define('LIMBO_VERSION', '1.0.1');
     19define('LIMBO_VERSION', '1.0.3');
    2020define('LIMBO_PLUGIN_FILE', __FILE__);
    2121define('LIMBO_PLUGIN_DIR', plugin_dir_path(__FILE__));
  • limbo/trunk/readme.txt

    r3253459 r3280282  
    44Requires at least: 5.0
    55Tested up to: 6.8
    6 Stable tag: 1.0.2
     6Stable tag: 1.0.3
    77Requires PHP: 7.2
    88License: GPLv2 or later
Note: See TracChangeset for help on using the changeset viewer.