| @@ -10,9 +10,24 @@ | ||
| 10 | 10 | use FluentCart\Framework\Support\Arr; |
| 11 | 11 | |
| 12 | 12 | class CheckoutFieldsSchema |
| 13 | 13 | { |
| 14 | + /** | |
| 15 | + * Per-request memo for getFieldsSettings(). In production every HTTP | |
| 16 | + * request runs in a fresh PHP process, so this lives exactly one request. | |
| 17 | + * Long-running processes that simulate multiple requests (test suites, | |
| 18 | + * CLI) must clear it between simulated requests via | |
| 19 | + * resetFieldsCache() — as a function-static it was | |
| 20 | + * unreachable and leaked the first request's field settings into every | |
| 21 | + * subsequent one. | |
| 22 | + */ | |
| 23 | + private static $fieldsCache = null; | |
| 14 | 24 | |
| 25 | + public static function resetFieldsCache(): void | |
| 26 | + { | |
| 27 | + self::$fieldsCache = null; | |
| 28 | + } | |
| 29 | + | |
| 15 | 30 | public static function titleMap(): array |
| 16 | 31 | { |
| 17 | 32 | return [ |
| 18 | 33 | 'full_name' => __('Name', 'fluent-cart'), |
| @@ -492,8 +507,14 @@ | ||
| 492 | 507 | 'help_text' => __('Show a legal registration / business ID field at checkout (e.g. company registration number).', 'fluent-cart'), |
| 493 | 508 | 'type' => 'text', |
| 494 | 509 | 'can_alter' => 'yes', |
| 495 | 510 | ], |
| 511 | + 'b2b_only_mode' => [ | |
| 512 | + 'label' => __('B2B Only Mode', 'fluent-cart'), | |
| 513 | + 'help_text' => __('When enabled, the B2B purchase toggle is hidden and business fields are always shown to all customers.', 'fluent-cart'), | |
| 514 | + 'type' => 'checkbox', | |
| 515 | + 'can_alter' => 'yes', | |
| 516 | + ], | |
| 496 | 517 | ], |
| 497 | 518 | 'billing_address' => [ |
| 498 | 519 | 'country' => [ |
| 499 | 520 | 'label' => __('Country', 'fluent-cart'), |
| @@ -582,11 +603,10 @@ | ||
| 582 | 603 | } |
| 583 | 604 | |
| 584 | 605 | public static function getFieldsSettings() |
| 585 | 606 | { |
| 586 | - static $cached = null; | |
| 587 | - if ($cached !== null) { | |
| 588 | - return $cached; | |
| 607 | + if (self::$fieldsCache !== null) { | |
| 608 | + return self::$fieldsCache; | |
| 589 | 609 | } |
| 590 | 610 | |
| 591 | 611 | $defaults = [ |
| 592 | 612 | 'basic_info' => [ |
| @@ -619,8 +639,11 @@ | ||
| 619 | 639 | 'legal_registration_id' => [ |
| 620 | 640 | 'required' => 'no', |
| 621 | 641 | 'enabled' => 'no' |
| 622 | 642 | ], |
| 643 | + 'b2b_only_mode' => [ | |
| 644 | + 'enabled' => 'no', | |
| 645 | + ], | |
| 623 | 646 | ], |
| 624 | 647 | 'billing_address' => [ |
| 625 | 648 | 'country' => [ |
| 626 | 649 | 'required' => 'yes', |
| @@ -726,9 +749,9 @@ | ||
| 726 | 749 | |
| 727 | 750 | $defaults[$key] = wp_parse_args($savedValues, $default); |
| 728 | 751 | } |
| 729 | 752 | |
| 730 | - return ($cached = $defaults); | |
| 753 | + return (self::$fieldsCache = $defaults); | |
| 731 | 754 | } |
| 732 | 755 | |
| 733 | 756 | public static function isTermsRequired(): bool |
| 734 | 757 | { |
| @@ -817,8 +840,14 @@ | ||
| 817 | 840 | { |
| 818 | 841 | $fieldSettings = self::getFieldsSettings(); |
| 819 | 842 | return Arr::get($fieldSettings, 'business_details.legal_registration_id.enabled') === 'yes' |
| 820 | 843 | && Arr::get($fieldSettings, 'business_details.legal_registration_id.required') === 'yes'; |
| 844 | + } | |
| 845 | + | |
| 846 | + public static function isB2BOnlyMode(): bool | |
| 847 | + { | |
| 848 | + $fieldSettings = self::getFieldsSettings(); | |
| 849 | + return Arr::get($fieldSettings, 'business_details.b2b_only_mode.enabled') === 'yes'; | |
| 821 | 850 | } |
| 822 | 851 | |
| 823 | 852 | public static function hasAnyBusinessFields(): bool |
| 824 | 853 | { |