Plugin Directory

Changeset 3733669


Ignore:
Timestamp:
10/08/2026 04:49:06 AM (2 weeks ago)
Author:
keyideas
Message:

Release 1.0.24 with V2 pricing URL and export controls

Location:
keyideas-jewelry-configurator
Files:
3 edited
8 copied

Legend:

Unmodified
Added
Removed
  • keyideas-jewelry-configurator/tags/1.0.24/includes/class-kijs-admin.php

    r3720949 r3733669  
    444444    }
    445445
     446    private function has_uploaded_csv_file($field_name) {
     447        return !empty($_FILES[$field_name]['tmp_name']);
     448    }
     449
    446450    private function build_preview_summary_message($summary) {
    447451        if (!is_array($summary) || empty($summary)) {
    … …  
    575579
    576580            if ($pricing_action === 'import_v2_csv') {
    577                 $products = $this->validate_uploaded_csv_file('kijs_products_csv', 'products');
    578                 $stones = $this->validate_uploaded_csv_file('kijs_stones_csv', 'stones');
     581                $products_url_input = isset($_POST['kijs_products_csv_url'])
     582                    ? trim((string) wp_unslash($_POST['kijs_products_csv_url']))
     583                    : '';
     584                $stones_url_input = isset($_POST['kijs_stones_csv_url'])
     585                    ? trim((string) wp_unslash($_POST['kijs_stones_csv_url']))
     586                    : '';
     587                $products_url = $products_url_input !== ''
     588                    ? $this->validate_pricing_url($products_url_input)
     589                    : '';
     590                $stones_url = $stones_url_input !== ''
     591                    ? $this->validate_pricing_url($stones_url_input)
     592                    : '';
     593                $products = $this->has_uploaded_csv_file('kijs_products_csv')
     594                    ? $this->validate_uploaded_csv_file('kijs_products_csv', 'products')
     595                    : null;
     596                $stones = $this->has_uploaded_csv_file('kijs_stones_csv')
     597                    ? $this->validate_uploaded_csv_file('kijs_stones_csv', 'stones')
     598                    : null;
     599
     600                if (!$products && $products_url === '') {
     601                    throw new Exception('Provide a products CSV URL or upload the products CSV file.');
     602                }
     603
     604                if (!$stones && $stones_url === '') {
     605                    throw new Exception('Provide a stones CSV URL or upload the stones CSV file.');
     606                }
     607
    579608                $store = $this->get_store_key();
    580609                $token = $this->ensure_remote_token();
    … …  
    583612                    'store'           => $store,
    584613                    'token'           => $token,
    585                     'productsCsvText' => $products['csvText'],
    586                     'stonesCsvText'   => $stones['csvText'],
     614                    'productsCsvText' => $products ? $products['csvText'] : '',
     615                    'stonesCsvText'   => $stones ? $stones['csvText'] : '',
     616                    'productsUrl'     => $products_url,
     617                    'stonesUrl'       => $stones_url,
    587618                ]);
    588619
    … …  
    595626                    'token'       => $token,
    596627                    'pricingData' => $preview['pricingData'],
     628                    'productsUrl' => $products_url,
     629                    'stonesUrl'   => $stones_url,
    597630                ]);
     631
     632                if ($products_url !== '') {
     633                    update_option('kijs_products_pricing_url', $products_url);
     634                }
     635
     636                if ($stones_url !== '') {
     637                    update_option('kijs_stones_pricing_url', $stones_url);
     638                }
    598639
    599640                $message = 'Products and stones pricing imported successfully.';
    … …  
    601642                $this->set_admin_notice('success', $message);
    602643                $this->redirect_to_settings();
     644            }
     645
     646            if ($pricing_action === 'export_v2_products' || $pricing_action === 'export_v2_stones') {
     647                $store = $this->get_store_key();
     648                $token = $this->ensure_remote_token();
     649                $type = $pricing_action === 'export_v2_products' ? 'products' : 'stones';
     650                $response = $this->remote_get('/api/wordpress/pricing-v2/export', [
     651                    'store' => $store,
     652                    'token' => $token,
     653                    'type'  => $type,
     654                ]);
     655
     656                $filename = $store !== '' ? $store . '-ring-pricing-' . $type . '.csv' : 'ring-pricing-' . $type . '.csv';
     657                $content_type = !empty($response['content_type']) ? (string) $response['content_type'] : 'text/csv; charset=utf-8';
     658
     659                nocache_headers();
     660                header('Content-Type: ' . $content_type);
     661                header('Content-Disposition: attachment; filename="' . sanitize_file_name($filename) . '"');
     662                echo $response['body'];
     663                exit;
    603664            }
    604665
    … …  
    637698        $store_key = $this->get_store_key();
    638699        $saved_token = $this->get_saved_token();
     700        $saved_products_url = get_option('kijs_products_pricing_url', '');
     701        $saved_stones_url = get_option('kijs_stones_pricing_url', '');
     702        $api_base_url = $this->get_api_base_url();
    639703        $notice = $this->consume_admin_notice();
    640704        ?>
    … …  
    744808                        <td>
    745809                            <p><strong>Products CSV</strong></p>
     810                            <p>
     811                                <a class="button button-secondary" href="<?php echo esc_url($api_base_url . '/api/common-admin/settings/sample-csv-v2?type=products'); ?>">Download sample</a>
     812                                <button type="submit" class="button button-secondary" name="kijs_pricing_action" value="export_v2_products">Export current products</button>
     813                            </p>
     814                            <label for="kijs_products_csv_url"><strong>Products CSV URL</strong></label>
     815                            <input type="url" id="kijs_products_csv_url" name="kijs_products_csv_url" class="regular-text" value="<?php echo esc_attr($saved_products_url); ?>" placeholder="https://example.com/products-pricing.csv">
     816                            <p class="description">Use a public CSV URL or upload a file below.</p>
    746817                            <input type="file" name="kijs_products_csv" accept=".csv,text/csv">
    747                             <p class="description">Upload the product pricing CSV for this store.</p>
    748818
    749819                            <p><strong>Stones CSV</strong></p>
     820                            <p>
     821                                <a class="button button-secondary" href="<?php echo esc_url($api_base_url . '/api/common-admin/settings/sample-csv-v2?type=stones'); ?>">Download sample</a>
     822                                <button type="submit" class="button button-secondary" name="kijs_pricing_action" value="export_v2_stones">Export current stones</button>
     823                            </p>
     824                            <label for="kijs_stones_csv_url"><strong>Stones CSV URL</strong></label>
     825                            <input type="url" id="kijs_stones_csv_url" name="kijs_stones_csv_url" class="regular-text" value="<?php echo esc_attr($saved_stones_url); ?>" placeholder="https://example.com/stones-pricing.csv">
     826                            <p class="description">Use a public CSV URL or upload a file below.</p>
    750827                            <input type="file" name="kijs_stones_csv" accept=".csv,text/csv">
    751                             <p class="description">Upload the stone pricing CSV for this store. Both files are validated before anything is saved.</p>
     828                            <p class="description">Both products and stones sources are validated before anything is saved. Maximum upload size: 2 MB per file.</p>
    752829                        </td>
    753830                    </tr>
  • keyideas-jewelry-configurator/tags/1.0.24/keyideas-jewelry-configurator.php

    r3720949 r3733669  
    44* Author URI: https://www.keyideasinfotech.com/
    55* Description: 3D jewelry configurator for WordPress and WooCommerce with ring and bracelet customization.
    6 * Version: 1.0.23
     6* Version: 1.0.24
    77* Author:      Keyideas
    88* License: GPL v2 or later
  • keyideas-jewelry-configurator/tags/1.0.24/readme.txt

    r3720949 r3733669  
    66Tested up to: 6.9
    77Requires PHP: 7.4
    8 Stable tag: 1.0.23
     8Stable tag: 1.0.24
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    290290== Changelog ==
    291291
     292= 1.0.24 =
     293* Add V2 products and stones sample downloads, hosted CSV URL inputs, and current pricing exports to the WordPress settings page.
     294* Keep CSV upload fallback and existing pricing/frontend behavior unchanged.
     295
    292296= 1.0.23 =
    293297* Update the pricing import UI to support separate products and stones CSV uploads for V2 pricing.
  • keyideas-jewelry-configurator/trunk/includes/class-kijs-admin.php

    r3720949 r3733669  
    444444    }
    445445
     446    private function has_uploaded_csv_file($field_name) {
     447        return !empty($_FILES[$field_name]['tmp_name']);
     448    }
     449
    446450    private function build_preview_summary_message($summary) {
    447451        if (!is_array($summary) || empty($summary)) {
    … …  
    575579
    576580            if ($pricing_action === 'import_v2_csv') {
    577                 $products = $this->validate_uploaded_csv_file('kijs_products_csv', 'products');
    578                 $stones = $this->validate_uploaded_csv_file('kijs_stones_csv', 'stones');
     581                $products_url_input = isset($_POST['kijs_products_csv_url'])
     582                    ? trim((string) wp_unslash($_POST['kijs_products_csv_url']))
     583                    : '';
     584                $stones_url_input = isset($_POST['kijs_stones_csv_url'])
     585                    ? trim((string) wp_unslash($_POST['kijs_stones_csv_url']))
     586                    : '';
     587                $products_url = $products_url_input !== ''
     588                    ? $this->validate_pricing_url($products_url_input)
     589                    : '';
     590                $stones_url = $stones_url_input !== ''
     591                    ? $this->validate_pricing_url($stones_url_input)
     592                    : '';
     593                $products = $this->has_uploaded_csv_file('kijs_products_csv')
     594                    ? $this->validate_uploaded_csv_file('kijs_products_csv', 'products')
     595                    : null;
     596                $stones = $this->has_uploaded_csv_file('kijs_stones_csv')
     597                    ? $this->validate_uploaded_csv_file('kijs_stones_csv', 'stones')
     598                    : null;
     599
     600                if (!$products && $products_url === '') {
     601                    throw new Exception('Provide a products CSV URL or upload the products CSV file.');
     602                }
     603
     604                if (!$stones && $stones_url === '') {
     605                    throw new Exception('Provide a stones CSV URL or upload the stones CSV file.');
     606                }
     607
    579608                $store = $this->get_store_key();
    580609                $token = $this->ensure_remote_token();
    … …  
    583612                    'store'           => $store,
    584613                    'token'           => $token,
    585                     'productsCsvText' => $products['csvText'],
    586                     'stonesCsvText'   => $stones['csvText'],
     614                    'productsCsvText' => $products ? $products['csvText'] : '',
     615                    'stonesCsvText'   => $stones ? $stones['csvText'] : '',
     616                    'productsUrl'     => $products_url,
     617                    'stonesUrl'       => $stones_url,
    587618                ]);
    588619
    … …  
    595626                    'token'       => $token,
    596627                    'pricingData' => $preview['pricingData'],
     628                    'productsUrl' => $products_url,
     629                    'stonesUrl'   => $stones_url,
    597630                ]);
     631
     632                if ($products_url !== '') {
     633                    update_option('kijs_products_pricing_url', $products_url);
     634                }
     635
     636                if ($stones_url !== '') {
     637                    update_option('kijs_stones_pricing_url', $stones_url);
     638                }
    598639
    599640                $message = 'Products and stones pricing imported successfully.';
    … …  
    601642                $this->set_admin_notice('success', $message);
    602643                $this->redirect_to_settings();
     644            }
     645
     646            if ($pricing_action === 'export_v2_products' || $pricing_action === 'export_v2_stones') {
     647                $store = $this->get_store_key();
     648                $token = $this->ensure_remote_token();
     649                $type = $pricing_action === 'export_v2_products' ? 'products' : 'stones';
     650                $response = $this->remote_get('/api/wordpress/pricing-v2/export', [
     651                    'store' => $store,
     652                    'token' => $token,
     653                    'type'  => $type,
     654                ]);
     655
     656                $filename = $store !== '' ? $store . '-ring-pricing-' . $type . '.csv' : 'ring-pricing-' . $type . '.csv';
     657                $content_type = !empty($response['content_type']) ? (string) $response['content_type'] : 'text/csv; charset=utf-8';
     658
     659                nocache_headers();
     660                header('Content-Type: ' . $content_type);
     661                header('Content-Disposition: attachment; filename="' . sanitize_file_name($filename) . '"');
     662                echo $response['body'];
     663                exit;
    603664            }
    604665
    … …  
    637698        $store_key = $this->get_store_key();
    638699        $saved_token = $this->get_saved_token();
     700        $saved_products_url = get_option('kijs_products_pricing_url', '');
     701        $saved_stones_url = get_option('kijs_stones_pricing_url', '');
     702        $api_base_url = $this->get_api_base_url();
    639703        $notice = $this->consume_admin_notice();
    640704        ?>
    … …  
    744808                        <td>
    745809                            <p><strong>Products CSV</strong></p>
     810                            <p>
     811                                <a class="button button-secondary" href="<?php echo esc_url($api_base_url . '/api/common-admin/settings/sample-csv-v2?type=products'); ?>">Download sample</a>
     812                                <button type="submit" class="button button-secondary" name="kijs_pricing_action" value="export_v2_products">Export current products</button>
     813                            </p>
     814                            <label for="kijs_products_csv_url"><strong>Products CSV URL</strong></label>
     815                            <input type="url" id="kijs_products_csv_url" name="kijs_products_csv_url" class="regular-text" value="<?php echo esc_attr($saved_products_url); ?>" placeholder="https://example.com/products-pricing.csv">
     816                            <p class="description">Use a public CSV URL or upload a file below.</p>
    746817                            <input type="file" name="kijs_products_csv" accept=".csv,text/csv">
    747                             <p class="description">Upload the product pricing CSV for this store.</p>
    748818
    749819                            <p><strong>Stones CSV</strong></p>
     820                            <p>
     821                                <a class="button button-secondary" href="<?php echo esc_url($api_base_url . '/api/common-admin/settings/sample-csv-v2?type=stones'); ?>">Download sample</a>
     822                                <button type="submit" class="button button-secondary" name="kijs_pricing_action" value="export_v2_stones">Export current stones</button>
     823                            </p>
     824                            <label for="kijs_stones_csv_url"><strong>Stones CSV URL</strong></label>
     825                            <input type="url" id="kijs_stones_csv_url" name="kijs_stones_csv_url" class="regular-text" value="<?php echo esc_attr($saved_stones_url); ?>" placeholder="https://example.com/stones-pricing.csv">
     826                            <p class="description">Use a public CSV URL or upload a file below.</p>
    750827                            <input type="file" name="kijs_stones_csv" accept=".csv,text/csv">
    751                             <p class="description">Upload the stone pricing CSV for this store. Both files are validated before anything is saved.</p>
     828                            <p class="description">Both products and stones sources are validated before anything is saved. Maximum upload size: 2 MB per file.</p>
    752829                        </td>
    753830                    </tr>
  • keyideas-jewelry-configurator/trunk/keyideas-jewelry-configurator.php

    r3720949 r3733669  
    44* Author URI: https://www.keyideasinfotech.com/
    55* Description: 3D jewelry configurator for WordPress and WooCommerce with ring and bracelet customization.
    6 * Version: 1.0.23
     6* Version: 1.0.24
    77* Author:      Keyideas
    88* License: GPL v2 or later
  • keyideas-jewelry-configurator/trunk/readme.txt

    r3720949 r3733669  
    66Tested up to: 6.9
    77Requires PHP: 7.4
    8 Stable tag: 1.0.23
     8Stable tag: 1.0.24
    99License: GPLv2 or later
    1010License URI: https://www.gnu.org/licenses/gpl-2.0.html
    … …  
    290290== Changelog ==
    291291
     292= 1.0.24 =
     293* Add V2 products and stones sample downloads, hosted CSV URL inputs, and current pricing exports to the WordPress settings page.
     294* Keep CSV upload fallback and existing pricing/frontend behavior unchanged.
     295
    292296= 1.0.23 =
    293297* Update the pricing import UI to support separate products and stones CSV uploads for V2 pricing.
Note: See TracChangeset for help on using the changeset viewer.