PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.3.23
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.3.23
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 / CartSummaryRender.php

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

415 lines 16.6 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\Api\StoreSettings;
6 use FluentCart\App\Helpers\Helper;
7 use FluentCart\App\Models\Cart;
8 use FluentCart\App\Services\Tax\TaxManager;
9 use FluentCart\Framework\Support\Arr;
10
11 class CartSummaryRender
12 {
13
14 protected $cart;
15
16 public function __construct(Cart $cart)
17 {
18 $this->cart = $cart;
19 }
20
21 public function render($withWrapper = true)
22 {
23 if (!$this->cart) {
24 return '';
25 }
26 ?>
27 <?php if($withWrapper): ?>
28 <div class="fct_summary_box" data-fluent-cart-checkout-page-cart-items-wrapper>
29 <?php endif; ?>
30 <div class="fct_checkout_form_section">
31 <?php $this->renderOrderSummarySectionHeading(); ?>
32
33
34 <div class="fct_form_section_body" id="order_summary_panel" role="region" aria-labelledby="order_summary_label">
35 <div class="fct_form_section_body_inner">
36 <div data-fluent-cart-checkout-item-wrapper class="fct_items_wrapper">
37 <?php $this->renderItemsLists(); ?>
38 </div>
39 <?php $this->renderItemsFooter(); ?>
40 </div>
41 </div><!-- .fct_form_section_body -->
42 </div>
43 <?php if($withWrapper): ?>
44 </div>
45 <?php endif; ?>
46 <?php
47 }
48
49 public function renderOrderSummarySectionHeading()
50 {
51 ?>
52 <div class="fct_form_section_header" role="heading" aria-level="2">
53 <div
54 data-fluent-cart-checkout-cart-items-toggle
55 class="fct_toggle_content"
56 aria-expanded="true"
57 aria-controls="order_summary_panel"
58 >
59 <h4 id="order_summary_label"><?php echo __('Order summary', 'fluent-cart'); ?></h4>
60 <div class="fct_toggle_icon" aria-hidden="true">
61 <svg xmlns="http://www.w3.org/2000/svg" width="10" height="6" viewBox="0 0 10 6"
62 fill="none">
63 <path
64 d="M1 1L4.29289 4.29289C4.62623 4.62623 4.79289 4.79289 5 4.79289C5.20711 4.79289 5.37377 4.62623 5.70711 4.29289L9 1"
65 stroke="currentColor" stroke-width="1.5" stroke-linecap="round"
66 stroke-linejoin="round"></path>
67 </svg>
68 </div>
69 </div><!-- .fct_toggle_content -->
70
71 <div class="fct_summary_toggle_total">
72 <span
73 id="order_summary_total"
74 class="value"
75 data-fluent-cart-checkout-estimated-total
76 aria-labelledby="order_summary_label"
77 >
78 <?php
79 echo esc_html(Helper::toDecimal($this->cart->getEstimatedTotal())); ?>
80 </span>
81 </div>
82 </div><!-- .fct_form_section_header -->
83 <?php
84 }
85
86 public function renderItemsLists()
87 {
88 $items = $this->cart->cart_data;
89 if (!$items) {
90 return '';
91 }
92 ?>
93 <div class="fct_line_items">
94 <?php foreach ($items as $item) {
95 (new CartItemRenderer($item, $this->cart))->render();
96 }
97 ?>
98 </div>
99 <?php
100 }
101
102 public function renderItemsFooter()
103 {
104 $hideCouponField = (new StoreSettings())->get('hide_coupon_field') === 'yes';
105 $hideCouponField = $hideCouponField || Arr::get($this->cart->checkout_data, 'disable_coupons', 'no') === 'yes';
106 ?>
107 <div class="fct_summary_items">
108 <ul class="fct_summary_items_list">
109 <?php
110 $this->renderSubtotal();
111 ?>
112
113 <?php $this->maybeShowCustomCartSummaries(); ?>
114
115 <?php if ($this->cart->requireShipping()):
116 $this->renderShipping();
117 ?>
118 <?php endif ?>
119
120 <?php $this->renderFees(); ?>
121
122 <?php
123 $extraLines = apply_filters('fluent_cart/checkout/summary_extra_lines', [], [
124 'cart' => $this->cart,
125 ]);
126
127 if (!is_array($extraLines)) {
128 $extraLines = [];
129 }
130
131 foreach ($extraLines as $extraLine) :
132 if (!is_array($extraLine) || !isset($extraLine['label'], $extraLine['amount'])) {
133 continue;
134 }
135 ?>
136 <li>
137 <span class="fct_summary_label"><?php echo esc_html($extraLine['label']); ?></span>
138 <span class="fct_summary_value"><?php echo esc_html(Helper::toDecimal($extraLine['amount'])); ?></span>
139 </li>
140 <?php endforeach; ?>
141
142 <li data-fluent-cart-checkout-page-applied-coupon>
143 <?php $this->showCouponApplied(); ?>
144 </li>
145
146 <?php $this->showManualDiscount(); ?>
147
148 <?php if (!$hideCouponField): ?>
149 <li>
150 <?php $this->showCouponField(); ?>
151 </li>
152 <?php endif ?>
153
154 <?php do_action('fluent_cart/checkout/before_summary_total', [ 'cart' => $this->cart ]); ?>
155
156 <?php
157 $this->renderTotal();
158 ?>
159 </ul>
160 </div>
161 <?php
162 }
163
164 public function renderSubtotal($atts = '')
165 {
166 ?>
167 <li <?php echo $atts; ?>>
168 <span class="fct_summary_label"> <?php esc_html_e('Subtotal', 'fluent-cart'); ?></span>
169 <span class="fct_summary_value" data-fluent-cart-checkout-subtotal>
170 <?php echo esc_html(Helper::toDecimal($this->cart->getItemsSubtotal())); ?>
171 </span>
172 </li>
173 <?php
174 }
175
176 public function renderShipping($atts = '')
177 {
178 if ($atts) {
179 echo '<li ' . $atts . '>';
180 } else {
181 echo '<li class="' . ($this->cart->getShippingTotal() === 0 ? 'shipping-charge-hidden' : '') . '" data-fluent-cart-checkout-shipping-amount-wrapper>';
182 }
183 ?>
184 <span class="fct_summary_label"><?php esc_html_e('Shipping', 'fluent-cart'); ?></span>
185 <span class="fct_summary_value" data-fluent-cart-checkout-shipping-amount data-shipping-method-id="">
186 <?php
187 echo esc_html(Helper::toDecimal($this->cart->getShippingTotal()));
188 ?>
189 </span>
190 <?php
191 echo '</li>';
192 }
193
194 public function renderFees()
195 {
196 $fees = $this->cart->getFees();
197 if (empty($fees)) {
198 return;
199 }
200 foreach ($fees as $fee) {
201 ?>
202 <li class="fct_fee_row" data-fluent-cart-checkout-fee="<?php echo esc_attr($fee['key']); ?>">
203 <span class="fct_summary_label"><?php echo esc_html($fee['label']); ?></span>
204 <span class="fct_summary_value" data-fluent-cart-checkout-fee-amount="<?php echo esc_attr($fee['key']); ?>">
205 <?php echo esc_html(Helper::toDecimal($fee['amount'])); ?>
206 </span>
207 </li>
208 <?php
209 }
210 }
211
212 public function renderTotal($atts = '')
213 {
214 ?>
215 <li <?php echo empty($atts) ? ' class="fct_summary_items_total" data-fluent-cart-checkout-page-current-total' : $atts; ?>>
216 <span class="fct_summary_label"><?php _e('Total','fluent-cart'); ?></span>
217 <span class="fct_summary_value" data-fluent-cart-checkout-estimated-total>
218 <?php
219 echo esc_html(Helper::toDecimal($this->cart->getEstimatedTotal()));
220 ?>
221 </span>
222 </li>
223 <?php
224 }
225
226 public function maybeShowCustomCartSummaries()
227 {
228 $isCustomCheckout = Arr::get($this->cart->checkout_data, 'custom_checkout') === 'yes';
229 if (!$isCustomCheckout) {
230 return '';
231 }
232
233 $customerDiscountAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.discount_total', 0);
234 $formattedCustomDiscountAmount = Helper::toDecimal($customerDiscountAmount);
235 $customShippingAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.shipping_total', 0);
236 $formattedCustomShippingAmount = Helper::toDecimal($customShippingAmount);
237
238 $checkoutShippingData = $this->cart->checkout_data['shipping_data'] ?? [];
239 $shippingMethodId = Arr::get($checkoutShippingData, 'shipping_method_id', '');
240 $shippingCharge = Arr::get($checkoutShippingData, 'shipping_charge', 0); // checking if shipping charge is again set from checkout
241
242 ?>
243 <?php if ($customerDiscountAmount) {
244 $this->renderDiscountDetailRow();
245 }
246 if ($customShippingAmount && !$shippingCharge){
247 $this->renderShippingDetailRow();
248 }
249 }
250
251 public function renderDiscountDetailRow()
252 {
253 $customerDiscountAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.discount_total', 0);
254 $formattedCustomDiscountAmount = Helper::toDecimal($customerDiscountAmount);
255 ?>
256 <li>
257 <span class="fct_summary_label"> <?php esc_html_e('Discount', 'fluent-cart'); ?></span>
258 <span class="fct_summary_value" data-fluent-cart-checkout-subtotal>
259 -<?php echo esc_html($formattedCustomDiscountAmount); ?>
260 </span>
261 </li>
262 <?php
263 }
264
265 public function renderShippingDetailRow()
266 {
267 $customShippingAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.shipping_total', 0);
268 $formattedCustomShippingAmount = Helper::toDecimal($customShippingAmount);
269 ?>
270 <li>
271 <span class="fct_summary_label"> <?php esc_html_e('Shipping', 'fluent-cart'); ?></span>
272 <span class="fct_summary_value" data-fluent-cart-checkout-subtotal>
273 <?php echo esc_html($formattedCustomShippingAmount); ?>
274 </span>
275 </li>
276 <?php
277 }
278
279 public function showCouponApplied()
280 {
281 $discounts = $this->cart->getDiscountLines();
282
283 if (!$discounts) {
284 return;
285 }
286
287 ?>
288
289 <div class="fct_coupon_applied" data-fluent-cart-checkout-page-discount-container>
290 <?php foreach ($discounts as $couponCode => $discount_data): ?>
291 <div class="fct_coupon_applied_item">
292 <div class="fct_coupon_info">
293 <span class="fct_coupon">
294 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 16 16" fill="none">
295 <ellipse cx="1" cy="1" rx="1" ry="1" transform="matrix(1 0 0 -1 10.6667 5.3335)" stroke="#2F3448"
296 stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
297 <path
298 d="M1.8495 7.42921C1.18073 8.17611 1.16635 9.30298 1.78012 10.0957C2.99809 11.6688 4.33117 13.0018 5.90423 14.2198C6.69694 14.8336 7.82382 14.8192 8.57072 14.1504C10.5986 12.3347 12.4557 10.4372 14.2479 8.35189C14.4251 8.14572 14.536 7.89304 14.5608 7.62234C14.6708 6.42524 14.8968 2.97637 13.9602 2.03975C13.0236 1.10313 9.57469 1.3291 8.37759 1.43909C8.10689 1.46397 7.8542 1.57481 7.64804 1.75199C5.56276 3.54422 3.66521 5.40132 1.8495 7.42921Z"
299 stroke="#2F3448" stroke-width="1.5"/>
300 <path d="M4.66669 9.3335L6.66669 11.3335" stroke="#2F3448" stroke-width="1.5"
301 stroke-linecap="round" stroke-linejoin="round"/>
302 </svg>
303
304 <?php echo esc_html($discount_data['formatted_title']) ?>
305 </span>
306 <a
307 href="#"
308 class="fct_remove_coupon"
309 data-remove-coupon
310 data-coupon="<?php echo esc_attr($couponCode); ?>"
311 >
312 <?php echo esc_html__('Remove', 'fluent-cart'); ?>
313 </a>
314 </div>
315 <div class="fct_coupon_price">
316 &#8211; <?php echo esc_html($discount_data['actual_formatted_discount']) ?>
317 </div>
318 </div>
319 <?php endforeach; ?>
320 </div>
321
322 <?php
323 }
324
325 public function showManualDiscount($atts = '')
326 {
327 $manualDiscount = Arr::get($this->cart->checkout_data, 'manual_discount', []);
328
329 if (!$manualDiscount || !Arr::get($manualDiscount, 'amount', 0)) {
330 return;
331 }
332
333 $title = Arr::get($manualDiscount, 'title', __('Manual Discount', 'fluent-cart'));
334 $amount = Arr::get($manualDiscount, 'amount', 0);
335 $formattedAmount = Helper::toDecimal($amount);
336 ?>
337 <li>
338 <span class="fct_summary_label" aria-label="<?php echo esc_attr($title); ?>"> <?php echo esc_html($title); ?></span>
339 <span class="fct_summary_value" data-fluent-cart-checkout-manual-discount aria-label="<?php echo esc_attr($formattedAmount); ?>">
340 -<?php echo esc_html($formattedAmount); ?>
341 </span>
342 </li>
343 <?php
344 }
345
346 public function showCouponField()
347 {
348 ?>
349 <div class="fct_coupon">
350 <div class="fct_coupon_toggle">
351 <a
352 aria-expanded="false"
353 aria-controls="coupon_section"
354 href="#"
355 data-fluent-cart-checkout-page-coupon-field-toggle
356 >
357 <?php echo esc_html__('Have a Coupon?', 'fluent-cart'); ?>
358 </a>
359 </div>
360
361 <div
362 id="coupon_section"
363 class="fct_coupon_field"
364 hidden
365 data-fluent-cart-checkout-page-coupon-container
366 role="region"
367 aria-label="<?php esc_attr_e('Coupon entry area', 'fluent-cart'); ?>"
368 >
369 <label for="coupon" class="sr-only">
370 <?php echo esc_html__('Enter coupon code', 'fluent-cart'); ?>
371 </label>
372
373 <span class="fct_coupon_icon" aria-hidden="true">
374 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
375 <g clip-path="url(#clip0_3365_10538)">
376 <ellipse cx="1.125" cy="1.125" rx="1.125" ry="1.125" transform="matrix(1 0 0 -1 12 6)"
377 stroke="#8b8d9a" stroke-width="1.5" stroke-linecap="round"
378 stroke-linejoin="round"/>
379 <path
380 d="M2.08067 8.35795C1.32831 9.19822 1.31213 10.4659 2.00262 11.3578C3.37284 13.1274 4.87255 14.6272 6.64225 15.9974C7.53405 16.6879 8.80178 16.6717 9.64205 15.9193C11.9234 13.8766 14.0127 11.7419 16.0289 9.39596C16.2282 9.16403 16.3529 8.87976 16.3809 8.57522C16.5047 7.22849 16.7589 3.3485 15.7052 2.29481C14.6515 1.24111 10.7715 1.49532 9.42478 1.61907C9.12024 1.64706 8.83597 1.77175 8.60404 1.97109C6.25809 3.98734 4.12335 6.07658 2.08067 8.35795Z"
381 stroke="#8b8d9a" stroke-width="1.5"/>
382 <path d="M5.25002 10.5L7.50002 12.75" stroke="#8b8d9a" stroke-width="1.5"
383 stroke-linecap="round" stroke-linejoin="round"/>
384 </g>
385 <defs>
386 <clipPath id="clip0_3365_10538">
387 <rect width="18" height="18" fill="white"/>
388 </clipPath>
389 </defs>
390 </svg>
391 </span>
392
393 <div data-fluent-cart-checkout-page-form-input-wrapper class="fct_coupon_input_wrapper">
394 <input
395 class="fct_coupon_input"
396 type=text
397 name=coupon
398 placeholder="<?php esc_attr_e('Apply Here', 'fluent-cart'); ?>"
399 data-required=no
400 data-type=input
401 id=coupon
402 autocomplete="off"
403 />
404 </div>
405
406 <button type='submit' data-fluent-cart-checkout-page-coupon-validate>
407 <?php echo esc_html__('Apply', 'fluent-cart'); ?>
408 </button>
409 </div>
410 </div>
411 <?php
412 }
413
414 }
415