PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.26
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.26
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 / Hooks / Handlers / BlockEditors / Checkout / InnerBlocks / InnerBlocks.php

InnerBlocks.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.3.26, at app/Hooks/Handlers/BlockEditors/Checkout/InnerBlocks/InnerBlocks.php

1,055 lines 36.3 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\Hooks\Handlers\BlockEditors\Checkout\InnerBlocks;
4
5 use FluentCart\Api\Contracts\CanEnqueue;
6 use FluentCart\Api\ModuleSettings;
7 use FluentCart\Api\StoreSettings;
8 use FluentCart\App\App;
9 use FluentCart\App\Helpers\CartHelper;
10 use FluentCart\App\Helpers\Helper;
11 use FluentCart\App\Modules\Tax\TaxModule;
12 use FluentCart\App\Services\Renderer\CartSummaryRender;
13 use FluentCart\App\Services\Renderer\CheckoutRenderer;
14 use FluentCart\App\Services\Translations\TransStrings;
15 use FluentCart\Framework\Support\Arr;
16 use FluentCartPro\App\Modules\Promotional\OrderBump\OrderBumpBoot;
17
18 class InnerBlocks
19 {
20 use CanEnqueue;
21
22 public static $parentBlock = 'fluent-cart/checkout';
23
24 public array $blocks = [];
25
26 private $cart = null;
27
28 private function getCart()
29 {
30 if ($this->cart === null) {
31 $this->cart = CartHelper::getCart();
32 }
33 return $this->cart;
34 }
35
36
37 public static function textBlockSupport(): array
38 {
39 return [
40 'html' => false,
41 'align' => ['left', 'center', 'right'],
42 'typography' => [
43 'fontSize' => true,
44 'lineHeight' => true
45 ],
46 'spacing' => [
47 'margin' => true,
48 'padding' => true
49 ],
50 'color' => [
51 'text' => true,
52 ],
53 '__experimentalBorder' => [
54 'radius' => true,
55 'color' => true,
56 'width' => true,
57 'style' => true
58 ]
59 ];
60 }
61
62 public static function buttonBlockSupport(): array
63 {
64 return [
65 'html' => false,
66 'align' => ['left', 'center', 'right'],
67 'typography' => [
68 'fontSize' => true,
69 'lineHeight' => true,
70 'fontWeight' => true,
71 'textTransform' => true,
72 ],
73 'spacing' => [
74 'margin' => true,
75 'padding' => true,
76 ],
77 'color' => [
78 'text' => true,
79 'background' => true,
80 ],
81 '__experimentalBorder' => [
82 'radius' => true,
83 'color' => true,
84 'width' => true,
85 'style' => true
86 ],
87 'shadow' => true,
88 ];
89 }
90
91
92 public static function register()
93 {
94 $self = new self();
95 $blocks = $self->getInnerBlocks();
96
97 foreach ($blocks as $block) {
98
99 register_block_type($block['slug'], [
100 'apiVersion' => 3,
101 'api_version' => 3,
102 'version' => 3,
103 'title' => $block['title'],
104 'category' => 'fluent-cart',
105 'parent' => array_merge($block['parent'] ?? [], [static::$parentBlock]),
106 'render_callback' => $block['callback'],
107 'supports' => Arr::get($block, 'supports', []),
108 'attributes' => Arr::get($block, 'attributes', []),
109 'uses_context' => Arr::get($block, 'uses_context', []),
110 ]);
111 }
112
113 add_action('enqueue_block_editor_assets', function () use ($self) {
114 $self->enqueueScripts();
115 });
116
117 }
118
119 public function getInnerBlocks(): array
120 {
121 return [
122 [
123 'title' => __('Checkout Name Fields', 'fluent-cart'),
124 'slug' => 'fluent-cart/checkout-name-fields',
125 'callback' => [$this, 'renderCheckoutNameFields'],
126 'component' => 'CheckoutNameFieldsBlock',
127 'icon' => 'editor-code',
128 'supports' => [
129 'html' => false,
130 'typography' => [
131 'fontSize' => false,
132 'lineHeight' => false
133 ],
134 'spacing' => [
135 'margin' => true,
136 'padding' => true
137 ],
138 'color' => [
139 'text' => false,
140 'background' => true,
141 ],
142 ],
143 'parent' => [
144 'fluent-cart/checkout',
145 'core/column',
146 'core/group'
147 ],
148 ],
149 [
150 'title' => __('Checkout Create Account Field', 'fluent-cart'),
151 'slug' => 'fluent-cart/checkout-create-account-field',
152 'callback' => [$this, 'renderCheckoutCreateAccountField'],
153 'component' => 'CheckoutCreateAccountFieldBlock',
154 'icon' => 'editor-code',
155 'supports' => static::textBlockSupport(),
156 'parent' => [
157 'fluent-cart/checkout',
158 'core/column',
159 'core/group'
160 ],
161 ],
162 [
163 'title' => __('Checkout Address Fields', 'fluent-cart'),
164 'slug' => 'fluent-cart/checkout-address-fields',
165 'callback' => [$this, 'renderCheckoutAddressFields'],
166 'component' => 'CheckoutAddressFieldsBlock',
167 'icon' => 'editor-code',
168 'supports' => [
169 'html' => false,
170 'typography' => [
171 'fontSize' => false,
172 'lineHeight' => false
173 ],
174 'spacing' => [
175 'margin' => true,
176 'padding' => true
177 ],
178 'color' => [
179 'text' => false,
180 'background' => true,
181 ],
182 '__experimentalBorder' => [
183 'radius' => true,
184 'color' => true,
185 'width' => true,
186 'style' => true
187 ]
188 ],
189 'parent' => [
190 'fluent-cart/checkout',
191 'core/column',
192 'core/group'
193 ],
194 ],
195 [
196 'title' => __('Billing Address Field', 'fluent-cart'),
197 'slug' => 'fluent-cart/checkout-billing-address-field',
198 'callback' => [$this, 'renderCheckoutBillingAddressField'],
199 'component' => 'CheckoutBillingAddressFieldBlock',
200 'icon' => 'editor-code',
201 'supports' => [
202 'html' => false,
203 'typography' => [
204 'fontSize' => false,
205 'lineHeight' => false
206 ],
207 'spacing' => [
208 'margin' => true,
209 'padding' => true
210 ],
211 'color' => [
212 'text' => false,
213 'background' => true,
214 ],
215 '__experimentalBorder' => [
216 'radius' => true,
217 'color' => true,
218 'width' => true,
219 'style' => true
220 ]
221 ],
222 'parent' => [
223 'fluent-cart/checkout-address-fields'
224 ],
225 ],
226 [
227 'title' => __('Shipping Address Field', 'fluent-cart'),
228 'slug' => 'fluent-cart/checkout-shipping-address-field',
229 'callback' => [$this, 'renderCheckoutShippingAddressField'],
230 'component' => 'CheckoutShippingAddressFieldBlock',
231 'icon' => 'editor-code',
232 'supports' => [
233 'html' => false,
234 'typography' => [
235 'fontSize' => false,
236 'lineHeight' => false
237 ],
238 'spacing' => [
239 'margin' => true,
240 'padding' => true
241 ],
242 'color' => [
243 'text' => false,
244 'background' => true,
245 ],
246 '__experimentalBorder' => [
247 'radius' => true,
248 'color' => true,
249 'width' => true,
250 'style' => true
251 ]
252 ],
253 'parent' => [
254 'fluent-cart/checkout-address-fields'
255 ],
256 ],
257 [
258 'title' => __('Ship to Different Field', 'fluent-cart'),
259 'slug' => 'fluent-cart/checkout-ship-to-different-field',
260 'callback' => [$this, 'renderCheckoutShipToDifferentField'],
261 'component' => 'CheckoutShipToDifferentFieldBlock',
262 'icon' => 'editor-code',
263 'supports' => [
264 'html' => false,
265 'align' => ['left', 'center', 'right'],
266 'typography' => [
267 'fontSize' => true,
268 'lineHeight' => true
269 ],
270 'spacing' => [
271 'margin' => true,
272 'padding' => true
273 ],
274 'color' => [
275 'text' => true,
276 ],
277 '__experimentalBorder' => [
278 'radius' => true,
279 'color' => true,
280 'width' => true,
281 'style' => true
282 ]
283 ],
284 'parent' => [
285 'fluent-cart/checkout-address-fields'
286 ],
287 ],
288 [
289 'title' => __('Checkout Shipping Methods', 'fluent-cart'),
290 'slug' => 'fluent-cart/checkout-shipping-methods',
291 'callback' => [$this, 'renderCheckoutShippingMethods'],
292 'component' => 'CheckoutShippingMethodsBlock',
293 'icon' => 'editor-code',
294 'supports' => static::textBlockSupport(),
295 'parent' => [
296 'fluent-cart/checkout',
297 'core/column',
298 'core/group'
299 ],
300 ],
301 [
302 'title' => __('Checkout Payment Methods', 'fluent-cart'),
303 'slug' => 'fluent-cart/checkout-payment-methods',
304 'callback' => [$this, 'renderCheckoutPaymentMethods'],
305 'component' => 'CheckoutPaymentMethodsBlock',
306 'icon' => 'editor-code',
307 'supports' => static::textBlockSupport(),
308 'parent' => [
309 'fluent-cart/checkout',
310 'core/column',
311 'core/group'
312 ],
313 ],
314 [
315 'title' => __('Checkout Agree Terms Field', 'fluent-cart'),
316 'slug' => 'fluent-cart/checkout-agree-terms-field',
317 'callback' => [$this, 'renderCheckoutAgreeTermsField'],
318 'component' => 'CheckoutAgreeTermsFieldBlock',
319 'icon' => 'editor-code',
320 'supports' => [
321 'html' => false,
322 'align' => ['left', 'center', 'right'],
323 'typography' => [
324 'fontSize' => true,
325 'lineHeight' => true
326 ],
327 'spacing' => [
328 'margin' => true
329 ],
330 'color' => [
331 'text' => true,
332 ]
333 ],
334 'parent' => [
335 'fluent-cart/checkout',
336 'core/column',
337 'core/group'
338 ],
339 ],
340 [
341 'title' => __('Checkout Submit Button', 'fluent-cart'),
342 'slug' => 'fluent-cart/checkout-submit-button',
343 'callback' => [$this, 'renderCheckoutSubmitButton'],
344 'component' => 'CheckoutSubmitButtonBlock',
345 'icon' => 'editor-code',
346 'supports' => static::buttonBlockSupport(),
347 'parent' => [
348 'fluent-cart/checkout',
349 'core/column',
350 'core/group'
351 ],
352 ],
353 [
354 'title' => __('Checkout Order Notes Field', 'fluent-cart'),
355 'slug' => 'fluent-cart/checkout-order-notes-field',
356 'callback' => [$this, 'renderCheckoutOrderNotesField'],
357 'component' => 'CheckoutOrderNotesFieldBlock',
358 'icon' => 'editor-code',
359 'supports' => static::textBlockSupport(),
360 'parent' => [
361 'fluent-cart/checkout',
362 'core/column',
363 'core/group'
364 ],
365 ],
366 [
367 'title' => __('Checkout Summary', 'fluent-cart'),
368 'slug' => 'fluent-cart/checkout-summary',
369 'callback' => [$this, 'renderCheckoutSummary'],
370 'component' => 'CheckoutSummaryBlock',
371 'icon' => 'editor-code',
372 'supports' => static::textBlockSupport(),
373 'parent' => [
374 'fluent-cart/checkout',
375 'core/column',
376 'core/group'
377 ],
378 ],
379 [
380 'title' => __('Order Summary', 'fluent-cart'),
381 'slug' => 'fluent-cart/checkout-order-summary',
382 'callback' => [$this, 'renderCheckoutOrderSummary'],
383 'component' => 'CheckoutOrderSummaryBlock',
384 'icon' => 'editor-code',
385 'supports' => static::textBlockSupport(),
386 'parent' => [
387 'fluent-cart/checkout-summary'
388 ],
389 ],
390 [
391 'title' => __('Summary Footer', 'fluent-cart'),
392 'slug' => 'fluent-cart/checkout-summary-footer',
393 'callback' => [$this, 'renderCheckoutSummaryFooter'],
394 'component' => 'CheckoutSummaryFooterBlock',
395 'icon' => 'editor-code',
396 'supports' => static::textBlockSupport(),
397 'parent' => [
398 'fluent-cart/checkout-summary'
399 ],
400 ],
401 [
402 'title' => __('Subtotal', 'fluent-cart'),
403 'slug' => 'fluent-cart/checkout-subtotal',
404 'callback' => [$this, 'renderCheckoutSubtotal'],
405 'component' => 'CheckoutSubtotalBlock',
406 'icon' => 'editor-code',
407 'supports' => static::textBlockSupport(),
408 'parent' => [
409 'fluent-cart/checkout-summary-footer'
410 ],
411 ],
412 [
413 'title' => __('Shipping', 'fluent-cart'),
414 'slug' => 'fluent-cart/checkout-shipping',
415 'callback' => [$this, 'renderCheckoutShipping'],
416 'component' => 'CheckoutShippingBlock',
417 'icon' => 'editor-code',
418 'supports' => static::textBlockSupport(),
419 'parent' => [
420 'fluent-cart/checkout-summary-footer'
421 ],
422 ],
423 [
424 'title' => __('Fees', 'fluent-cart'),
425 'slug' => 'fluent-cart/checkout-fees',
426 'callback' => [$this, 'renderCheckoutFees'],
427 'component' => 'CheckoutFeesBlock',
428 'icon' => 'editor-code',
429 'supports' => static::textBlockSupport(),
430 'parent' => [
431 'fluent-cart/checkout-summary-footer'
432 ],
433 ],
434 [
435 'title' => __('Coupon', 'fluent-cart'),
436 'slug' => 'fluent-cart/checkout-coupon',
437 'callback' => [$this, 'renderCheckoutCoupon'],
438 'component' => 'CheckoutCouponBlock',
439 'icon' => 'editor-code',
440 'supports' => static::textBlockSupport(),
441 'parent' => [
442 'fluent-cart/checkout-summary-footer'
443 ],
444 ],
445 [
446 'title' => __('Manual Discount', 'fluent-cart'),
447 'slug' => 'fluent-cart/checkout-manual-discount',
448 'callback' => [$this, 'renderCheckoutManualDiscount'],
449 'component' => 'CheckoutManualDiscountBlock',
450 'icon' => 'editor-code',
451 'supports' => static::textBlockSupport(),
452 'parent' => [
453 'fluent-cart/checkout-summary-footer'
454 ],
455 ],
456 [
457 'title' => __('Tax', 'fluent-cart'),
458 'slug' => 'fluent-cart/checkout-tax',
459 'callback' => [$this, 'renderCheckoutTax'],
460 'component' => 'CheckoutTaxBlock',
461 'icon' => 'editor-code',
462 'supports' => static::textBlockSupport(),
463 'parent' => [
464 'fluent-cart/checkout-summary-footer'
465 ],
466 ],
467 [
468 'title' => __('Shipping Tax', 'fluent-cart'),
469 'slug' => 'fluent-cart/checkout-shipping-tax',
470 'callback' => [$this, 'renderCheckoutShippingTax'],
471 'component' => 'CheckoutShippingTaxBlock',
472 'icon' => 'editor-code',
473 'supports' => static::textBlockSupport(),
474 'parent' => [
475 'fluent-cart/checkout-summary-footer'
476 ],
477 ],
478 [
479 'title' => __('Total', 'fluent-cart'),
480 'slug' => 'fluent-cart/checkout-total',
481 'callback' => [$this, 'renderCheckoutTotal'],
482 'component' => 'CheckoutTotalBlock',
483 'icon' => 'editor-code',
484 'supports' => static::textBlockSupport(),
485 'parent' => [
486 'fluent-cart/checkout-summary-footer'
487 ],
488 ],
489 [
490 'title' => __('Checkout Order Bump', 'fluent-cart'),
491 'slug' => 'fluent-cart/checkout-order-bump',
492 'callback' => [$this, 'renderCheckoutOrderBump'],
493 'component' => 'CheckoutOrderBumpBlock',
494 'icon' => 'editor-code',
495 'supports' => [
496 'html' => false,
497 'align' => ['left', 'center', 'right'],
498 'typography' => [
499 'fontSize' => false,
500 'lineHeight' => false
501 ],
502 'spacing' => [
503 'margin' => true,
504 'padding' => true
505 ],
506 'color' => [
507 'text' => false,
508 'background' => true,
509 ],
510 '__experimentalBorder' => [
511 'radius' => true,
512 'color' => true,
513 'width' => true,
514 'style' => true
515 ]
516 ],
517 'parent' => [
518 'fluent-cart/checkout',
519 'core/column',
520 'core/group'
521 ],
522 ],
523 [
524 'title' => __('Checkout EU VAT', 'fluent-cart'),
525 'slug' => 'fluent-cart/checkout-eu-vat',
526 'callback' => [$this, 'renderCheckoutEuVat'],
527 'component' => 'CheckoutEuVatBlock',
528 'icon' => 'editor-code',
529 'supports' => [
530 'html' => false,
531 'spacing' => [
532 'margin' => true,
533 'padding' => true
534 ],
535 '__experimentalBorder' => [
536 'radius' => true,
537 'color' => true,
538 'width' => true,
539 'style' => true
540 ]
541 ],
542 'parent' => [
543 'fluent-cart/checkout',
544 'core/column',
545 'core/group'
546 ],
547 ]
548 ];
549 }
550
551 public function renderCheckoutNameFields($attributes, $content, $block)
552 {
553 $atts = get_block_wrapper_attributes();
554 $cart = $this->getCart();
555 if (empty(Arr::get($cart, 'cart_data', []))) {
556 return '';
557 }
558
559 ob_start();
560 ?>
561 <div <?php echo $atts; ?>>
562 <?php
563 $renderer = new CheckoutRenderer($cart);
564 $renderer->renderNameFields();
565 $renderer->renderCreateAccountField();
566 ?>
567 </div>
568 <?php
569 return ob_get_clean();
570 }
571
572 public function renderCheckoutCreateAccountField($attributes, $content, $block)
573 {
574 return '';
575 }
576
577 public function renderCheckoutAddressFields($attributes, $content, $block)
578 {
579 $atts = get_block_wrapper_attributes();
580
581 $cart = $this->getCart();
582 if (empty(Arr::get($cart, 'cart_data', []))) {
583 return '';
584 }
585
586 $innerBlocksContent = '';
587 if ($block instanceof \WP_Block && !empty($block->inner_blocks)) {
588 ob_start();
589 ?>
590 <div <?php echo $atts; ?>>
591 <?php
592 foreach ($block->inner_blocks as $inner_block) {
593 if (isset($inner_block->parsed_block)) {
594 echo $inner_block->render();
595 }
596 } ?>
597 </div>
598 <?php
599 $innerBlocksContent = ob_get_clean();
600 }
601 return $innerBlocksContent;
602 }
603
604 public function renderCheckoutBillingAddressField($attributes, $content, $block)
605 {
606 $atts = get_block_wrapper_attributes();
607 $cart = $this->getCart();
608
609 $addressTitle = Arr::get($attributes, 'addressTitle');
610
611 if (empty(Arr::get($cart, 'cart_data', []))) {
612 return '';
613 }
614
615 ob_start();
616 ?>
617 <div <?php echo $atts; ?>>
618 <?php
619 (new CheckoutRenderer($cart))->renderBillingAddressFields($addressTitle);
620 ?>
621 </div>
622 <?php
623 return ob_get_clean();
624
625 }
626
627 public function renderCheckoutShippingAddressField($attributes, $content, $block)
628 {
629 $atts = get_block_wrapper_attributes();
630 $cart = $this->getCart();
631 $addressTitle = Arr::get($attributes, 'addressTitle');
632 if (empty(Arr::get($cart, 'cart_data', [])) || !$cart->requireShipping()) {
633 return '';
634 }
635 ob_start();
636 ?>
637 <div <?php echo $atts; ?>>
638 <?php
639 (new CheckoutRenderer($cart))->renderShippingAddressFields($addressTitle);
640 ?>
641 </div>
642 <?php
643 return ob_get_clean();
644 }
645
646 public function renderCheckoutShipToDifferentField($attributes, $content, $block)
647 {
648 $atts = get_block_wrapper_attributes();
649 $cart = $this->getCart();
650 $title = Arr::get($attributes, 'ship_to_different_title');
651 if (empty(Arr::get($cart, 'cart_data', [])) || !$cart->requireShipping()) {
652 return '';
653 }
654 ob_start();
655 ?>
656 <div <?php echo $atts; ?>>
657 <?php
658 (new CheckoutRenderer($cart))->renderShipToDifferentField([
659 'title' => $title,
660 'wrapper_atts'=> $atts,
661 ]);
662 ?>
663 </div>
664 <?php
665 return ob_get_clean();
666
667 }
668
669 public function renderCheckoutShippingMethods($attributes, $content, $block)
670 {
671 $cart = $this->getCart();
672 if (empty(Arr::get($cart, 'cart_data', []))) {
673 return '';
674 }
675 $class = $cart->requireShipping() ? '' : 'is-hidden';
676 $atts = get_block_wrapper_attributes([
677 'class' => 'fct_checkout_shipping_methods ' . $class
678 ]);
679 ob_start();
680 ?>
681 <div <?php echo $atts; ?>>
682 <?php
683 (new CheckoutRenderer($cart))->renderShippingOptions();
684 ?>
685 </div>
686 <?php
687 return ob_get_clean();
688 }
689
690 public function renderCheckoutPaymentMethods($attributes, $content, $block)
691 {
692 $cart = $this->getCart();
693 if (empty(Arr::get($cart, 'cart_data', []))) {
694 return '';
695 }
696 $atts = get_block_wrapper_attributes([
697 'class' => 'fct_checkout_payment_methods',
698 'data-fluent-cart-checkout-payment-methods' => ''
699 ]);
700 ob_start(); ?>
701 <div <?php echo $atts; ?>>
702 <?php
703 (new CheckoutRenderer($cart))->renderPaymentMethods();
704 ?>
705 </div>
706 <?php
707 return ob_get_clean();
708 }
709
710 public function renderCheckoutEuVat($attributes, $content, $block)
711 {
712 $cart = $this->getCart();
713 if (empty(Arr::get($cart, 'cart_data', []))) {
714 return '';
715 }
716
717 ob_start();
718 do_action('fluent_cart/before_payment_methods', ['cart' => $cart]);
719 $output = ob_get_clean();
720
721 if (empty(trim($output))) {
722 return '';
723 }
724
725 $atts = get_block_wrapper_attributes();
726
727 return sprintf('<div %s>%s</div>', $atts, $output);
728 }
729
730 public function renderCheckoutAgreeTermsField($attributes, $content, $block)
731 {
732 $cart = $this->getCart();
733 if (empty(Arr::get($cart, 'cart_data', []))) {
734 return '';
735 }
736 $title = Arr::get($attributes, 'terms_title');
737 $atts = get_block_wrapper_attributes();
738 ob_start();
739 ?>
740 <div <?php echo $atts; ?>>
741 <?php
742 (new CheckoutRenderer($cart))->agreeTerms([
743 'title' => $title,
744 'wrapper_atts'=> $atts,
745 ]);
746 ?>
747 </div>
748 <?php
749 return ob_get_clean();
750 }
751
752 public function renderCheckoutSubmitButton($attributes, $content, $block)
753 {
754 $cart = $this->getCart();
755 if (empty(Arr::get($cart, 'cart_data', []))) {
756 return '';
757 }
758
759 $atts = get_block_wrapper_attributes();
760 ob_start();
761 (new CheckoutRenderer($cart))->renderCheckoutButton($atts);
762 return ob_get_clean();
763 }
764
765 public function renderCheckoutOrderNotesField($attributes, $content, $block)
766 {
767 $cart = $this->getCart();
768 if (empty(Arr::get($cart, 'cart_data', []))) {
769 return '';
770 }
771 $atts = get_block_wrapper_attributes();
772 $title = Arr::get($attributes, 'title');
773 ob_start();
774 ?>
775 <div <?php echo $atts; ?>>
776 <?php (new CheckoutRenderer($cart))->renderOrderNoteField($title); ?>
777 </div>
778 <?php
779 return ob_get_clean();
780 }
781
782 public function renderCheckoutSummary($attributes, $content, $block)
783 {
784 $cart = $this->getCart();
785 if (empty(Arr::get($cart, 'cart_data', []))) {
786 return '';
787 }
788 $atts = get_block_wrapper_attributes([
789 'class' => 'fct_checkout_summary'
790 ]);
791
792 ob_start();
793 ?>
794 <div <?php echo $atts; ?>>
795 <div class="fct_summary active" data-fluent-cart-checkout-page-checkout-form-order-summary>
796 <?php (new CartSummaryRender($cart))->render(); ?>
797 </div>
798 </div>
799 <?php
800 return ob_get_clean();
801 }
802
803 public function renderCheckoutOrderSummary($attributes, $content, $block)
804 {
805 $cart = $this->getCart();
806 if (empty(Arr::get($cart, 'cart_data', []))) {
807 return '';
808 }
809 $atts = get_block_wrapper_attributes([
810 'class' => 'fct_items_wrapper',
811 'data-fluent-cart-checkout-item-wrapper' => ''
812 ]);
813 ob_start();
814 ?>
815 <div <?php echo $atts; ?>>
816 <?php
817 (new CartSummaryRender($cart))->renderItemsLists();
818 ?>
819 </div>
820 <?php
821 return ob_get_clean();
822 }
823
824 public function renderCheckoutSummaryFooter($attributes, $content, $block)
825 {
826 $cart = $this->getCart();
827 if (empty(Arr::get($cart, 'cart_data', []))) {
828 return '';
829 }
830 $innerBlocksContent = '';
831 if ($block instanceof \WP_Block && !empty($block->inner_blocks)) {
832 ob_start();
833 ?>
834 <div class="fct_summary_items">
835 <ul class="fct_summary_items_list">
836 <?php
837 $hasFeeBlock = false;
838 foreach ($block->inner_blocks as $inner_block) {
839 if (isset($inner_block->parsed_block)) {
840 if (Arr::get($inner_block->parsed_block, 'blockName') === 'fluent-cart/checkout-fees') {
841 $hasFeeBlock = true;
842 }
843 // Auto-render fees before the Coupon block if no explicit fees block exists
844 if (!$hasFeeBlock && Arr::get($inner_block->parsed_block, 'blockName') === 'fluent-cart/checkout-coupon') {
845 (new CartSummaryRender($cart))->renderFees();
846 $hasFeeBlock = true;
847 }
848 echo $inner_block->render();
849 }
850 }
851 // Fallback: render fees at the end if no fees block and no coupon block existed
852 if (!$hasFeeBlock) {
853 (new CartSummaryRender($cart))->renderFees();
854 }
855 ?>
856 </ul>
857 </div>
858 <?php
859 $innerBlocksContent = ob_get_clean();
860 }
861
862 return $innerBlocksContent;
863 }
864
865 public function renderCheckoutSubtotal($attributes, $content, $block)
866 {
867 $cart = $this->getCart();
868 if (empty(Arr::get($cart, 'cart_data', []))) {
869 return '';
870 }
871 $atts = get_block_wrapper_attributes();
872 ob_start();
873 (new CartSummaryRender($cart))->renderSubtotal($atts);
874 return ob_get_clean();
875 }
876
877 public function renderCheckoutShipping($attributes, $content, $block)
878 {
879 $cart = $this->getCart();
880 if (empty(Arr::get($cart, 'cart_data', []))) {
881 return '';
882 }
883 $atts = get_block_wrapper_attributes([
884 'class' => $cart->getShippingTotal() === 0 ? 'shipping-charge-hidden' : '',
885 'data-fluent-cart-checkout-shipping-amount-wrapper' => ''
886 ]);
887 ob_start();
888 (new CartSummaryRender($cart))->renderShipping($atts);
889 return ob_get_clean();
890 }
891
892 public function renderCheckoutFees($attributes, $content, $block)
893 {
894 $cart = $this->getCart();
895 if (empty(Arr::get($cart, 'cart_data', []))) {
896 return '';
897 }
898 ob_start();
899 (new CartSummaryRender($cart))->renderFees();
900 return ob_get_clean();
901 }
902
903 public function renderCheckoutCoupon($attributes, $content, $block)
904 {
905 $cart = $this->getCart();
906 if (empty(Arr::get($cart, 'cart_data', []))) {
907 return '';
908 }
909 $atts = get_block_wrapper_attributes([
910 'data-fluent-cart-checkout-page-applied-coupon' => ''
911 ]);
912 ob_start();
913 ?>
914 <li <?php echo $atts; ?>>
915 <?php
916 (new CartSummaryRender($cart))->showCouponField();
917 ?>
918 </li>
919 <?php
920 return ob_get_clean();
921 }
922
923 public function renderCheckoutManualDiscount($attributes, $content, $block)
924 {
925 $cart = $this->getCart();
926 if (empty(Arr::get($cart, 'cart_data', []))) {
927 return '';
928 }
929 $atts = get_block_wrapper_attributes();
930 ob_start();
931 (new CartSummaryRender($cart))->showManualDiscount($atts);
932 return ob_get_clean();
933 }
934
935 public function renderCheckoutTax($attributes, $content, $block)
936 {
937 $cart = $this->getCart();
938 if (empty(Arr::get($cart, 'cart_data', []))) {
939 return '';
940 }
941 $atts = get_block_wrapper_attributes();
942 ob_start();
943 (new TaxModule())->renderTaxRow($cart, $atts);
944 return ob_get_clean();
945 }
946
947 public function renderCheckoutShippingTax($attributes, $content, $block)
948 {
949 $cart = $this->getCart();
950 if (empty(Arr::get($cart, 'cart_data', []))) {
951 return '';
952 }
953 $atts = get_block_wrapper_attributes();
954 ob_start();
955 (new TaxModule())->renderShippingTaxRow($cart, $atts);
956 return ob_get_clean();
957 }
958
959 public function renderCheckoutTotal($attributes, $content, $block)
960 {
961 $cart = $this->getCart();
962 if (empty(Arr::get($cart, 'cart_data', []))) {
963 return '';
964 }
965 $atts = get_block_wrapper_attributes([
966 'class' => 'fct_summary_items_total',
967 'data-fluent-cart-checkout-page-current-total' => ''
968 ]);
969 ob_start();
970 (new CartSummaryRender($cart))->renderTotal($atts);
971 return ob_get_clean();
972 }
973
974 public function renderCheckoutOrderBump($attributes, $content, $block)
975 {
976 if (!App::isProActive() || !ModuleSettings::isActive('order_bump')) {
977 return '';
978 }
979
980 $cart = $this->getCart();
981 if (empty(Arr::get($cart, 'cart_data', []))) {
982 return '';
983 }
984 $atts = get_block_wrapper_attributes();
985 $title = Arr::get($attributes, 'section_title');
986 ob_start();
987 ?>
988 <div <?php echo $atts; ?>>
989 <?php
990 (new OrderBumpBoot())->maybeShowBumps([
991 'cart' => $cart,
992 'section_title' => $title
993 ]);
994 ?>
995 </div>
996 <?php
997 return ob_get_clean();
998 }
999
1000
1001 protected function getLocalizationKey(): string
1002 {
1003 return 'fluent_cart_checkout_inner_blocks';
1004 }
1005
1006 public function localizeData(): array
1007 {
1008 return [
1009 $this->getLocalizationKey() => [
1010 'blocks' => Arr::except($this->getInnerBlocks(), ['callback']),
1011 ],
1012 'fluentcart_single_product_vars' => [
1013 'trans' => TransStrings::singleProductPageString(),
1014 'cart_button_text' => App::storeSettings()->get('cart_button_text', __('Add To Cart', 'fluent-cart')),
1015 'out_of_stock_button_text' => App::storeSettings()->get('out_of_stock_button_text', __('Not Available', 'fluent-cart')),
1016 'in_stock_status' => Helper::IN_STOCK,
1017 'out_of_stock_status' => Helper::OUT_OF_STOCK,
1018 'enable_image_zoom' => (new StoreSettings())->get('enable_image_zoom_in_single_product'),
1019 'enable_image_zoom_in_modal' => (new StoreSettings())->get('enable_image_zoom_in_modal')
1020 ]
1021 ];
1022 }
1023
1024
1025 public function getStyles(): array
1026 {
1027 return [
1028 'public/checkout/style/checkout.scss',
1029 'public/components/select/style/style.scss'
1030 ];
1031 }
1032
1033 public function getScripts(): array
1034 {
1035 $scripts = [
1036 [
1037 'source' => 'admin/BlockEditor/ReactSupport.js',
1038 'dependencies' => ['wp-blocks', 'wp-components']
1039 ],
1040 [
1041 'source' => 'admin/BlockEditor/Checkout/InnerBlocks/InnerBlocks.jsx',
1042 'dependencies' => ['wp-blocks', 'wp-components', 'wp-block-editor']
1043 ]
1044 ];
1045
1046 return $scripts;
1047 }
1048
1049 protected function generateEnqueueSlug(): string
1050 {
1051 return 'fluent_cart_checkout_inner_blocks';
1052 }
1053
1054 }
1055