Changeset 3314209
- Timestamp:
- 06/18/2025 10:24:45 PM (10 months ago)
- Location:
- sign-customiser
- Files:
-
- 12 added
- 4 edited
-
tags/1.5.2 (added)
-
tags/1.5.2/.gitignore (added)
-
tags/1.5.2/api.php (added)
-
tags/1.5.2/bootstrap.php (added)
-
tags/1.5.2/cart.php (added)
-
tags/1.5.2/config.php (added)
-
tags/1.5.2/logger.php (added)
-
tags/1.5.2/orders.php (added)
-
tags/1.5.2/readme.txt (added)
-
tags/1.5.2/settings.php (added)
-
tags/1.5.2/sign-customiser.php (added)
-
trunk/cart.php (modified) (12 diffs)
-
trunk/logger.php (added)
-
trunk/orders.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/sign-customiser.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sign-customiser/trunk/cart.php
r3295993 r3314209 11 11 12 12 function 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"); 50 15 51 16 $data = $request['product']; … … 62 27 $product->add_meta_data('_hide_from_search_engines', '1'); 63 28 64 $log ("Product properties set");29 $logger->log("Product properties set"); 65 30 66 $upload = function ($base64, $ext = '.png') use ($log ) {31 $upload = function ($base64, $ext = '.png') use ($logger) { 67 32 $upload_dir = wp_upload_dir(); 68 33 $image_data = base64_decode($base64); 69 $log ("Decoded base64");34 $logger->log("Decoded base64"); 70 35 71 36 $dir = $upload_dir['path'] . '/sign-customiser/'; … … 74 39 $fs = new WP_Filesystem_Direct( true ); 75 40 $fs->put_contents($filename, $image_data); 76 $log ("Wrote decoded image to disk");41 $logger->log("Wrote decoded image to disk"); 77 42 78 43 $filetype = wp_check_filetype(basename($filename), null); … … 84 49 ]; 85 50 $attach_id = wp_insert_attachment($attachment, $filename); 86 $log ("Inserted attachment");51 $logger->log("Inserted attachment"); 87 52 $file = get_attached_file($attach_id); 88 53 $attach_data = wp_generate_attachment_metadata($attach_id, $file); 89 $log ("Generated attachment metadata");54 $logger->log("Generated attachment metadata"); 90 55 wp_update_attachment_metadata($attach_id, $attach_data); 91 $log ("Updated attachment metadata");56 $logger->log("Updated attachment metadata"); 92 57 93 58 return $attach_id; … … 100 65 101 66 if (!empty($data['productImage'])) { 102 $log ("Begin product image");67 $logger->log("Begin product image"); 103 68 $imageId = $upload($data['productImage']); 104 69 $product->set_image_id($imageId); … … 107 72 } 108 73 if (!empty($data['productImageWhite'])) { 109 $log ("Begin product image white");74 $logger->log("Begin product image white"); 110 75 $imageId = $upload($data['productImageWhite']); 111 76 $product->add_meta_data('spcwp_white_image_id', $imageId); … … 113 78 } 114 79 if (!empty($request['svg'])) { 115 $log ("Begin svg");80 $logger->log("Begin svg"); 116 81 $imageId = $upload(base64_encode($request['svg']), '.svg'); 117 82 $product->add_meta_data('spcwp_svg_image_id', $imageId); 118 83 } 119 84 if (!empty($data['customBackground'])) { 120 $log ("Begin custom background");85 $logger->log("Begin custom background"); 121 86 $imageId = $upload($data['customBackground'], '.jpeg'); 122 87 $product->add_meta_data('spcwp_custom_background_image_id', $imageId); … … 125 90 } 126 91 if (!empty($data['customBackgroundOriginal'])) { 127 $log ("Begin custom background original");92 $logger->log("Begin custom background original"); 128 93 $imageId = $upload($data['customBackgroundOriginal'], '.jpeg'); 129 94 $product->add_meta_data('spcwp_custom_background_original_image_id', $imageId); … … 132 97 } 133 98 if (!empty($data['productTypeImageUrls'])) { 134 $log ("Begin product type images");99 $logger->log("Begin product type images"); 135 100 foreach ($data['productTypeImageUrls'] as $part => $arr) { 136 101 foreach (['cropped', 'original'] as $variant) { … … 152 117 } 153 118 154 $log ("Before product save");119 $logger->log("Before product save"); 155 120 156 121 $id = $product->save(); 157 122 158 $log ("Product saved");123 $logger->log("Product saved"); 159 124 160 125 wp_set_object_terms($id, 'SignCustomiser', 'product_tag'); … … 167 132 168 133 if ($customiserId) { 169 $log ("Sending /products request");134 $logger->log("Sending /products request"); 170 135 spcwp_remote_post("/api/customisers/{$customiserId}/products", [ 171 136 'product_id' => strval($id), … … 180 145 } 181 146 182 $log ("Product saved: " . strval($id));147 $logger->log("Product saved: " . strval($id)); 183 148 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(); 188 150 189 151 return rest_ensure_response(['product_id' => $id]); -
sign-customiser/trunk/orders.php
r3305372 r3314209 5 5 */ 6 6 function 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 7 20 $order = wc_get_order($order_id); 8 21 $apiKey = spcwp_get_api_key(); 9 22 10 23 if (!$order || !$apiKey) { 24 $logger->log("Order or API key missing, skipping"); 25 $logger->commit(); 11 26 return; 12 27 } … … 18 33 foreach ($order->get_items() as $item_id => $item) { 19 34 $product_id = $item->get_product_id(); 35 $logger->log("Checking product {$product_id}"); 20 36 21 37 if (!has_term($tag_to_check, 'product_tag', $product_id)) { 38 $logger->log("Product {$product_id} is not a SignCustomiser product, skipping"); 22 39 continue; 23 40 } … … 63 80 'product_type_urls' => $productTypeUrls, 64 81 ]; 82 83 $logger->log("Product {$product_id} added to order"); 65 84 } 66 85 67 86 if (empty($products)) { 87 $logger->log("No products found, skipping"); 88 $logger->commit(); 68 89 return; 69 90 } 91 92 $logger->log("Sending order to API"); 70 93 71 94 spcwp_remote_post("/api/orders", [ … … 88 111 'shipping_line' => $order->get_shipping_method(), 89 112 ]); 113 114 $logger->log("Order sent to API"); 115 $logger->commit(); 90 116 } 91 117 92 118 add_action('woocommerce_new_order', 'spcwp_on_order_created'); 119 add_action('woocommerce_thankyou', 'spcwp_on_order_created'); 120 add_action('woocommerce_order_status_processing', 'spcwp_on_order_created'); 121 add_action('woocommerce_order_status_completed', 'spcwp_on_order_created'); -
sign-customiser/trunk/readme.txt
r3305372 r3314209 3 3 Tested up to: 6.6.1 4 4 Requires at least: 6.5 5 Stable tag: 1.5. 15 Stable tag: 1.5.2 6 6 Requires PHP: 7.4 7 7 License: GPLv2 or later … … 63 63 == Changelog == 64 64 65 = 1.5.2 = 66 * Adds more order hooks to account for different order completion scenarios. 67 65 68 = 1.5.1 = 66 69 * Fixes duplicate order emails coming through. -
sign-customiser/trunk/sign-customiser.php
r3305372 r3314209 4 4 Plugin Name: Sign Customiser 5 5 Plugin URI: https://signcustomiser.com 6 Version: 1.5. 16 Version: 1.5.2 7 7 Requires Plugins: woocommerce 8 8 License: GPL v2 or later … … 24 24 require_once 'config.php'; 25 25 require_once 'bootstrap.php'; 26 require_once 'logger.php'; 26 27 require_once 'settings.php'; 27 28 require_once 'api.php';
Note: See TracChangeset
for help on using the changeset viewer.