Plugin Directory

Changeset 3314209


Ignore:
Timestamp:
06/18/2025 10:24:45 PM (10 months ago)
Author:
signcustomiser
Message:

Release version 1.5.2

Location:
sign-customiser
Files:
12 added
4 edited

Legend:

Unmodified
Added
Removed
  • sign-customiser/trunk/cart.php

    r3295993 r3314209  
    1111
    1212function spcwp_product_callback($request) {
    13   $start_time = null;
    14   $last_time = null;
    15   $logs = [];
    16 
    17   $debug = spcwp_get_debug();
    18 
    19   $log = function($step_name, $reset = false) use ($debug, &$start_time, &$last_time, &$logs) {
    20     if (!$debug) {
    21       return;
    22     }
    23 
    24     // Get current time
    25     $current_time = microtime(true);
    26 
    27     // Initialize start time if not set or reset requested
    28     if ($start_time === null || $reset) {
    29       $start_time = $current_time;
    30       $last_time = $current_time;
    31       $time_since_start = 0;
    32       $time_since_last = 0;
    33     } else {
    34       $time_since_start = $current_time - $start_time;
    35       $time_since_last = $current_time - $last_time;
    36       $last_time = $current_time;
    37     }
    38 
    39     // Format the log entry
    40     $logs[] = sprintf(
    41       "[%s] %s - Time since start: %.4f sec, Time since last step: %.4f sec",
    42       date('Y-m-d H:i:s'),
    43       $step_name,
    44       $time_since_start,
    45       $time_since_last
    46     );
    47   };
    48 
    49   $log("Starting product create", true);
     13  $logger = new SPCWP_Logger();
     14  $logger->log("Starting product create");
    5015
    5116  $data = $request['product'];
     
    6227  $product->add_meta_data('_hide_from_search_engines', '1');
    6328
    64   $log("Product properties set");
     29  $logger->log("Product properties set");
    6530
    66   $upload = function ($base64, $ext = '.png') use ($log) {
     31  $upload = function ($base64, $ext = '.png') use ($logger) {
    6732    $upload_dir = wp_upload_dir();
    6833    $image_data = base64_decode($base64);
    69     $log("Decoded base64");
     34    $logger->log("Decoded base64");
    7035
    7136    $dir = $upload_dir['path'] . '/sign-customiser/';
     
    7439    $fs = new WP_Filesystem_Direct( true );
    7540    $fs->put_contents($filename, $image_data);
    76     $log("Wrote decoded image to disk");
     41    $logger->log("Wrote decoded image to disk");
    7742
    7843    $filetype = wp_check_filetype(basename($filename), null);
     
    8449    ];
    8550    $attach_id = wp_insert_attachment($attachment, $filename);
    86     $log("Inserted attachment");
     51    $logger->log("Inserted attachment");
    8752    $file = get_attached_file($attach_id);
    8853    $attach_data = wp_generate_attachment_metadata($attach_id, $file);
    89     $log("Generated attachment metadata");
     54    $logger->log("Generated attachment metadata");
    9055    wp_update_attachment_metadata($attach_id, $attach_data);
    91     $log("Updated attachment metadata");
     56    $logger->log("Updated attachment metadata");
    9257
    9358    return $attach_id;
     
    10065
    10166  if (!empty($data['productImage'])) {
    102     $log("Begin product image");
     67    $logger->log("Begin product image");
    10368    $imageId = $upload($data['productImage']);
    10469    $product->set_image_id($imageId);
     
    10772  }
    10873  if (!empty($data['productImageWhite'])) {
    109     $log("Begin product image white");
     74    $logger->log("Begin product image white");
    11075    $imageId = $upload($data['productImageWhite']);
    11176    $product->add_meta_data('spcwp_white_image_id', $imageId);
     
    11378  }
    11479  if (!empty($request['svg'])) {
    115     $log("Begin svg");
     80    $logger->log("Begin svg");
    11681    $imageId = $upload(base64_encode($request['svg']), '.svg');
    11782    $product->add_meta_data('spcwp_svg_image_id', $imageId);
    11883  }
    11984  if (!empty($data['customBackground'])) {
    120     $log("Begin custom background");
     85    $logger->log("Begin custom background");
    12186    $imageId = $upload($data['customBackground'], '.jpeg');
    12287    $product->add_meta_data('spcwp_custom_background_image_id', $imageId);
     
    12590  }
    12691  if (!empty($data['customBackgroundOriginal'])) {
    127     $log("Begin custom background original");
     92    $logger->log("Begin custom background original");
    12893    $imageId = $upload($data['customBackgroundOriginal'], '.jpeg');
    12994    $product->add_meta_data('spcwp_custom_background_original_image_id', $imageId);
     
    13297  }
    13398  if (!empty($data['productTypeImageUrls'])) {
    134     $log("Begin product type images");
     99    $logger->log("Begin product type images");
    135100    foreach ($data['productTypeImageUrls'] as $part => $arr) {
    136101      foreach (['cropped', 'original'] as $variant) {
     
    152117  }
    153118
    154   $log("Before product save");
     119  $logger->log("Before product save");
    155120
    156121  $id = $product->save();
    157122
    158   $log("Product saved");
     123  $logger->log("Product saved");
    159124
    160125  wp_set_object_terms($id, 'SignCustomiser', 'product_tag');
     
    167132
    168133  if ($customiserId) {
    169     $log("Sending /products request");
     134    $logger->log("Sending /products request");
    170135    spcwp_remote_post("/api/customisers/{$customiserId}/products", [
    171136      'product_id' => strval($id),
     
    180145  }
    181146
    182   $log("Product saved: " . strval($id));
     147  $logger->log("Product saved: " . strval($id));
    183148
    184   if ($debug) {
    185     $log_file = dirname(__FILE__) . '/debug.txt';
    186     file_put_contents($log_file, implode(PHP_EOL, $logs), FILE_APPEND);
    187   }
     149  $logger->commit();
    188150
    189151  return rest_ensure_response(['product_id' => $id]);
  • sign-customiser/trunk/orders.php

    r3305372 r3314209  
    55 */
    66function spcwp_on_order_created($order_id) {
     7  $logger = new SPCWP_Logger();
     8  $logger->log("Starting order create {$order_id} via hook " . current_filter());
     9
     10  // Check if we've already processed this order
     11  $processed = get_post_meta($order_id, '_spcwp_processed', true);
     12  if ($processed) {
     13    $logger->log("Order already processed, skipping");
     14    $logger->commit();
     15    return;
     16  }
     17
     18  update_post_meta($order_id, '_spcwp_processed', true);
     19
    720  $order = wc_get_order($order_id);
    821  $apiKey = spcwp_get_api_key();
    922
    1023  if (!$order || !$apiKey) {
     24    $logger->log("Order or API key missing, skipping");
     25    $logger->commit();
    1126    return;
    1227  }
     
    1833  foreach ($order->get_items() as $item_id => $item) {
    1934    $product_id = $item->get_product_id();
     35    $logger->log("Checking product {$product_id}");
    2036
    2137    if (!has_term($tag_to_check, 'product_tag', $product_id)) {
     38      $logger->log("Product {$product_id} is not a SignCustomiser product, skipping");
    2239      continue;
    2340    }
     
    6380      'product_type_urls' => $productTypeUrls,
    6481    ];
     82
     83    $logger->log("Product {$product_id} added to order");
    6584  }
    6685
    6786  if (empty($products)) {
     87    $logger->log("No products found, skipping");
     88    $logger->commit();
    6889    return;
    6990  }
     91
     92  $logger->log("Sending order to API");
    7093
    7194  spcwp_remote_post("/api/orders", [
     
    88111    'shipping_line' => $order->get_shipping_method(),
    89112  ]);
     113
     114  $logger->log("Order sent to API");
     115  $logger->commit();
    90116}
    91117
    92118add_action('woocommerce_new_order', 'spcwp_on_order_created');
     119add_action('woocommerce_thankyou', 'spcwp_on_order_created');
     120add_action('woocommerce_order_status_processing', 'spcwp_on_order_created');
     121add_action('woocommerce_order_status_completed', 'spcwp_on_order_created');
  • sign-customiser/trunk/readme.txt

    r3305372 r3314209  
    33Tested up to: 6.6.1
    44Requires at least: 6.5
    5 Stable tag: 1.5.1
     5Stable tag: 1.5.2
    66Requires PHP: 7.4
    77License: GPLv2 or later
     
    6363== Changelog ==
    6464
     65= 1.5.2 =
     66* Adds more order hooks to account for different order completion scenarios.
     67
    6568= 1.5.1 =
    6669* Fixes duplicate order emails coming through.
  • sign-customiser/trunk/sign-customiser.php

    r3305372 r3314209  
    44Plugin Name: Sign Customiser
    55Plugin URI: https://signcustomiser.com
    6 Version: 1.5.1
     6Version: 1.5.2
    77Requires Plugins: woocommerce
    88License: GPL v2 or later
     
    2424require_once 'config.php';
    2525require_once 'bootstrap.php';
     26require_once 'logger.php';
    2627require_once 'settings.php';
    2728require_once 'api.php';
Note: See TracChangeset for help on using the changeset viewer.