@@ -1691,8 +1691,6 @@ public function test_is_coupon_valid_fixed_product_sale_items() {
1691
1691
1692
1692
/**
1693
1693
* Test that fixed cart discount coupons maintain their total amount when quantities change in admin orders.
1694
- *
1695
- * @link https://github.com/woocommerce/woocommerce/issues/XXXXX
1696
1694
*/
1697
1695
public function test_fixed_cart_discount_quantity_change_admin_order () {
1698
1696
$ price = 20 ;
@@ -1747,4 +1745,45 @@ public function test_fixed_cart_discount_quantity_change_admin_order() {
1747
1745
// Verify order total is $30 (original $40 - $10 discount).
1748
1746
$ this ->assertEquals ( 30.0 , $ order ->get_total (), 'Order total should be $30 after quantity change ' );
1749
1747
}
1748
+
1749
+ /**
1750
+ * Test that manual discounts are preserved when no coupons are used in order.
1751
+ * This tests the logic in wc_save_order_items that only recalculates coupons when coupons exist.
1752
+ */
1753
+ public function test_manual_discount_preservation_no_coupons () {
1754
+ $ price = 20 ;
1755
+
1756
+ // Create a product with a price of $20.
1757
+ $ product = WC_Helper_Product::create_simple_product ();
1758
+ $ product ->set_regular_price ( $ price );
1759
+ $ product ->save ();
1760
+ $ this ->store_product ( $ product );
1761
+
1762
+ // Create an order.
1763
+ $ order = new WC_Order ();
1764
+ $ order ->set_status ( 'processing ' );
1765
+ $ order ->save ();
1766
+ $ order_item_id = $ order ->add_product ( $ product , 1 );
1767
+ $ this ->store_order ( $ order );
1768
+
1769
+ // Simulate $5 manual discount.
1770
+ $ items = array (
1771
+ 'order_item_id ' => array ( $ order_item_id ),
1772
+ 'line_total ' => array ( $ order_item_id => $ price - 5 ),
1773
+ 'line_subtotal ' => array ( $ order_item_id => $ price ),
1774
+ );
1775
+
1776
+ // Save the order items - this should preserve manual discounts since no coupons are applied.
1777
+ wc_save_order_items ( $ order ->get_id (), $ items );
1778
+
1779
+ // Reload the order to get updated data.
1780
+ $ order = wc_get_order ( $ order ->get_id () );
1781
+ $ order_items = $ order ->get_items ();
1782
+ $ order_item = reset ( $ order_items );
1783
+
1784
+ // Verify the manual discount is preserved.
1785
+ $ this ->assertEquals ( 20.0 , $ order_item ->get_subtotal (), 'Subtotal should be $20 ' );
1786
+ $ this ->assertEquals ( 15.0 , $ order_item ->get_total (), 'Total should be $15 preserving manual discount ' );
1787
+ $ this ->assertEquals ( 15.0 , $ order ->get_total (), 'Order total should be $15 preserving manual discount ' );
1788
+ }
1750
1789
}
0 commit comments