| @@ -493,8 +493,37 @@ | ||
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | $discountable_units = $this->grouped_discount_budget( $rule, $total_qualifying_units ); |
| 496 | 496 | |
| 497 | + /** | |
| 498 | + * A flat amount is charged for the pooled group as a whole. | |
| 499 | + * | |
| 500 | + * Pooling exists so the cart together can reach the tier minimum, so | |
| 501 | + * the rule qualifies for the group rather than for each line that | |
| 502 | + * contributed quantity. The Calc layer returns the rule value whole | |
| 503 | + * for every line it is handed, because a flat amount does not scale | |
| 504 | + * with units, so spreading it across lines multiplied the discount by | |
| 505 | + * the line count: a flat 10 came out as 20 over two lines. | |
| 506 | + * | |
| 507 | + * It is applied to the first eligible line carrying the entire pooled | |
| 508 | + * budget, which is what lets a recursive rule still charge once per | |
| 509 | + * bundle: the Calc layer derives the bundle count from that quantity. | |
| 510 | + * Per unit types keep every line, since their amount is meant to | |
| 511 | + * scale with the units. | |
| 512 | + */ | |
| 513 | + if ( in_array( $rule['discount_type'], array( 'fixed', 'fixed_price' ), true ) ) { | |
| 514 | + $first_line = reset( $eligible_lines ); | |
| 515 | + | |
| 516 | + if ( ! empty( $first_line['item'] ) && $discountable_units > 0 ) { | |
| 517 | + $item = $first_line['item']; | |
| 518 | + $item['disco_forced_qty'] = $discountable_units; | |
| 519 | + | |
| 520 | + $this->apply_rule_to_discount( $discounts, $campaign, $rule, $item, $cart, $total_applicable_qty ); | |
| 521 | + } | |
| 522 | + | |
| 523 | + continue; | |
| 524 | + } | |
| 525 | + | |
| 497 | 526 | // Hand out the discountable units across the eligible lines in cart order. |
| 498 | 527 | foreach ( $eligible_lines as $eligible_line ) { |
| 499 | 528 | if ( $discountable_units <= 0 ) { |
| 500 | 529 | break; |