PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.21
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.21
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 trunk All 48 releases
fluent-cart / app / Services / Renderer / ShippingMethodsRender.php

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

143 lines 5.5 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\App\Helpers\Helper;
6 use FluentCart\Framework\Support\Arr;
7
8 class ShippingMethodsRender
9 {
10 protected $shippingMethods = [];
11
12 protected $selectedId = null;
13
14 public function __construct($shippingMethods = [], $selectedId = null)
15 {
16 $this->shippingMethods = $shippingMethods;
17 $this->selectedId = $selectedId;
18 }
19
20 public function render()
21 {
22 $errorId = 'shipping-methods-error';
23
24 ?>
25 <div class="fct_shipping_methods" id="shipping_methods" data-fluent-cart-checkout-page-shipping-methods-wrapper>
26 <div class="fct_checkout_form_section" aria-describedby="<?php echo esc_attr($errorId); ?>">
27 <div class="fct_form_section_header">
28 <h4 id="shipping-methods-title" class="fct_form_section_header_label">
29 <?php echo esc_html__('Shipping Options', 'fluent-cart') ?>
30 </h4>
31 </div>
32 <div class="fct_form_section_body">
33 <?php $this->renderBody(); ?>
34 </div>
35 <span
36 id="<?php echo esc_attr($errorId); ?>"
37 data-fluent-cart-checkout-page-form-error=""
38 class="fct_form_error"
39 role="alert"
40 aria-live="polite"
41 ></span>
42 </div>
43 </div>
44 <?php
45 }
46
47 public function renderBody()
48 {
49 if (is_wp_error($this->shippingMethods)) {
50 $this->renderEmpty($this->shippingMethods->get_error_message());
51 } else if ($this->shippingMethods) {
52 $this->renderMethods();
53 } else {
54 $this->renderEmptyState();
55 }
56 }
57
58 public function renderEmptyState()
59 {
60 ?>
61 <div class="fct-empty-state" role="alert">
62 <?php echo esc_html__('No shipping methods available for this address.', 'fluent-cart') ?>
63 </div>
64 <?php
65 }
66
67 public function renderMethods()
68 {
69 if (is_wp_error($this->shippingMethods)) {
70 return;
71 }
72 $errorId = 'shipping-methods-error';
73 ?>
74 <div
75 class="fct_shipping_methods_list"
76 data-fluent-cart-checkout-page-shipping-method-wrapper
77 role="radiogroup"
78 aria-labelledby="shipping-methods-title"
79 aria-describedby="<?php echo esc_attr($errorId); ?>"
80 >
81 <?php $this->renderLoader(); ?>
82
83 <input type="hidden" name="fc_selected_shipping_method" value="<?php echo esc_attr($this->selectedId); ?>">
84 <?php foreach ($this->shippingMethods as $shippingMethod) : ?>
85 <div class="fct_shipping_methods_item">
86 <input
87 type="radio"
88 <?php echo checked($this->selectedId, $shippingMethod->id); ?>
89 name="fc_shipping_method"
90 id="shipping_method_<?php echo esc_attr($shippingMethod->id); ?>"
91 value="<?php echo esc_attr($shippingMethod->id); ?>"
92 />
93 <label for="shipping_method_<?php echo esc_attr($shippingMethod->id); ?>">
94 <?php
95 $description = Arr::get($shippingMethod->meta, 'description', '');
96 ?>
97 <?php echo esc_html($shippingMethod->title); ?>
98 <span class="shipping-method-amount" aria-label="<?php
99 /* translators: %s charge amount */
100 printf(esc_attr__('Shipping cost: %s', 'fluent-cart'),
101 esc_html(Helper::toDecimal($shippingMethod->charge_amount))); ?>"
102 >
103 <?php echo esc_html(Helper::toDecimal($shippingMethod->charge_amount)); ?>
104 </span>
105 <span class="fct-checkmark" aria-hidden="true"></span>
106 <?php if (!empty($description)) : ?>
107 <small class="fct_shipping_method_description"><?php echo esc_html($description); ?></small>
108 <?php endif; ?>
109 </label>
110 </div>
111 <?php endforeach; ?>
112 </div>
113 <?php
114 // do_action('fluent_cart/views/checkout_page_shipping_method_list', [
115 // 'shipping_methods' => $this->shippingMethods
116 // ]);
117 }
118
119 public function renderEmpty($message)
120 {
121 ?>
122 <div class="fct-empty-state" role="alert">
123 <?php echo wp_kses_post($message); ?>
124 </div>
125 <?php
126 }
127
128 public function renderLoader()
129 {
130 ?>
131 <div class="fct_shipping_methods_loader">
132 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 24 24">
133 <circle cx="12" cy="12" r="10" opacity="0.2" fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="2.5"></circle>
134
135 <path d="m12,2c5.52,0,10,4.48,10,10" fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2.5">
136 <animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="0.5s" from="0 12 12" to="360 12 12" repeatCount="indefinite"></animateTransform>
137 </path>
138 </svg>
139 </div>
140 <?php
141 }
142 }
143