Plugin Directory

Changeset 3375637


Ignore:
Timestamp:
10/09/2025 10:06:32 AM (6 months ago)
Author:
closetechnology
Message:

Update to version 3.1.6 from GitHub

Location:
connect-ecommerce
Files:
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • connect-ecommerce/tags/3.1.6/composer.json

    r3362630 r3375637  
    4242    "prepare-behat-tests": "install-package-tests",
    4343    "test": "phpunit",
     44        "test-debug": "XDEBUG_MODE=debug XDEBUG_TRIGGER=1 phpunit",
    4445        "test-install": "bash bin/install-wp-tests.sh wordpress_test root 'root' 127.0.0.1 latest"
    4546  },
  • connect-ecommerce/tags/3.1.6/connect-ecommerce.php

    r3362630 r3375637  
    66 * Author:            Closetechnology
    77 * Author URI:        https://close.technology/
    8  * Version:           3.1.5
     8 * Version:           3.1.6
    99 * Requires PHP:      7.4
    1010 * Requires at least: 6.3
     
    1414 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
    1515 *
     16 * Prefix:            conecom_
     17 *
    1618 * @package WordPress
    1719 */
     
    1921defined( 'ABSPATH' ) || exit;
    2022
    21 define( 'CONECOM_VERSION', '3.1.5' );
     23define( 'CONECOM_VERSION', '3.1.6' );
    2224define( 'CONECOM_FILE', __FILE__ );
    2325define( 'CONECOM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  • connect-ecommerce/tags/3.1.6/includes/Admin/Orders.php

    r3362630 r3375637  
    6666            return;
    6767        }
    68         $this->options        = $options[ $connector ];
    69         $this->settings       = get_option( 'connect_ecommerce' )[ $connector ] ?? array();
    70         $apiname              = 'Connect_Ecommerce_' . $this->options['name'];
    71         $this->connapi_erp    = new $apiname( $options );
    72         $ecstatus             = isset( $this->settings['ecstatus'] ) ? $this->settings['ecstatus'] : $this->options['order_only_order_completed'];
    73         $this->meta_key_order = '_' . $this->options['slug'] . '_invoice_id';
     68        $this->options                    = $options[ $connector ];
     69        $this->settings                   = get_option( 'connect_ecommerce' )[ $connector ] ?? array();
     70        $this->settings['prod_mergevars'] = get_option( 'connect_ecommerce_prod_mergevars' )['prod_mergevars'] ?? array();
     71        $apiname                          = 'Connect_Ecommerce_' . $this->options['name'];
     72        $this->connapi_erp                = new $apiname( $options );
     73        $ecstatus                         = isset( $this->settings['ecstatus'] ) ? $this->settings['ecstatus'] : $this->options['order_only_order_completed'];
     74        $this->meta_key_order             = '_' . $this->options['slug'] . '_invoice_id';
    7475
    7576        add_action( 'wp_ajax_connect_ecommerce_sync_orders', array( $this, 'sync_orders' ) );
  • connect-ecommerce/tags/3.1.6/includes/Admin/Settings.php

    r3362630 r3375637  
    705705        add_settings_section(
    706706            'connect_ecommerce_prod_mergevars_section',
    707             __( 'Merge variables from product attributes to custom fields', 'connect-ecommerce' ),
     707            __( 'Merge variables from ERP to WooCommerce', 'connect-ecommerce' ),
    708708            array( $this, 'section_info_prod_mergevars' ),
    709709            'connect_ecommerce_prod_mergevars'
     
    712712        add_settings_field(
    713713            'wcpimh_prod_mergevars',
    714             __( 'Merge fields with product', 'connect-ecommerce' ),
     714            __( 'Merge fields', 'connect-ecommerce' ),
    715715            array( $this, 'prod_mergevars_callback' ),
    716716            'connect_ecommerce_prod_mergevars',
     
    928928        $admin_settings = [
    929929            $connector => [
    930                 'api'            => '',
    931                 'idcentre'       => '',
    932                 'url'            => '',
    933                 'username'       => '',
    934                 'password'       => '',
    935                 'company'        => '',
    936                 'company_id'     => '',
    937                 'domain'         => '',
    938                 'dbname'         => '',
    939                 'stock'          => 'no',
    940                 'prodst'         => 'draft',
    941                 'virtual'        => 'no',
    942                 'backorders'     => 'no',
    943                 'catsep'         => '',
    944                 'catattr'        => '',
    945                 'filter'         => '',
     930                'api'                => '',
     931                'idcentre'           => '',
     932                'url'                => '',
     933                'username'           => '',
     934                'password'           => '',
     935                'company'            => '',
     936                'company_id'         => '',
     937                'domain'             => '',
     938                'dbname'             => '',
     939                'stock'              => 'no',
     940                'prodst'             => 'draft',
     941                'virtual'            => 'no',
     942                'backorders'         => 'no',
     943                'catsep'             => '',
     944                'catattr'            => '',
     945                'filter'             => '',
    946946                'pricesale_discount' => '',
    947                 'filter_sku'     => '',
    948                 'tax_option'     => 'no',
    949                 'rates'          => 'default',
    950                 'catnp'          => 'yes',
    951                 'doctype'        => 'invoice',
    952                 'cleanchars'     => '',
    953                 'approve_document' => 'no',
    954                 'series'         => '',
    955                 'freeorder'      => 'no',
    956                 'ecstatus'       => 'all',
    957                 'order_tags'     => '',
    958                 'design_id'      => '',
    959                 'sync'           => 'no',
    960                 'sync_num'       => 5,
    961                 'sync_email'     => 'yes',
    962                 'prod_weight_eq' => '',
    963                 'debug_log'      => 'no',
     947                'filter_sku'         => '',
     948                'tax_option'         => 'no',
     949                'rates'              => 'default',
     950                'catnp'              => 'yes',
     951                'doctype'            => 'invoice',
     952                'cleanchars'         => '',
     953                'approve_document'   => 'no',
     954                'series'             => '',
     955                'freeorder'          => 'no',
     956                'ecstatus'           => 'all',
     957                'order_tags'         => '',
     958                'design_id'          => '',
     959                'sync'               => 'no',
     960                'sync_num'           => 5,
     961                'sync_email'         => 'yes',
     962                'prod_weight_eq'     => '',
     963                'debug_log'          => 'no',
    964964            ],
    965965        ];
     
    12551255        }
    12561256        printf(
    1257             '<input class="regular-text" type="text" name="connect_ecommerce[<?php echo esc_html( $this->connector ); ?>][catsep]" id="wcpimh_catsep" value="%s" %s>',
     1257            '<input class="regular-text" type="text" name="connect_ecommerce[%s][catsep]" id="wcpimh_catsep" value="%s" %s>',
     1258            esc_html( $this->connector ),
    12581259            isset( $this->settings['catsep'] ) ? esc_attr( $this->settings['catsep'] ) : '',
    12591260            ! empty( $prod_category_fixed ) ? ' readonly' : ''
     
    14351436     */
    14361437    public function doctype_callback() {
     1438        $documents_type = array(
     1439            'nosync'       => __( 'Not sync', 'connect-ecommerce' ),
     1440            'smart'        => __( 'Smart', 'connect-ecommerce' ),
     1441            'invoice'      => __( 'Invoice', 'connect-ecommerce' ),
     1442            'salesreceipt' => __( 'Sales receipt', 'connect-ecommerce' ),
     1443            'salesorder'   => __( 'Sales order', 'connect-ecommerce' ),
     1444            'waybill'      => __( 'Waybill', 'connect-ecommerce' ),
     1445        );
    14371446        $doctype = isset( $this->settings['doctype'] ) ? $this->settings['doctype'] : 'invoice';
    14381447        ?>
    14391448        <select name="connect_ecommerce[<?php echo esc_html( $this->connector ); ?>][doctype]" id="wcpimh_doctype">
    1440             <option value="nosync" <?php selected( $doctype, 'nosync' ); ?>><?php esc_html_e( 'Not sync', 'connect-ecommerce' ); ?></option>        <option value="invoice" <?php selected( $doctype, 'invoice' ); ?>><?php esc_html_e( 'Invoice', 'connect-ecommerce' ); ?></option>           <option value="salesreceipt" <?php selected( $doctype, 'salesreceipt' ); ?>><?php esc_html_e( 'Sales receipt', 'connect-ecommerce' ); ?></option>           <option value="salesorder" <?php selected( $doctype, 'salesorder' ); ?>><?php esc_html_e( 'Sales order', 'connect-ecommerce' ); ?></option>         <option value="waybill" <?php selected( $doctype, 'waybill' ); ?>><?php esc_html_e( 'Waybill', 'connect-ecommerce' ); ?></option>
     1449            <?php
     1450            foreach ( $documents_type as $value => $label ) {
     1451                echo '<option value="' . esc_html( $value ) . '" ';
     1452                selected( $value, $doctype );
     1453                echo '>' . esc_html( $label ) . '</option>';
     1454            }
     1455            ?>
    14411456        </select>
    14421457        <?php
     
    16341649     */
    16351650    public function prod_mergevars_callback() {
    1636         $product_fields    = PROD::get_all_product_fields();
    1637         $custom_fields     = PROD::get_all_custom_fields();
    1638         $custom_taxonomies = TAX::get_all_custom_taxonomies();
    1639         $product_cat_terms = TAX::get_terms_product_cat();
    1640         $attribute_fields  = $this->connapi_erp->get_product_attributes();
     1651        $product_fields      = PROD::get_all_product_fields();
     1652        $custom_fields       = PROD::get_all_custom_fields();
     1653        $custom_taxonomies   = TAX::get_all_custom_taxonomies();
     1654        $product_cat_terms   = TAX::get_terms_product_cat();
     1655        $attribute_fields    = $this->connapi_erp->get_product_attributes();
     1656        $payment_methods_api = method_exists( $this->connapi_erp, 'get_payment_methods' ) ? $this->connapi_erp->get_payment_methods() : array();
     1657        $payment_methods     = WC()->payment_gateways()->get_available_payment_gateways();
    16411658
    16421659        $settings_mergevars = ! empty( $this->settings_prod_mergevars['prod_mergevars'] ) ? $this->settings_prod_mergevars['prod_mergevars'] : array();
     
    16601677                $size = ! empty( $settings_mergevars ) ? count( $settings_mergevars ) : 0;
    16611678                for ( $idx = 0, $size; $idx <= $size; ++$idx ) {
    1662                     $attrprod = isset( $saved_attr[ $idx ]['attrprod'] ) ? $saved_attr[ $idx ]['attrprod'] : '';
     1679                    $attrprod       = isset( $saved_attr[ $idx ]['attrprod'] ) ? $saved_attr[ $idx ]['attrprod'] : '';
     1680                    $attrprod_label = '';
    16631681                    ?>
    16641682                    <div class="product-mergevars repeating" style="border: 1px solid #ccc; padding: 10px; margin-bottom: 10px;">
     
    16681686                                <?php
    16691687                                foreach ( $attribute_fields as $attribute ) {
     1688                                    if ( empty( $attribute['elements'] ) ) {
     1689                                        continue;
     1690                                    }
    16701691                                    ?>
    16711692                                    <optgroup label="<?php echo esc_html( $attribute['name'] ); ?>">
     
    16761697                                            selected( $option_id, $attrprod );
    16771698                                            echo '>' . esc_html( $value ) . '</option>';
     1699
     1700                                            if ( $option_id === $attrprod ) {
     1701                                                $attrprod_label = $attribute['name'];
     1702                                            }
    16781703                                        }
    16791704                                        ?>
     
    16821707                                }
    16831708                                ?>
     1709                                <?php if ( ! empty( $payment_methods_api ) ) { ?>
     1710                                    <optgroup label="<?php esc_html_e( 'Payment Methods', 'connect-ecommerce' ); ?>">
     1711                                        <?php
     1712                                        foreach ( $payment_methods_api as $key => $value ) {
     1713                                            echo '<option value="' . esc_html( $key ) . '" ';
     1714                                            selected( $key, $attrprod );
     1715                                            echo '>' . esc_html( $value ) . '</option>';
     1716
     1717                                            if ( $key === $attrprod ) {
     1718                                                $attrprod_label = __( 'Payment Method', 'connect-ecommerce' );
     1719                                            }
     1720                                        }
     1721                                        ?>
     1722                                    </optgroup>
     1723                                <?php } ?>
    16841724                            </select>
    16851725                        </div>
     1726                        <span class="attrprod-label">
     1727                            <?php
     1728                            if ( ! empty( $attrprod_label ) ) {
     1729                                echo esc_html( $attrprod_label );
     1730                            }
     1731                            ?>
     1732                        </span>
    16861733                        <span class="dashicons dashicons-arrow-right-alt2"></span>
    16871734                        <div class="save-item">
    1688                             <?php 
     1735                            <?php
    16891736                            $saved_custom_field = isset( $saved_attr[ $idx ]['custom_field'] ) ? $saved_attr[ $idx ]['custom_field'] : '';
    16901737                            $all_fields = array_merge( $product_fields, $product_cat_terms, $custom_taxonomies, $custom_fields );
     
    17331780                                ?>
    17341781                                </optgroup>
     1782                                <?php if ( ! empty( $payment_methods_api ) ) { ?>
     1783                                    <optgroup label="<?php esc_html_e( 'Payment Methods', 'connect-ecommerce' ); ?>">
     1784                                        <?php
     1785                                        foreach ( $payment_methods as $method ) {
     1786                                            $key = 'cf|' . $method->id;
     1787                                            ?>
     1788                                            <option value="<?php echo esc_html( $key ); ?>" <?php selected( $key, $saved_custom_field ); ?>><?php echo esc_html( $method->title ); ?></option>
     1789                                        <?php } ?>
     1790                                    </optgroup>
     1791                                <?php } ?>
    17351792                            </select>
    17361793                        </div>
  • connect-ecommerce/tags/3.1.6/includes/Helpers/ORDER.php

    r3362630 r3375637  
    121121            $contact_name = $order->get_billing_company();
    122122        }
    123         $first_name = $order->get_billing_first_name();
    124         $last_name = $order->get_billing_last_name();
     123        $first_name           = $order->get_billing_first_name();
     124        $last_name            = $order->get_billing_last_name();
     125        $billing_company      = $order->get_billing_company();
     126        $billing_address      = $order->get_billing_address_1() . ',' . $order->get_billing_address_2();
     127        $billing_city         = $order->get_billing_city();
     128        $billing_postcode     = $order->get_billing_postcode();
     129        $billing_state_code   = $order->get_billing_state();
     130        $billing_country_code = $order->get_billing_country();
    125131
    126132        // Clean special chars.
    127133        if ( isset( $setttings['cleanchars'] ) && 'on' === $setttings['cleanchars'] ) {
    128             $contact_name = self::clean_special_chars( $contact_name );
    129             $first_name   = self::clean_special_chars( $first_name );
    130             $last_name    = self::clean_special_chars( $last_name );
     134            $contact_name         = self::clean_special_chars( $contact_name );
     135            $first_name           = self::clean_special_chars( $first_name );
     136            $last_name            = self::clean_special_chars( $last_name );
     137            $billing_company      = self::clean_special_chars( $billing_company );
     138            $billing_address      = self::clean_special_chars( $billing_address );
     139            $billing_city         = self::clean_special_chars( $billing_city );
     140            $billing_postcode     = self::clean_special_chars( $billing_postcode );
     141            $billing_state_code   = self::clean_special_chars( $billing_state_code );
     142            $billing_country_code = self::clean_special_chars( $billing_country_code );
    131143        }
    132144
    133145        // State and Country.
    134         $billing_country_code = $order->get_billing_country();
    135         $billing_state_code   = $order->get_billing_state();
    136         $order_description    = get_bloginfo( 'name', 'display' ) . ' WooCommerce ' . $order_label_id;
    137         $billing_state        = ! empty( $billing_state_code ) && ! empty( $billing_country_code ) ? WC()->countries->get_states( $billing_country_code )[ $billing_state_code ] : '';
     146        $order_description = get_bloginfo( 'name', 'display' ) . ' WooCommerce ' . $order_label_id;
     147        $woo_states        = WC()->countries->get_states( $billing_country_code );
     148        $billing_state     = ! empty( $billing_state_code ) && ! empty( $billing_country_code ) && ! empty( $woo_states[ $billing_state_code ] ) ? $woo_states[ $billing_state_code ] : '';
    138149
    139150        $contact_code = self::get_billing_vat( $order );
     
    162173            'woocommerceStore'       => get_bloginfo( 'name', 'display' ),
    163174            'contactEmail'           => $order->get_billing_email(),
    164             'contactCompany'         => $order->get_billing_company(),
     175            'contactCompany'         => $billing_company,
    165176            'contact_phone'          => $order->get_billing_phone(),
    166             'contactAddress'         => $order->get_billing_address_1() . ',' . $order->get_billing_address_2(),
    167             'contactCity'            => $order->get_billing_city(),
    168             'contactCp'              => $order->get_billing_postcode(),
     177            'contactAddress'         => $billing_address,
     178            'contactCity'            => $billing_city,
     179            'contactCp'              => $billing_postcode,
    169180            'contactProvince'        => $billing_state,
    170181            'contactCountryCode'     => $billing_country_code,
     
    205216        }
    206217
    207         $wc_payment_method    = $order->get_payment_method();
    208         $order_data['notes'] .= ' ';
    209         switch ( $wc_payment_method ) {
    210             case 'cod':
    211                 $order_data['notes'] .= __( 'Paid by cash', 'connect-ecommerce' );
    212                 break;
    213             case 'cheque':
    214                 $order_data['notes'] .= __( 'Paid by check', 'connect-ecommerce' );
    215                 break;
    216             case 'paypal':
    217                 $order_data['notes'] .= __( 'Paid by paypal', 'connect-ecommerce' );
    218                 break;
    219             case 'bacs':
    220                 $order_data['notes'] .= __( 'Paid by bank transfer', 'connect-ecommerce' );
    221                 break;
    222             default:
    223                 $order_data['notes'] .= __( 'Paid by', 'connect-ecommerce' ) . ' ' . (string) $wc_payment_method;
    224                 break;
    225         }
    226         $result_items = self::review_items( $order, $option_prefix );
     218        // Payment method.
     219        $wc_payment_method = $order->get_payment_method();
     220        if ( ! empty( $wc_payment_method ) ) {
     221            $order_data['paymentMethod'] = $wc_payment_method;
     222        }
     223        $settings_prod_mergevars = isset( $setttings['prod_mergevars'] ) ? $setttings['prod_mergevars'] : '';
     224        if ( ! empty( $settings_prod_mergevars ) ) {
     225            foreach ( $settings_prod_mergevars as $key => $value ) {
     226                if ( false === strpos( $key, 'paymentmethods|' ) ) {
     227                    continue;
     228                }
     229                $payment_method     = explode( '|', $key );
     230                $payment_method_woo = explode( '|', $value );
     231                if ( $payment_method_woo[1] === $wc_payment_method ) {
     232                    $order_data['paymentMethodId'] = $payment_method[1];
     233                }
     234            }
     235        }
     236
     237        $result_items        = self::review_items( $order, $option_prefix );
    227238        $order_data['items'] = $result_items['items'];
    228239
  • connect-ecommerce/tags/3.1.6/includes/Helpers/PROD.php

    r3362630 r3375637  
    4242        }
    4343
    44         if ( empty( $item['sku'] ) ) {
     44        if ( empty( $item['sku'] ) && empty( $item['variants'] ) ) { // Only for simple products.
    4545            return array(
    4646                'status'  => 'error',
     
    4949            );
    5050        }
     51        $item_sku = ! empty( $item['sku'] ) ? $item['sku'] : '';
    5152
    5253        if ( empty( $item['variants'] ) && ( 'variants' === $item['kind'] || 'variable' === $item['kind'] ) ) {
     
    6465
    6566        if ( empty( $post_id ) ) {
    66             $post_id        = self::find_product( $item['sku'] ?? '' );
     67            $post_id        = self::find_product( $item_sku );
    6768            $is_new_product = empty( $post_id ) ? true : false;
    6869        }
     
    7475        $msg_product_synced  = __( 'Product synced: ', 'connect-ecommerce' );
    7576
    76         if ( ! $is_filtered && $item['sku'] && 'simple' === $item['kind'] ) {
     77        if ( ! $is_filtered && $item_sku && 'simple' === $item['kind'] ) {
    7778            $result_post = self::sync_product_simple( $settings, $item, $api_erp, false, $post_id );
    7879            $post_id     = $result_post['post_id'] ?? 0;
     
    8687                // Activar para buscar un archivo.
    8788                $any_variant_sku = false;
    88    
     89
    8990                foreach ( $item['variants'] as $variant ) {
    90                     if ( ! $variant['sku'] ) {
     91                    if ( empty( $variant['sku'] ) ) {
    9192                        break;
    9293                    } else {
     
    104105            if ( $post_id ) {
    105106                $parent_product = wc_get_product( $post_id );
    106                 if ( $parent_product && ! $parent_product->get_sku() && ! empty( $item['sku'] ) ) {
     107                if ( $parent_product && ! $parent_product->get_sku() && $item_sku ) {
    107108                    try {
    108                         $parent_product->set_sku( $item['sku'] );
     109                        $parent_product->set_sku( $item_sku );
    109110                        $parent_product->save();
    110                     } catch ( \Exception $e ) {}
     111                    } catch ( \Exception $e ) {
     112                        // Error.
     113                        return array(
     114                            'status'  => 'error',
     115                            'post_id' => $post_id,
     116                            'message' => __( 'Error setting SKU to parent product: ', 'connect-ecommerce' ) . $e->getMessage(),
     117                        );
     118                    }
    111119                }
    112120                unset( $parent_product );
     
    120128                $post_id     = $result_prod['prod_id'] ?? 0;
    121129                $message    .= 0 === $post_id || false === $post_id ? $msg_product_created : $msg_product_synced;
    122                 $message    .= $item['name'] . '. SKU: ' . $item['sku'] . '(' . $item['kind'] . ') ' . $result_prod['message'] ?? '';
     130                $message    .= $item['name'] . '. SKU: ' . $item_sku . '(' . $item['kind'] . ') ' . $result_prod['message'] ?? '';
    123131            }
    124132        } elseif ( ! $is_filtered && 'pack' === $item['kind'] && $plugin_pack_active ) {
    125             $post_id = ! empty( $post_id ) ? $post_id : self::find_product( $item['sku'] );
     133            $post_id = ! empty( $post_id ) ? $post_id : self::find_product( $item_sku );
    126134
    127135            if ( ! $post_id ) {
     
    129137                wp_set_object_terms( $post_id, 'woosb', 'product_type' );
    130138            }
    131             if ( $post_id && $item['sku'] && 'pack' === $item['kind'] ) {
     139            if ( $post_id && $item_sku && 'pack' === $item['kind'] ) {
    132140                // Create subproducts before.
    133141                $pack_items = '';
     
    153161                );
    154162            }
    155             $message .= $item['name'] . '. SKU: ' . $item['sku'] . ' (' . $item['kind'] . ')' . $result_prod['message'] ?? '';
     163            $message .= $item['name'] . '. SKU: ' . $item_sku . ' (' . $item['kind'] . ')' . $result_prod['message'] ?? '';
    156164        } elseif ( ! $is_filtered && 'pack' === $item['kind'] && ! $plugin_pack_active ) {
    157165            $message .= '<span class="warning">' . __( 'Product needs Plugin to import: ', 'connect-ecommerce' );
     
    161169            // Product not synced without SKU.
    162170            $message .= '<span class="warning">' . __( 'Product filtered to not import: ', 'connect-ecommerce' ) . $item['name'] . '(' . $item['kind'] . ') </span>';
    163         } elseif ( '' === $item['sku'] && 'simple' === $item['kind'] ) {
     171        } elseif ( '' === $item_sku && 'simple' === $item['kind'] ) {
    164172            // Product not synced without SKU.
    165173            return array(
     
    257265        $message            = '';
    258266        $product            = null;
     267        $item_sku           = ! empty( $item['sku'] ) ? $item['sku'] : '';
    259268
    260269        // Start.
     
    330339
    331340        $product_props        = array_merge( $product_props, $product_props_new );
    332         $product_props['sku'] = $item['sku'] ?? '';
     341        $product_props['sku'] = $item_sku;
    333342        // Set properties and save.
    334343        $product->set_props( $product_props );
     
    546555            }
    547556        }
     557        $variations_atachment_ids = array();
    548558        foreach ( $item['variants'] as $variant ) {
    549559            $variation_id = 0; // default value.
     
    639649            // Add image to variation.
    640650            if ( ! empty( $variant['image'] ) ) {
    641                 self::attach_image_to_product( $variation_id, $variant['image'] );
    642             }
     651                $variations_atachment_ids[] = self::attach_image_to_product( $variation_id, $variant['image'] );
     652            }
     653        }
     654        if ( ! empty( $variations_atachment_ids ) ) {
     655            $product->set_gallery_image_ids( $variations_atachment_ids );
    643656        }
    644657        $var_prop   = TAX::make_attributes( $attributes, true );
     
    892905     * @param array|string  $image Image data.
    893906     * @param bool   $first_image If is the first image for thumbnail.
    894      * @return void
     907     *
     908     * @return int $attach_id Attachment ID.
    895909     */
    896910    private static function attach_image_to_product( $product_id, $image_data, $first_image = true ) {
     
    928942            // Check for download errors
    929943            if ( is_wp_error( $handle_file['tmp_name'] ) ) {
    930                 return;
     944                return 0;
    931945            }
    932946
     
    964978            update_post_meta( $product_id, '_product_image_gallery', $gallery );
    965979        }
     980
     981        return $attach_id;
    966982    }
    967983
  • connect-ecommerce/tags/3.1.6/includes/assets/admin.css

    r3362630 r3375637  
    8080.repeater-section .product-mergevars {
    8181    display: grid;
    82     grid-template-columns: 3fr 1fr 3fr 1fr;
     82    grid-template-columns: 3fr 1fr 1fr 3fr 1fr;
    8383}
    8484
  • connect-ecommerce/tags/3.1.6/readme.txt

    r3362630 r3375637  
    66Requires PHP: 7.4
    77Tested up to: 6.8
    8 Stable tag: 3.1.5
    9 Version: 3.1.5
     8Stable tag: 3.1.6
     9Version: 3.1.6
    1010License: GPL2
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4545- Adds the NIF/CIF field for proper invoicing.
    4646- Complies with Verifactu and GDPR.
     47- For ERPs that support it, you can send the payment method.
    4748
    4849This plugin serves as the foundation for various connectors. The free version supports:
    4950- [Clientify](https://close.marketing/likes/clientify/)
     51
     52**Merge variables**
     53You can use this section to merge variables from ERP to WooCommerce. That means that you can merge categories, attributes, products, custom fields, taxonomies, etc.
     54
     55You will need to add Payment methods to merge variables to send the payment method to the ERP.
    5056
    5157Premium connectors include:
     
    99105
    100106== Changelog ==
     107
     108= 3.1.6 =
     109* Enhancement: Added variation images to product gallery for APIs that allows images in variations.
     110* Enhancement: Added support to import variable products without SKU in parent.
     111* Fixed: error saving category separator.
     112* Enhancement: Added support to payment methods from API.
     113* Enhancement: Added support to smart doctype in Holded.
    101114
    102115= 3.1.5 =
  • connect-ecommerce/tags/3.1.6/vendor/composer/installed.php

    r3362630 r3375637  
    22    'root' => array(
    33        'name' => 'closemarketing/connect-ecommerce',
    4         'pretty_version' => '3.1.5',
    5         'version' => '3.1.5.0',
    6         'reference' => 'c63957d4716f5035636c124eaa23a6694d6e078f',
     4        'pretty_version' => '3.1.6',
     5        'version' => '3.1.6.0',
     6        'reference' => 'c58aa3f1e42e75d62e03e6a22d0846c89ae2f641',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'closemarketing/connect-ecommerce' => array(
    14             'pretty_version' => '3.1.5',
    15             'version' => '3.1.5.0',
    16             'reference' => 'c63957d4716f5035636c124eaa23a6694d6e078f',
     14            'pretty_version' => '3.1.6',
     15            'version' => '3.1.6.0',
     16            'reference' => 'c58aa3f1e42e75d62e03e6a22d0846c89ae2f641',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
  • connect-ecommerce/trunk/composer.json

    r3362630 r3375637  
    4242    "prepare-behat-tests": "install-package-tests",
    4343    "test": "phpunit",
     44        "test-debug": "XDEBUG_MODE=debug XDEBUG_TRIGGER=1 phpunit",
    4445        "test-install": "bash bin/install-wp-tests.sh wordpress_test root 'root' 127.0.0.1 latest"
    4546  },
  • connect-ecommerce/trunk/connect-ecommerce.php

    r3362630 r3375637  
    66 * Author:            Closetechnology
    77 * Author URI:        https://close.technology/
    8  * Version:           3.1.5
     8 * Version:           3.1.6
    99 * Requires PHP:      7.4
    1010 * Requires at least: 6.3
     
    1414 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
    1515 *
     16 * Prefix:            conecom_
     17 *
    1618 * @package WordPress
    1719 */
     
    1921defined( 'ABSPATH' ) || exit;
    2022
    21 define( 'CONECOM_VERSION', '3.1.5' );
     23define( 'CONECOM_VERSION', '3.1.6' );
    2224define( 'CONECOM_FILE', __FILE__ );
    2325define( 'CONECOM_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
  • connect-ecommerce/trunk/includes/Admin/Orders.php

    r3362630 r3375637  
    6666            return;
    6767        }
    68         $this->options        = $options[ $connector ];
    69         $this->settings       = get_option( 'connect_ecommerce' )[ $connector ] ?? array();
    70         $apiname              = 'Connect_Ecommerce_' . $this->options['name'];
    71         $this->connapi_erp    = new $apiname( $options );
    72         $ecstatus             = isset( $this->settings['ecstatus'] ) ? $this->settings['ecstatus'] : $this->options['order_only_order_completed'];
    73         $this->meta_key_order = '_' . $this->options['slug'] . '_invoice_id';
     68        $this->options                    = $options[ $connector ];
     69        $this->settings                   = get_option( 'connect_ecommerce' )[ $connector ] ?? array();
     70        $this->settings['prod_mergevars'] = get_option( 'connect_ecommerce_prod_mergevars' )['prod_mergevars'] ?? array();
     71        $apiname                          = 'Connect_Ecommerce_' . $this->options['name'];
     72        $this->connapi_erp                = new $apiname( $options );
     73        $ecstatus                         = isset( $this->settings['ecstatus'] ) ? $this->settings['ecstatus'] : $this->options['order_only_order_completed'];
     74        $this->meta_key_order             = '_' . $this->options['slug'] . '_invoice_id';
    7475
    7576        add_action( 'wp_ajax_connect_ecommerce_sync_orders', array( $this, 'sync_orders' ) );
  • connect-ecommerce/trunk/includes/Admin/Settings.php

    r3362630 r3375637  
    705705        add_settings_section(
    706706            'connect_ecommerce_prod_mergevars_section',
    707             __( 'Merge variables from product attributes to custom fields', 'connect-ecommerce' ),
     707            __( 'Merge variables from ERP to WooCommerce', 'connect-ecommerce' ),
    708708            array( $this, 'section_info_prod_mergevars' ),
    709709            'connect_ecommerce_prod_mergevars'
     
    712712        add_settings_field(
    713713            'wcpimh_prod_mergevars',
    714             __( 'Merge fields with product', 'connect-ecommerce' ),
     714            __( 'Merge fields', 'connect-ecommerce' ),
    715715            array( $this, 'prod_mergevars_callback' ),
    716716            'connect_ecommerce_prod_mergevars',
     
    928928        $admin_settings = [
    929929            $connector => [
    930                 'api'            => '',
    931                 'idcentre'       => '',
    932                 'url'            => '',
    933                 'username'       => '',
    934                 'password'       => '',
    935                 'company'        => '',
    936                 'company_id'     => '',
    937                 'domain'         => '',
    938                 'dbname'         => '',
    939                 'stock'          => 'no',
    940                 'prodst'         => 'draft',
    941                 'virtual'        => 'no',
    942                 'backorders'     => 'no',
    943                 'catsep'         => '',
    944                 'catattr'        => '',
    945                 'filter'         => '',
     930                'api'                => '',
     931                'idcentre'           => '',
     932                'url'                => '',
     933                'username'           => '',
     934                'password'           => '',
     935                'company'            => '',
     936                'company_id'         => '',
     937                'domain'             => '',
     938                'dbname'             => '',
     939                'stock'              => 'no',
     940                'prodst'             => 'draft',
     941                'virtual'            => 'no',
     942                'backorders'         => 'no',
     943                'catsep'             => '',
     944                'catattr'            => '',
     945                'filter'             => '',
    946946                'pricesale_discount' => '',
    947                 'filter_sku'     => '',
    948                 'tax_option'     => 'no',
    949                 'rates'          => 'default',
    950                 'catnp'          => 'yes',
    951                 'doctype'        => 'invoice',
    952                 'cleanchars'     => '',
    953                 'approve_document' => 'no',
    954                 'series'         => '',
    955                 'freeorder'      => 'no',
    956                 'ecstatus'       => 'all',
    957                 'order_tags'     => '',
    958                 'design_id'      => '',
    959                 'sync'           => 'no',
    960                 'sync_num'       => 5,
    961                 'sync_email'     => 'yes',
    962                 'prod_weight_eq' => '',
    963                 'debug_log'      => 'no',
     947                'filter_sku'         => '',
     948                'tax_option'         => 'no',
     949                'rates'              => 'default',
     950                'catnp'              => 'yes',
     951                'doctype'            => 'invoice',
     952                'cleanchars'         => '',
     953                'approve_document'   => 'no',
     954                'series'             => '',
     955                'freeorder'          => 'no',
     956                'ecstatus'           => 'all',
     957                'order_tags'         => '',
     958                'design_id'          => '',
     959                'sync'               => 'no',
     960                'sync_num'           => 5,
     961                'sync_email'         => 'yes',
     962                'prod_weight_eq'     => '',
     963                'debug_log'          => 'no',
    964964            ],
    965965        ];
     
    12551255        }
    12561256        printf(
    1257             '<input class="regular-text" type="text" name="connect_ecommerce[<?php echo esc_html( $this->connector ); ?>][catsep]" id="wcpimh_catsep" value="%s" %s>',
     1257            '<input class="regular-text" type="text" name="connect_ecommerce[%s][catsep]" id="wcpimh_catsep" value="%s" %s>',
     1258            esc_html( $this->connector ),
    12581259            isset( $this->settings['catsep'] ) ? esc_attr( $this->settings['catsep'] ) : '',
    12591260            ! empty( $prod_category_fixed ) ? ' readonly' : ''
     
    14351436     */
    14361437    public function doctype_callback() {
     1438        $documents_type = array(
     1439            'nosync'       => __( 'Not sync', 'connect-ecommerce' ),
     1440            'smart'        => __( 'Smart', 'connect-ecommerce' ),
     1441            'invoice'      => __( 'Invoice', 'connect-ecommerce' ),
     1442            'salesreceipt' => __( 'Sales receipt', 'connect-ecommerce' ),
     1443            'salesorder'   => __( 'Sales order', 'connect-ecommerce' ),
     1444            'waybill'      => __( 'Waybill', 'connect-ecommerce' ),
     1445        );
    14371446        $doctype = isset( $this->settings['doctype'] ) ? $this->settings['doctype'] : 'invoice';
    14381447        ?>
    14391448        <select name="connect_ecommerce[<?php echo esc_html( $this->connector ); ?>][doctype]" id="wcpimh_doctype">
    1440             <option value="nosync" <?php selected( $doctype, 'nosync' ); ?>><?php esc_html_e( 'Not sync', 'connect-ecommerce' ); ?></option>        <option value="invoice" <?php selected( $doctype, 'invoice' ); ?>><?php esc_html_e( 'Invoice', 'connect-ecommerce' ); ?></option>           <option value="salesreceipt" <?php selected( $doctype, 'salesreceipt' ); ?>><?php esc_html_e( 'Sales receipt', 'connect-ecommerce' ); ?></option>           <option value="salesorder" <?php selected( $doctype, 'salesorder' ); ?>><?php esc_html_e( 'Sales order', 'connect-ecommerce' ); ?></option>         <option value="waybill" <?php selected( $doctype, 'waybill' ); ?>><?php esc_html_e( 'Waybill', 'connect-ecommerce' ); ?></option>
     1449            <?php
     1450            foreach ( $documents_type as $value => $label ) {
     1451                echo '<option value="' . esc_html( $value ) . '" ';
     1452                selected( $value, $doctype );
     1453                echo '>' . esc_html( $label ) . '</option>';
     1454            }
     1455            ?>
    14411456        </select>
    14421457        <?php
     
    16341649     */
    16351650    public function prod_mergevars_callback() {
    1636         $product_fields    = PROD::get_all_product_fields();
    1637         $custom_fields     = PROD::get_all_custom_fields();
    1638         $custom_taxonomies = TAX::get_all_custom_taxonomies();
    1639         $product_cat_terms = TAX::get_terms_product_cat();
    1640         $attribute_fields  = $this->connapi_erp->get_product_attributes();
     1651        $product_fields      = PROD::get_all_product_fields();
     1652        $custom_fields       = PROD::get_all_custom_fields();
     1653        $custom_taxonomies   = TAX::get_all_custom_taxonomies();
     1654        $product_cat_terms   = TAX::get_terms_product_cat();
     1655        $attribute_fields    = $this->connapi_erp->get_product_attributes();
     1656        $payment_methods_api = method_exists( $this->connapi_erp, 'get_payment_methods' ) ? $this->connapi_erp->get_payment_methods() : array();
     1657        $payment_methods     = WC()->payment_gateways()->get_available_payment_gateways();
    16411658
    16421659        $settings_mergevars = ! empty( $this->settings_prod_mergevars['prod_mergevars'] ) ? $this->settings_prod_mergevars['prod_mergevars'] : array();
     
    16601677                $size = ! empty( $settings_mergevars ) ? count( $settings_mergevars ) : 0;
    16611678                for ( $idx = 0, $size; $idx <= $size; ++$idx ) {
    1662                     $attrprod = isset( $saved_attr[ $idx ]['attrprod'] ) ? $saved_attr[ $idx ]['attrprod'] : '';
     1679                    $attrprod       = isset( $saved_attr[ $idx ]['attrprod'] ) ? $saved_attr[ $idx ]['attrprod'] : '';
     1680                    $attrprod_label = '';
    16631681                    ?>
    16641682                    <div class="product-mergevars repeating" style="border: 1px solid #ccc; padding: 10px; margin-bottom: 10px;">
     
    16681686                                <?php
    16691687                                foreach ( $attribute_fields as $attribute ) {
     1688                                    if ( empty( $attribute['elements'] ) ) {
     1689                                        continue;
     1690                                    }
    16701691                                    ?>
    16711692                                    <optgroup label="<?php echo esc_html( $attribute['name'] ); ?>">
     
    16761697                                            selected( $option_id, $attrprod );
    16771698                                            echo '>' . esc_html( $value ) . '</option>';
     1699
     1700                                            if ( $option_id === $attrprod ) {
     1701                                                $attrprod_label = $attribute['name'];
     1702                                            }
    16781703                                        }
    16791704                                        ?>
     
    16821707                                }
    16831708                                ?>
     1709                                <?php if ( ! empty( $payment_methods_api ) ) { ?>
     1710                                    <optgroup label="<?php esc_html_e( 'Payment Methods', 'connect-ecommerce' ); ?>">
     1711                                        <?php
     1712                                        foreach ( $payment_methods_api as $key => $value ) {
     1713                                            echo '<option value="' . esc_html( $key ) . '" ';
     1714                                            selected( $key, $attrprod );
     1715                                            echo '>' . esc_html( $value ) . '</option>';
     1716
     1717                                            if ( $key === $attrprod ) {
     1718                                                $attrprod_label = __( 'Payment Method', 'connect-ecommerce' );
     1719                                            }
     1720                                        }
     1721                                        ?>
     1722                                    </optgroup>
     1723                                <?php } ?>
    16841724                            </select>
    16851725                        </div>
     1726                        <span class="attrprod-label">
     1727                            <?php
     1728                            if ( ! empty( $attrprod_label ) ) {
     1729                                echo esc_html( $attrprod_label );
     1730                            }
     1731                            ?>
     1732                        </span>
    16861733                        <span class="dashicons dashicons-arrow-right-alt2"></span>
    16871734                        <div class="save-item">
    1688                             <?php 
     1735                            <?php
    16891736                            $saved_custom_field = isset( $saved_attr[ $idx ]['custom_field'] ) ? $saved_attr[ $idx ]['custom_field'] : '';
    16901737                            $all_fields = array_merge( $product_fields, $product_cat_terms, $custom_taxonomies, $custom_fields );
     
    17331780                                ?>
    17341781                                </optgroup>
     1782                                <?php if ( ! empty( $payment_methods_api ) ) { ?>
     1783                                    <optgroup label="<?php esc_html_e( 'Payment Methods', 'connect-ecommerce' ); ?>">
     1784                                        <?php
     1785                                        foreach ( $payment_methods as $method ) {
     1786                                            $key = 'cf|' . $method->id;
     1787                                            ?>
     1788                                            <option value="<?php echo esc_html( $key ); ?>" <?php selected( $key, $saved_custom_field ); ?>><?php echo esc_html( $method->title ); ?></option>
     1789                                        <?php } ?>
     1790                                    </optgroup>
     1791                                <?php } ?>
    17351792                            </select>
    17361793                        </div>
  • connect-ecommerce/trunk/includes/Helpers/ORDER.php

    r3362630 r3375637  
    121121            $contact_name = $order->get_billing_company();
    122122        }
    123         $first_name = $order->get_billing_first_name();
    124         $last_name = $order->get_billing_last_name();
     123        $first_name           = $order->get_billing_first_name();
     124        $last_name            = $order->get_billing_last_name();
     125        $billing_company      = $order->get_billing_company();
     126        $billing_address      = $order->get_billing_address_1() . ',' . $order->get_billing_address_2();
     127        $billing_city         = $order->get_billing_city();
     128        $billing_postcode     = $order->get_billing_postcode();
     129        $billing_state_code   = $order->get_billing_state();
     130        $billing_country_code = $order->get_billing_country();
    125131
    126132        // Clean special chars.
    127133        if ( isset( $setttings['cleanchars'] ) && 'on' === $setttings['cleanchars'] ) {
    128             $contact_name = self::clean_special_chars( $contact_name );
    129             $first_name   = self::clean_special_chars( $first_name );
    130             $last_name    = self::clean_special_chars( $last_name );
     134            $contact_name         = self::clean_special_chars( $contact_name );
     135            $first_name           = self::clean_special_chars( $first_name );
     136            $last_name            = self::clean_special_chars( $last_name );
     137            $billing_company      = self::clean_special_chars( $billing_company );
     138            $billing_address      = self::clean_special_chars( $billing_address );
     139            $billing_city         = self::clean_special_chars( $billing_city );
     140            $billing_postcode     = self::clean_special_chars( $billing_postcode );
     141            $billing_state_code   = self::clean_special_chars( $billing_state_code );
     142            $billing_country_code = self::clean_special_chars( $billing_country_code );
    131143        }
    132144
    133145        // State and Country.
    134         $billing_country_code = $order->get_billing_country();
    135         $billing_state_code   = $order->get_billing_state();
    136         $order_description    = get_bloginfo( 'name', 'display' ) . ' WooCommerce ' . $order_label_id;
    137         $billing_state        = ! empty( $billing_state_code ) && ! empty( $billing_country_code ) ? WC()->countries->get_states( $billing_country_code )[ $billing_state_code ] : '';
     146        $order_description = get_bloginfo( 'name', 'display' ) . ' WooCommerce ' . $order_label_id;
     147        $woo_states        = WC()->countries->get_states( $billing_country_code );
     148        $billing_state     = ! empty( $billing_state_code ) && ! empty( $billing_country_code ) && ! empty( $woo_states[ $billing_state_code ] ) ? $woo_states[ $billing_state_code ] : '';
    138149
    139150        $contact_code = self::get_billing_vat( $order );
     
    162173            'woocommerceStore'       => get_bloginfo( 'name', 'display' ),
    163174            'contactEmail'           => $order->get_billing_email(),
    164             'contactCompany'         => $order->get_billing_company(),
     175            'contactCompany'         => $billing_company,
    165176            'contact_phone'          => $order->get_billing_phone(),
    166             'contactAddress'         => $order->get_billing_address_1() . ',' . $order->get_billing_address_2(),
    167             'contactCity'            => $order->get_billing_city(),
    168             'contactCp'              => $order->get_billing_postcode(),
     177            'contactAddress'         => $billing_address,
     178            'contactCity'            => $billing_city,
     179            'contactCp'              => $billing_postcode,
    169180            'contactProvince'        => $billing_state,
    170181            'contactCountryCode'     => $billing_country_code,
     
    205216        }
    206217
    207         $wc_payment_method    = $order->get_payment_method();
    208         $order_data['notes'] .= ' ';
    209         switch ( $wc_payment_method ) {
    210             case 'cod':
    211                 $order_data['notes'] .= __( 'Paid by cash', 'connect-ecommerce' );
    212                 break;
    213             case 'cheque':
    214                 $order_data['notes'] .= __( 'Paid by check', 'connect-ecommerce' );
    215                 break;
    216             case 'paypal':
    217                 $order_data['notes'] .= __( 'Paid by paypal', 'connect-ecommerce' );
    218                 break;
    219             case 'bacs':
    220                 $order_data['notes'] .= __( 'Paid by bank transfer', 'connect-ecommerce' );
    221                 break;
    222             default:
    223                 $order_data['notes'] .= __( 'Paid by', 'connect-ecommerce' ) . ' ' . (string) $wc_payment_method;
    224                 break;
    225         }
    226         $result_items = self::review_items( $order, $option_prefix );
     218        // Payment method.
     219        $wc_payment_method = $order->get_payment_method();
     220        if ( ! empty( $wc_payment_method ) ) {
     221            $order_data['paymentMethod'] = $wc_payment_method;
     222        }
     223        $settings_prod_mergevars = isset( $setttings['prod_mergevars'] ) ? $setttings['prod_mergevars'] : '';
     224        if ( ! empty( $settings_prod_mergevars ) ) {
     225            foreach ( $settings_prod_mergevars as $key => $value ) {
     226                if ( false === strpos( $key, 'paymentmethods|' ) ) {
     227                    continue;
     228                }
     229                $payment_method     = explode( '|', $key );
     230                $payment_method_woo = explode( '|', $value );
     231                if ( $payment_method_woo[1] === $wc_payment_method ) {
     232                    $order_data['paymentMethodId'] = $payment_method[1];
     233                }
     234            }
     235        }
     236
     237        $result_items        = self::review_items( $order, $option_prefix );
    227238        $order_data['items'] = $result_items['items'];
    228239
  • connect-ecommerce/trunk/includes/Helpers/PROD.php

    r3362630 r3375637  
    4242        }
    4343
    44         if ( empty( $item['sku'] ) ) {
     44        if ( empty( $item['sku'] ) && empty( $item['variants'] ) ) { // Only for simple products.
    4545            return array(
    4646                'status'  => 'error',
     
    4949            );
    5050        }
     51        $item_sku = ! empty( $item['sku'] ) ? $item['sku'] : '';
    5152
    5253        if ( empty( $item['variants'] ) && ( 'variants' === $item['kind'] || 'variable' === $item['kind'] ) ) {
     
    6465
    6566        if ( empty( $post_id ) ) {
    66             $post_id        = self::find_product( $item['sku'] ?? '' );
     67            $post_id        = self::find_product( $item_sku );
    6768            $is_new_product = empty( $post_id ) ? true : false;
    6869        }
     
    7475        $msg_product_synced  = __( 'Product synced: ', 'connect-ecommerce' );
    7576
    76         if ( ! $is_filtered && $item['sku'] && 'simple' === $item['kind'] ) {
     77        if ( ! $is_filtered && $item_sku && 'simple' === $item['kind'] ) {
    7778            $result_post = self::sync_product_simple( $settings, $item, $api_erp, false, $post_id );
    7879            $post_id     = $result_post['post_id'] ?? 0;
     
    8687                // Activar para buscar un archivo.
    8788                $any_variant_sku = false;
    88    
     89
    8990                foreach ( $item['variants'] as $variant ) {
    90                     if ( ! $variant['sku'] ) {
     91                    if ( empty( $variant['sku'] ) ) {
    9192                        break;
    9293                    } else {
     
    104105            if ( $post_id ) {
    105106                $parent_product = wc_get_product( $post_id );
    106                 if ( $parent_product && ! $parent_product->get_sku() && ! empty( $item['sku'] ) ) {
     107                if ( $parent_product && ! $parent_product->get_sku() && $item_sku ) {
    107108                    try {
    108                         $parent_product->set_sku( $item['sku'] );
     109                        $parent_product->set_sku( $item_sku );
    109110                        $parent_product->save();
    110                     } catch ( \Exception $e ) {}
     111                    } catch ( \Exception $e ) {
     112                        // Error.
     113                        return array(
     114                            'status'  => 'error',
     115                            'post_id' => $post_id,
     116                            'message' => __( 'Error setting SKU to parent product: ', 'connect-ecommerce' ) . $e->getMessage(),
     117                        );
     118                    }
    111119                }
    112120                unset( $parent_product );
     
    120128                $post_id     = $result_prod['prod_id'] ?? 0;
    121129                $message    .= 0 === $post_id || false === $post_id ? $msg_product_created : $msg_product_synced;
    122                 $message    .= $item['name'] . '. SKU: ' . $item['sku'] . '(' . $item['kind'] . ') ' . $result_prod['message'] ?? '';
     130                $message    .= $item['name'] . '. SKU: ' . $item_sku . '(' . $item['kind'] . ') ' . $result_prod['message'] ?? '';
    123131            }
    124132        } elseif ( ! $is_filtered && 'pack' === $item['kind'] && $plugin_pack_active ) {
    125             $post_id = ! empty( $post_id ) ? $post_id : self::find_product( $item['sku'] );
     133            $post_id = ! empty( $post_id ) ? $post_id : self::find_product( $item_sku );
    126134
    127135            if ( ! $post_id ) {
     
    129137                wp_set_object_terms( $post_id, 'woosb', 'product_type' );
    130138            }
    131             if ( $post_id && $item['sku'] && 'pack' === $item['kind'] ) {
     139            if ( $post_id && $item_sku && 'pack' === $item['kind'] ) {
    132140                // Create subproducts before.
    133141                $pack_items = '';
     
    153161                );
    154162            }
    155             $message .= $item['name'] . '. SKU: ' . $item['sku'] . ' (' . $item['kind'] . ')' . $result_prod['message'] ?? '';
     163            $message .= $item['name'] . '. SKU: ' . $item_sku . ' (' . $item['kind'] . ')' . $result_prod['message'] ?? '';
    156164        } elseif ( ! $is_filtered && 'pack' === $item['kind'] && ! $plugin_pack_active ) {
    157165            $message .= '<span class="warning">' . __( 'Product needs Plugin to import: ', 'connect-ecommerce' );
     
    161169            // Product not synced without SKU.
    162170            $message .= '<span class="warning">' . __( 'Product filtered to not import: ', 'connect-ecommerce' ) . $item['name'] . '(' . $item['kind'] . ') </span>';
    163         } elseif ( '' === $item['sku'] && 'simple' === $item['kind'] ) {
     171        } elseif ( '' === $item_sku && 'simple' === $item['kind'] ) {
    164172            // Product not synced without SKU.
    165173            return array(
     
    257265        $message            = '';
    258266        $product            = null;
     267        $item_sku           = ! empty( $item['sku'] ) ? $item['sku'] : '';
    259268
    260269        // Start.
     
    330339
    331340        $product_props        = array_merge( $product_props, $product_props_new );
    332         $product_props['sku'] = $item['sku'] ?? '';
     341        $product_props['sku'] = $item_sku;
    333342        // Set properties and save.
    334343        $product->set_props( $product_props );
     
    546555            }
    547556        }
     557        $variations_atachment_ids = array();
    548558        foreach ( $item['variants'] as $variant ) {
    549559            $variation_id = 0; // default value.
     
    639649            // Add image to variation.
    640650            if ( ! empty( $variant['image'] ) ) {
    641                 self::attach_image_to_product( $variation_id, $variant['image'] );
    642             }
     651                $variations_atachment_ids[] = self::attach_image_to_product( $variation_id, $variant['image'] );
     652            }
     653        }
     654        if ( ! empty( $variations_atachment_ids ) ) {
     655            $product->set_gallery_image_ids( $variations_atachment_ids );
    643656        }
    644657        $var_prop   = TAX::make_attributes( $attributes, true );
     
    892905     * @param array|string  $image Image data.
    893906     * @param bool   $first_image If is the first image for thumbnail.
    894      * @return void
     907     *
     908     * @return int $attach_id Attachment ID.
    895909     */
    896910    private static function attach_image_to_product( $product_id, $image_data, $first_image = true ) {
     
    928942            // Check for download errors
    929943            if ( is_wp_error( $handle_file['tmp_name'] ) ) {
    930                 return;
     944                return 0;
    931945            }
    932946
     
    964978            update_post_meta( $product_id, '_product_image_gallery', $gallery );
    965979        }
     980
     981        return $attach_id;
    966982    }
    967983
  • connect-ecommerce/trunk/includes/assets/admin.css

    r3362630 r3375637  
    8080.repeater-section .product-mergevars {
    8181    display: grid;
    82     grid-template-columns: 3fr 1fr 3fr 1fr;
     82    grid-template-columns: 3fr 1fr 1fr 3fr 1fr;
    8383}
    8484
  • connect-ecommerce/trunk/readme.txt

    r3362630 r3375637  
    66Requires PHP: 7.4
    77Tested up to: 6.8
    8 Stable tag: 3.1.5
    9 Version: 3.1.5
     8Stable tag: 3.1.6
     9Version: 3.1.6
    1010License: GPL2
    1111License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    4545- Adds the NIF/CIF field for proper invoicing.
    4646- Complies with Verifactu and GDPR.
     47- For ERPs that support it, you can send the payment method.
    4748
    4849This plugin serves as the foundation for various connectors. The free version supports:
    4950- [Clientify](https://close.marketing/likes/clientify/)
     51
     52**Merge variables**
     53You can use this section to merge variables from ERP to WooCommerce. That means that you can merge categories, attributes, products, custom fields, taxonomies, etc.
     54
     55You will need to add Payment methods to merge variables to send the payment method to the ERP.
    5056
    5157Premium connectors include:
     
    99105
    100106== Changelog ==
     107
     108= 3.1.6 =
     109* Enhancement: Added variation images to product gallery for APIs that allows images in variations.
     110* Enhancement: Added support to import variable products without SKU in parent.
     111* Fixed: error saving category separator.
     112* Enhancement: Added support to payment methods from API.
     113* Enhancement: Added support to smart doctype in Holded.
    101114
    102115= 3.1.5 =
  • connect-ecommerce/trunk/vendor/composer/installed.php

    r3362630 r3375637  
    22    'root' => array(
    33        'name' => 'closemarketing/connect-ecommerce',
    4         'pretty_version' => '3.1.5',
    5         'version' => '3.1.5.0',
    6         'reference' => 'c63957d4716f5035636c124eaa23a6694d6e078f',
     4        'pretty_version' => '3.1.6',
     5        'version' => '3.1.6.0',
     6        'reference' => 'c58aa3f1e42e75d62e03e6a22d0846c89ae2f641',
    77        'type' => 'library',
    88        'install_path' => __DIR__ . '/../../',
     
    1212    'versions' => array(
    1313        'closemarketing/connect-ecommerce' => array(
    14             'pretty_version' => '3.1.5',
    15             'version' => '3.1.5.0',
    16             'reference' => 'c63957d4716f5035636c124eaa23a6694d6e078f',
     14            'pretty_version' => '3.1.6',
     15            'version' => '3.1.6.0',
     16            'reference' => 'c58aa3f1e42e75d62e03e6a22d0846c89ae2f641',
    1717            'type' => 'library',
    1818            'install_path' => __DIR__ . '/../../',
Note: See TracChangeset for help on using the changeset viewer.