PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.5.2
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.5.2
1.6.6 1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 All 49 releases
fluent-cart / app / Services / Renderer / VatFieldRenderer.php

VatFieldRenderer.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.5.2, at app/Services/Renderer/VatFieldRenderer.php

150 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentCart\App\Services\Renderer;
4
5 use FluentCart\Framework\Support\Arr;
6 use FluentCart\App\Modules\Tax\TaxModule;
7 use FluentCart\App\Services\Localization\LocalizationManager;
8
9 class VatFieldRenderer
10 {
11 protected $taxApplicableCountry = '';
12
13 public function __construct($taxApplicableCountry = '')
14 {
15 $this->taxApplicableCountry = $taxApplicableCountry;
16 }
17
18 public function render($cart)
19 {
20 if (!CheckoutFieldsSchema::isVatNumberEnabled()) {
21 return '';
22 }
23 ?>
24 <div class="fct_tax_field" data-fluent-cart-checkout-page-tax-wrapper>
25 <?php $this->renderInner($cart->checkout_data); ?>
26 </div>
27 <?php
28 }
29
30 /**
31 * Renders only the inner content of the tax wrapper — used for fragment replacement
32 * so the fragment does not create a nested [data-fluent-cart-checkout-page-tax-wrapper].
33 * Accepts $checkoutData directly so the caller can pass the freshly-updated data
34 * instead of relying on the model's in-memory property.
35 */
36 public function renderInner($checkoutData)
37 {
38 $vatNumber = Arr::get($checkoutData, 'tax_data.vat_number', '');
39 $isValid = Arr::get($checkoutData, 'tax_data.valid', false);
40 $isRequired = CheckoutFieldsSchema::isVatNumberRequired();
41 $isB2BActive = Arr::get($checkoutData, 'form_data.is_business', 'no') === 'yes'
42 || CheckoutFieldsSchema::isB2BOnlyMode();
43 $isEuCountry = TaxModule::isTaxEnabled()
44 && $this->taxApplicableCountry
45 && LocalizationManager::getInstance()->isEuTaxCountry($this->taxApplicableCountry);
46 ?>
47 <div data-fluent-cart-checkout-page-form-input-wrapper class="fct_tax_input_wrapper"
48 id="fct_billing_tax_id_wrapper"
49 >
50 <label for="fct_billing_tax_id" class="sr-only">
51 <?php echo esc_html__('VAT Number', 'fluent-cart'); ?>
52 </label>
53
54 <input
55 data-fluent-cart-checkout-page-tax-id
56 type="text"
57 name="fct_billing_tax_id"
58 autocomplete="tax-id"
59 placeholder="<?php echo esc_attr__('Enter VAT / Tax ID', 'fluent-cart') . ($isRequired ? ' *' : ''); ?>"
60 id="fct_billing_tax_id"
61 value="<?php echo esc_attr($vatNumber); ?>"
62 aria-describedby="fct_billing_tax_id_error"
63 <?php if ($isRequired): ?> data-b2b-required="yes"<?php endif; ?>
64 aria-required="<?php echo ($isRequired && $isB2BActive) ? 'true' : 'false'; ?>"
65 <?php if ($isRequired && $isB2BActive): ?> required<?php endif; ?>
66 <?php echo ($isValid && $isEuCountry) ? 'readonly' : ''; ?>
67 />
68
69 <?php if ($isEuCountry): ?>
70 <?php if ($isValid): ?>
71 <button
72 type="button"
73 data-fluent-cart-tax-remove-btn
74 aria-label="<?php echo esc_attr__('Remove VAT number', 'fluent-cart'); ?>"
75 >
76 <?php echo esc_html__('Remove', 'fluent-cart'); ?>
77 </button>
78 <?php else: ?>
79 <button
80 type="button"
81 data-fluent-cart-checkout-page-tax-apply-btn
82 aria-label="<?php echo esc_attr__('Apply VAT number', 'fluent-cart'); ?>"
83 >
84 <?php echo esc_html__('Apply', 'fluent-cart'); ?>
85 </button>
86 <?php endif; ?>
87 <?php endif; ?>
88 </div>
89
90 <span
91 data-fluent-cart-checkout-page-tax-loading
92 class="fct_tax_loading"
93 role="status"
94 aria-live="polite"
95 aria-label="<?php echo esc_attr__('Validating VAT number', 'fluent-cart'); ?>">
96 </span>
97
98 <span
99 data-fluent-cart-checkout-page-form-error
100 class="fct_form_error"
101 id="fct_billing_tax_id_error"
102 role="alert"
103 aria-live="assertive">
104 </span>
105
106 <?php $this->renderValidNote($checkoutData); ?>
107 <?php
108 }
109
110 public function renderValidNote($checkoutData)
111 {
112 $isValid = Arr::get($checkoutData, 'tax_data.valid', false);
113 $name = Arr::get($checkoutData, 'tax_data.name', '');
114 $taxTotal = Arr::get($checkoutData, 'tax_data.tax_total', 0);
115 $declarationNote = sanitize_text_field(Arr::get($checkoutData, 'tax_data.declaration_note', ''));
116 $isReverseCharge = $isValid && (int) Arr::get($checkoutData, 'tax_data.tax_behavior', 2) === 0;
117 ?>
118 <div
119 class="fct_vat_valid_note <?php echo !$isValid ? 'is-hidden' : ''; ?>"
120 data-fluent-cart-tax-valid-note-wrapper
121 data-vat-valid="<?php echo $isValid ? 'true' : 'false'; ?>"
122 data-vat-name="<?php echo esc_attr($name); ?>"
123 aria-live="polite"
124 <?php echo $isValid ? '' : 'aria-hidden="true"'; ?>
125 >
126 <?php if ($taxTotal != 0 && $isValid): ?>
127 <span class="fct_vat_reverse_charge_warning">
128 <?php echo esc_html__('(Reverse Charge not applied)', 'fluent-cart'); ?>
129 </span>
130 <?php endif; ?>
131
132 <?php if ($isReverseCharge): ?>
133 <div class="fct_vat_declaration_note_wrapper">
134 <textarea
135 id="fct_vat_declaration_note"
136 name="fct_vat_declaration_note"
137 data-fluent-cart-vat-declaration-note
138 maxlength="255"
139 rows="2"
140 placeholder="<?php echo esc_attr__('e.g. I confirm reverse charge applies — VAT will be self-accounted in my country. Saved with your order. Max 255 characters. ', 'fluent-cart'); ?>"
141 aria-label="<?php echo esc_attr__('Reverse Charge Declaration', 'fluent-cart'); ?>"
142 aria-describedby="fct_vat_declaration_note_hint"
143 ><?php echo esc_textarea($declarationNote); ?></textarea>
144 </div>
145 <?php endif; ?>
146 </div>
147 <?php
148 }
149 }
150