Changeset 3497705
- Timestamp:
- 04/02/2026 05:31:16 PM (2 days ago)
- Location:
- flowdino/trunk
- Files:
-
- 6 edited
-
changelog.txt (modified) (1 diff)
-
flowdino.php (modified) (2 diffs)
-
includes/class-flowdino-wc-sync.php (modified) (1 diff)
-
includes/tabs/class-flowdino-wc-products-tab.php (modified) (1 diff)
-
includes/tabs/class-flowdino-wc-sales-tab.php (modified) (2 diffs)
-
readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
flowdino/trunk/changelog.txt
r3496827 r3497705 1 1 *** FlowDino Changelog *** 2 3 2026-04-02 - version 1.1.12 4 * Sales - Shipping lines ("Frais de port") are now imported as WooCommerce shipping items instead of product lines 5 * Sales - Discount lines ("Remise offre acceptée") are now absorbed into the product line subtotal/total, displaying the discount on the product row 6 * Product - Add variations name 2 7 3 8 2026-04-01 - version 1.1.11 -
flowdino/trunk/flowdino.php
r3496827 r3497705 4 4 * Plugin URI: https://www.flowdino.com 5 5 * Description: Automatically synchronize your WooCommerce catalog with the FlowDino platform for centralized product management. 6 * Version: 1.1.1 16 * Version: 1.1.12 7 7 * Author: Jeremy DUMONT 8 8 * License: GPL v2 or later … … 28 28 } 29 29 if (!defined('FLOWDINO_VERSION')) { 30 define('FLOWDINO_VERSION', '1.1.1 1');30 define('FLOWDINO_VERSION', '1.1.12'); 31 31 } 32 32 -
flowdino/trunk/includes/class-flowdino-wc-sync.php
r3493443 r3497705 319 319 'active' => $active, 320 320 'url' => $variation->get_permalink(), 321 'variation' => $variation_label, 321 322 ); 322 323 -
flowdino/trunk/includes/tabs/class-flowdino-wc-products-tab.php
r3493443 r3497705 1442 1442 ) ? 1 : 0, 1443 1443 'url' => $variation->get_permalink(), 1444 'variation' => $variation_label, 1444 1445 ); 1445 1446 -
flowdino/trunk/includes/tabs/class-flowdino-wc-sales-tab.php
r3496827 r3497705 385 385 386 386 if (!empty($order_lines)) { 387 // --- Classify lines: product, shipping, discount --- 388 $product_lines = array(); 389 $shipping_lines = array(); 390 $discount_lines = array(); 391 387 392 foreach ($order_lines as $line) { 393 $amount = (float) ($line['amountLines'] ?? 0); 394 $title_lc = strtolower($line['title'] ?? ''); 395 $has_product = !empty($line['productId']) || !empty($line['product']['id']); 396 397 if ($has_product) { 398 $product_lines[] = $line; 399 } elseif ( 400 strpos($title_lc, 'frais de port') !== false || 401 strpos($title_lc, 'frais de livraison') !== false || 402 strpos($title_lc, 'livraison') !== false || 403 strpos($title_lc, 'expédition') !== false || 404 strpos($title_lc, 'expedition') !== false || 405 strpos($title_lc, 'shipping') !== false 406 ) { 407 $shipping_lines[] = $line; 408 } elseif ($amount < 0) { 409 $discount_lines[] = $line; 410 } else { 411 $product_lines[] = $line; 412 } 413 } 414 415 // --- Total discount TTC (sum of negative discount lines) --- 416 $total_discount_ttc = 0.0; 417 foreach ($discount_lines as $dl) { 418 $total_discount_ttc += (float) ($dl['amountLines'] ?? 0); 419 } 420 421 // --- Sum of product amounts for proportional discount distribution --- 422 $products_total_ttc = 0.0; 423 foreach ($product_lines as $pl) { 424 $products_total_ttc += max(0.0, (float) ($pl['amountLines'] ?? 0)); 425 } 426 427 // --- Product lines (discount absorbed as subtotal/total difference) --- 428 foreach ($product_lines as $line) { 388 429 $product_id = $this->get_wc_product_id_from_line($line); 389 430 $line_ttc = (float) ($line['amountLines'] ?? 0); 390 431 432 // Proportional share of the global discount for this line 433 $discount_share_ttc = 0.0; 434 if ($products_total_ttc > 0 && $total_discount_ttc < 0) { 435 $discount_share_ttc = $total_discount_ttc * ($line_ttc / $products_total_ttc); 436 } 437 391 438 $product = $product_id ? wc_get_product($product_id) : null; 392 439 $tax_class = $product ? $product->get_tax_class() : ''; 393 $amounts = $this->split_ttc_amount($line_ttc, $billing_country, $tax_class); 394 $total_lines_ht += $amounts['ht']; 440 441 // subtotal = original gross price (before discount) 442 $sub_amounts = $this->split_ttc_amount($line_ttc, $billing_country, $tax_class); 443 // total = net price after discount applied 444 $net_amounts = $this->split_ttc_amount(max(0.0, $line_ttc + $discount_share_ttc), $billing_country, $tax_class); 445 446 $total_lines_ht += $net_amounts['ht']; 395 447 396 448 $item = new WC_Order_Item_Product(); 397 449 $item->set_name(sanitize_text_field($line['title'] ?? __('Produit FlowDino', 'flowdino'))); 398 450 $item->set_quantity(1); 399 $item->set_subtotal($ amounts['ht']);400 $item->set_total($ amounts['ht']);451 $item->set_subtotal($sub_amounts['ht']); // original price → shows discount in WC 452 $item->set_total($net_amounts['ht']); // price after discount 401 453 402 454 if ($product_id) { … … 404 456 } 405 457 458 if (!empty($sub_amounts['rates'])) { 459 $subtotal_taxes = WC_Tax::calc_tax($sub_amounts['ht'], $sub_amounts['rates'], false); 460 $total_taxes = WC_Tax::calc_tax($net_amounts['ht'], $sub_amounts['rates'], false); 461 $item->set_taxes(array('total' => $total_taxes, 'subtotal' => $subtotal_taxes)); 462 } 463 464 $order->add_item($item); 465 } 466 467 // --- Shipping lines --- 468 $shipping_total_ht = 0.0; 469 $shipping_total_tax = 0.0; 470 foreach ($shipping_lines as $line) { 471 $shipping_ttc = (float) ($line['amountLines'] ?? 0); 472 $amounts = $this->split_ttc_amount($shipping_ttc, $billing_country, ''); 473 474 $shipping_total_ht += $amounts['ht']; 475 $shipping_total_tax += $amounts['tax']; 476 $total_lines_ht += $amounts['ht']; 477 478 $shipping_item = new WC_Order_Item_Shipping(); 479 $shipping_item->set_name(sanitize_text_field( 480 $order_data['shippingMethod'] ?? $line['title'] ?? __('Expédition', 'flowdino') 481 )); 482 $shipping_item->set_total($amounts['ht']); 483 406 484 if (!empty($amounts['rates']) && $amounts['tax'] > 0.0) { 407 485 $taxes = WC_Tax::calc_tax($amounts['ht'], $amounts['rates'], false); 408 $ item->set_taxes(array('total' => $taxes, 'subtotal' => $taxes));486 $shipping_item->set_taxes(array('total' => $taxes)); 409 487 } 410 488 411 $order->add_item($item); 412 } 489 $order->add_item($shipping_item); 490 } 491 492 // Set shipping total so WooCommerce order summary reflects the correct amount 493 if ($shipping_total_ht > 0.0) { 494 $order->set_shipping_total($shipping_total_ht); 495 if (wc_tax_enabled() && $shipping_total_tax > 0.0) { 496 $order->set_shipping_tax($shipping_total_tax); 497 } 498 } 499 413 500 } else { 414 501 // No lines: compute from amounts -
flowdino/trunk/readme.txt
r3496827 r3497705 5 5 Tested up to: 6.9 6 6 Requires PHP: 7.4 7 Stable tag: 1.1.1 17 Stable tag: 1.1.12 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.