Ver Fonte

Fix order linking for block checkout — v1.1.5 -> v1.1.6

- Add woocommerce_store_api_checkout_order_processed hook for block
  checkout (receives $order only, not $order_id + $posted_data)
- Add woocommerce_thankyou fallback to catch any missed linking
- Refactor into do_link_files() with idempotent check (skips if
  already linked) so multiple hooks don't duplicate
- Update documentation and translations

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Dalibor Votruba há 3 meses atrás
pai
commit
1c74c14344

+ 2 - 2
studiou-wc-free-photo-product/CLAUDE.md

@@ -2,7 +2,7 @@
 
 ## Project Overview
 
-WordPress/WooCommerce plugin called **studiou-wc-free-photo-product** (QDR - Studiou WC Free Photo Product) v1.1.5.
+WordPress/WooCommerce plugin called **studiou-wc-free-photo-product** (QDR - Studiou WC Free Photo Product) v1.1.6.
 Allows publishing special variable products where customers upload custom raw images to be printed for a price.
 
 ## Initial Requirements
@@ -54,7 +54,7 @@ Allows publishing special variable products where customers upload custom raw im
 9. `woocommerce_add_cart_item_data` reads file data from WC session (session NOT cleared — same photo reusable for multiple variants)
 10. Cart thumbnails: classic cart via `woocommerce_cart_item_thumbnail`, block cart via `woocommerce_product_get_image_id`/`woocommerce_product_variation_get_image_id`
 11. Order admin thumbnails via `woocommerce_admin_order_item_thumbnail`
-11. On checkout, file record is linked to order via `woocommerce_checkout_order_processed`
+11. On checkout, file record linked to order via `woocommerce_checkout_order_processed` (classic), `woocommerce_store_api_checkout_order_processed` (block), `woocommerce_thankyou` (fallback)
 12. Session only cleared when user clicks Remove
 
 ## Coding Conventions

+ 33 - 2
studiou-wc-free-photo-product/includes/class-studiou-wc-fpp-cart.php

@@ -30,8 +30,10 @@ class Studiou_WC_FPP_Cart {
         // Save file reference to order item
         add_action('woocommerce_checkout_create_order_line_item', array($this, 'save_order_item_meta'), 10, 4);
 
-        // Link file records to order after checkout
+        // Link file records to order after checkout (classic + block checkout)
         add_action('woocommerce_checkout_order_processed', array($this, 'link_files_to_order'), 10, 3);
+        add_action('woocommerce_store_api_checkout_order_processed', array($this, 'link_files_to_order_from_store_api'), 10, 1);
+        add_action('woocommerce_thankyou', array($this, 'link_files_to_order_fallback'), 10, 1);
 
         // Replace order item thumbnail with uploaded image (admin)
         add_filter('woocommerce_admin_order_item_thumbnail', array($this, 'admin_order_item_thumbnail'), 10, 3);
@@ -183,10 +185,39 @@ class Studiou_WC_FPP_Cart {
     }
 
     public function link_files_to_order($order_id, $posted_data, $order) {
+        $this->do_link_files($order);
+    }
+
+    /**
+     * Block checkout fires this hook with only the $order parameter.
+     */
+    public function link_files_to_order_from_store_api($order) {
+        $this->do_link_files($order);
+    }
+
+    /**
+     * Fallback: runs on thank-you page to catch any missed linking.
+     */
+    public function link_files_to_order_fallback($order_id) {
+        $order = wc_get_order($order_id);
+        if ($order) {
+            $this->do_link_files($order);
+        }
+    }
+
+    private function do_link_files($order) {
+        if (!$order) {
+            return;
+        }
+        $order_id = $order->get_id();
         foreach ($order->get_items() as $item_id => $item) {
             $file_record_id = $item->get_meta('_studiou_fpp_file_record_id');
             if ($file_record_id) {
-                $this->db->link_file_to_order((int) $file_record_id, $order_id, $item_id);
+                // Only link if not already linked
+                $record = $this->db->get_file_record((int) $file_record_id);
+                if ($record && (int) $record->order_id === 0) {
+                    $this->db->link_file_to_order((int) $file_record_id, $order_id, $item_id);
+                }
             }
         }
     }

+ 1 - 1
studiou-wc-free-photo-product/languages/studiou-wc-free-photo-product-cs_CZ.po

@@ -3,7 +3,7 @@
 # This file is distributed under the GPL v2 or later.
 msgid ""
 msgstr ""
-"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.1.5\n"
+"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.1.6\n"
 "Report-Msgid-Bugs-To: https://www.quadarax.com\n"
 "POT-Creation-Date: 2026-04-02 00:00+0000\n"
 "PO-Revision-Date: 2026-04-02 00:00+0000\n"

+ 1 - 1
studiou-wc-free-photo-product/languages/studiou-wc-free-photo-product.pot

@@ -2,7 +2,7 @@
 # This file is distributed under the GPL v2 or later.
 msgid ""
 msgstr ""
-"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.1.5\n"
+"Project-Id-Version: QDR - Studiou WC Free Photo Product 1.1.6\n"
 "Report-Msgid-Bugs-To: https://www.quadarax.com\n"
 "POT-Creation-Date: 2026-04-02 00:00+0000\n"
 "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"

+ 3 - 1
studiou-wc-free-photo-product/readme.md

@@ -214,7 +214,9 @@ studiou-wc-free-photo-product/
 | `woocommerce_product_variation_get_image_id` | Filter | Returns uploaded photo as variation image (block cart) |
 | `woocommerce_get_item_data` | Filter | Displays file name in cart |
 | `woocommerce_checkout_create_order_line_item` | Action | Saves file meta to order item |
-| `woocommerce_checkout_order_processed` | Action | Links file record to order |
+| `woocommerce_checkout_order_processed` | Action | Links file record to order (classic checkout) |
+| `woocommerce_store_api_checkout_order_processed` | Action | Links file record to order (block checkout) |
+| `woocommerce_thankyou` | Action | Fallback linking on thank-you page |
 | `woocommerce_admin_order_item_thumbnail` | Filter | Replaces order item thumbnail with uploaded photo |
 | `woocommerce_product_data_tabs` | Filter | Adds Free Photo product tab |
 | `woocommerce_product_data_panels` | Action | Renders Free Photo settings panel |

+ 2 - 2
studiou-wc-free-photo-product/studiou-wc-free-photo-product.php

@@ -3,7 +3,7 @@
  * Plugin Name: QDR - Studiou WC Free Photo Product
  * Plugin URI: https://www.quadarax.com/plugins/studiou-wc-free-photo-product
  * Description: Allows publishing special WooCommerce products with variants and custom raw image upload for photo printing
- * Version: 1.1.5
+ * Version: 1.1.6
  * Requires at least: 6.9.4
  * Requires PHP: 8.2
  * Author: Dalibor Votruba
@@ -21,7 +21,7 @@ if (!defined('WPINC')) {
     die;
 }
 
-if (!defined('STUDIOU_WCFPP_VERSION')) define('STUDIOU_WCFPP_VERSION', '1.1.5');
+if (!defined('STUDIOU_WCFPP_VERSION')) define('STUDIOU_WCFPP_VERSION', '1.1.6');
 if (!defined('STUDIOU_WCFPP_PLUGIN_DIR')) define('STUDIOU_WCFPP_PLUGIN_DIR', plugin_dir_path(__FILE__));
 if (!defined('STUDIOU_WCFPP_PLUGIN_URL')) define('STUDIOU_WCFPP_PLUGIN_URL', plugin_dir_url(__FILE__));
 if (!defined('STUDIOU_WCFPP_PLUGIN_BASENAME')) define('STUDIOU_WCFPP_PLUGIN_BASENAME', plugin_basename(__FILE__));