Plugin Directory

Changeset 3223698


Ignore:
Timestamp:
01/16/2025 03:51:02 PM (14 months ago)
Author:
visidea
Message:

2.1.12

Location:
visidea
Files:
215 added
3 edited

Legend:

Unmodified
Added
Removed
  • visidea/trunk/admin/class-visidea-admin.php

    r3148770 r3223698  
    1212
    1313ini_set('max_execution_time', 3600);
    14 ini_set('display_errors', 0);
    15 ini_set('display_startup_errors', 0);
    16 error_reporting(E_ALL & ~E_NOTICE  & ~E_DEPRECATED);
     14// ini_set('display_errors', 0);
     15// ini_set('display_startup_errors', 0);
     16// error_reporting(E_ALL & ~E_NOTICE  & ~E_DEPRECATED);
    1717
    1818class Visidea_Admin {
     
    126126
    127127  public function cron_items_dump() {
     128    // Initialize multilanguage
     129    $multilanguage = $this->init_multilanguage();
     130
     131    // Get plugin options and set file paths
     132    $options = get_option('visidea_plugin_options');
     133    $option_filename = 'items_' . $options['private_token'] . '.tmp';
     134    $file_path = plugin_dir_path(__FILE__) . $option_filename;
     135    $fp = fopen($file_path, 'a'); // Open in append mode
     136
     137    // Write the header only if the file is new
     138    if (ftell($fp) === 0) {
     139        $items_columns = "item_id;code;mpn;ean;name;brand_id;brand_name;price;market_price;discount;page_ids;page_names;url;images;stock;gender;description";
     140
     141        if ($multilanguage['enabled']) {
     142            foreach ($multilanguage['languages'] as $lang) {
     143                if ($multilanguage['default'] != $lang) {
     144                    $lang_code = substr($lang, 0, 2);
     145                    $items_columns .= ";name_{$lang_code};description_{$lang_code};page_names_{$lang_code};url_{$lang_code}";
     146                }
     147            }
     148        }
     149
     150        fwrite($fp, $items_columns . "\n");
     151    }
     152
     153    // Set pagination and resume from the last processed page
     154    $chunkSize = 500; // Adjust chunk size to balance performance
     155    $page_marker_file = plugin_dir_path(__FILE__) . 'items_page_marker.txt';
     156    $page = file_exists($page_marker_file) ? (int)file_get_contents($page_marker_file) : 1;
     157
     158    while (true) {
     159        // Fetch product IDs in chunks
     160        $products = wc_get_products([
     161            'status' => 'publish',
     162            'type' => ['simple', 'variable', 'external'],
     163            'limit' => $chunkSize,
     164            'page' => $page,
     165            'return' => 'ids',
     166        ]);
     167
     168        if (empty($products)) {
     169            break; // No more products to process
     170        }
     171
     172        // Process products
     173        foreach ($products as $product_id) {
     174            $item = wc_get_product($product_id);
     175
     176            // Prepare and write product buffer
     177            $buffer = $this->prepare_product_buffer($item, $multilanguage);
     178            fwrite($fp, $buffer);
     179
     180            unset($item); // Free memory
     181        }
     182
     183        // Save progress and increment page
     184        file_put_contents($page_marker_file, $page);
     185        $page++;
     186    }
     187
     188    // Clean up marker file and finalize output
     189    if (file_exists($page_marker_file)) {
     190        unlink($page_marker_file);
     191    }
     192
     193    $old_filename = 'items_' . $options['private_token'] . '.csv';
     194    $hash_filename = 'items_' . $options['private_token'] . '.hash';
     195    unlink(plugin_dir_path(__FILE__) . $old_filename);
     196    rename($file_path, plugin_dir_path(__FILE__) . $old_filename);
     197    file_put_contents(plugin_dir_path(__FILE__) . $hash_filename, hash_file('md5', plugin_dir_path(__FILE__) . $old_filename));
     198
     199    fclose($fp); // Close the file pointer
     200  }
     201
     202  public function cron_items_dumpold() {
    128203    // Init multilanguage
    129204    $multilanguage = $this->init_multilanguage();
     
    386461  }
    387462
    388   public function cron_interactions_month() {
    389   }
    390 
    391463  public function cron_interactions_dump() {
    392464      // error_log( 'fired cron_interactions_dump at ' . date( DATE_RFC2822 ) );
     
    398470      $fp = fopen($file, 'w');
    399471
    400       // $logfile = plugin_dir_path(__FILE__) . 'log.txt';
    401       // $fp2 = fopen($logfile, 'w');
    402 
    403472      // Write header
    404       $interactions_columns = "item_id;action;user_id;timestamp\n";
     473      $interactions_columns = "item_id;action;user_id;price;quantity;timestamp\n";
    405474      fwrite($fp, $interactions_columns);
    406475
     
    411480        $today   = strtotime( date('Y-m-d') );
    412481
    413         // fwrite($fp2, json_encode(array(
    414         //   'limit' => -1,
    415         //   'orderby' => 'date',
    416         //   'order' => 'DESC',
    417         //   'date_created' => ( $today - ( $days_delay * $one_day ) ).'...'.( $today - ( $days_delay * $one_day ) + $one_day ),
    418         // ))."\n");
    419         // fwrite($fp2, 'start:'.gmdate("Y-m-d\TH:i:s\Z",( $today - ( $start * $one_day ) ))."\n");
    420         // fwrite($fp2, 'end:'.gmdate("Y-m-d\TH:i:s\Z",( $today - ( $start * $one_day ) + $one_day ))."\n");
    421 
    422482        $query = new WC_Order_Query( array(
    423483          'limit' => -1,
     
    427487 
    428488        foreach ($orders as $order) {
    429           // fwrite($fp2, 'order:'.$order->get_id()."\n");
    430489
    431490          // Get customer ID
    432           // $user_id = $order->get_billing_email();
    433491          $user_id = $order->get_user_id();
    434           // if (empty($user_id)) {
    435           //   $user_id = $this->vs_get_customer_id($order->get_billing_email());
    436           //   if (empty($user_id)) {
    437           //     $user_id = $order->get_billing_email();
    438           //   } else {
    439           //     $user_id = 'c_'.$user_id;
    440           //   }
    441           // }
    442492 
    443493          // Loop through order items and write them in the opened file
     
    452502            else
    453503              $product_id = 0;
    454  
    455             // fwrite($fp2, 'order:'.$order->get_id()."\n");
    456             // fwrite($fp2, 'mail:'.$order->get_billing_email()."\n");
    457             // fwrite($fp2, 'customer_id:'.$user_id."\n");
    458             // fwrite($fp2, 'product_id:'.$product_id."\n");
    459504     
    460      
     505            // Get item price and quantity
     506            $item_price = $item->get_total(); // Total price for this item (quantity * unit price)
     507            $item_quantity = $item->get_quantity(); // Quantity of the item in the order
     508
    461509            // If all is set create the buffer
    462510            if ($product_id > 0 && !empty($user_id)) {
    463               // fwrite($fp2, 'write to file'."\n");
    464  
    465               $buffer = $product_id . ';"purchase";' . $user_id . ';"'.$order->get_date_created()->format(DateTime::ATOM) .'"'. "\n";
     511 
     512              $buffer = $product_id .
     513                        ';"purchase";' .
     514                        $user_id . ';' .
     515                        round($item_price, 2). ';' .
     516                        round($item_quantity) . ';' .
     517                        '"' . $order->get_date_created()->format(DateTime::ATOM) . '"' . "\n";
    466518 
    467519              // Write to file
    468520              fwrite($fp, $buffer);
     521
    469522            }
    470523 
  • visidea/trunk/readme.txt

    r3211016 r3223698  
    66Tested up to: 6.6
    77Requires PHP: 7.0
    8 Stable tag: 2.1.11
     8Stable tag: 2.1.12
    99License: GPLv3
    1010License URI: https://www.gnu.org/licenses/gpl-3.0.html
     
    9696
    9797== Changelog ==
     98
     99= 2.1.12 2025-01-16 =
     100Export improvements
    98101
    99102= 2.1.11 2024-12-20 =
  • visidea/trunk/visidea.php

    r3211016 r3223698  
    55 * Plugin URI: https://visidea.ai
    66 * Description: Visidea is the search and recommendations plugin for WooCommerce. Visidea improves UX and increases the revenues of your website.
    7  * Version: 2.1.11
     7 * Version: 2.1.12
    88 * Author: Inferendo
    99 * Author URI: https://visidea.ai
     
    2727 * Current Visidea version.
    2828 */
    29 define('VISIDEA_VERSION', '2.1.11');
     29define('VISIDEA_VERSION', '2.1.12');
    3030
    3131/**
Note: See TracChangeset for help on using the changeset viewer.