PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.8.0
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.8.0
1.8.0 1.7.1 1.7.0 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 All 52 releases
fluent-cart / app / Services / Renderer / CartSummaryRender.php

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

469 lines 18.9 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 // The same filter getEstimatedTotal() runs before summing. A rule
94 // discount lives only in the filtered copy — reading cart_data here
95 // would price the lines above the total shown underneath them.
96 $items = apply_filters('fluent_cart/cart/item_dynamic_discount', $items, [
97 'cart' => $this->cart,
98 ]);
99 ?>
100 <div class="fct_line_items">
101 <?php foreach ($items as $item) {
102 (new CartItemRenderer($item, $this->cart))->render();
103 }
104 ?>
105 </div>
106 <?php
107 }
108
109 public function renderItemsFooter()
110 {
111 $hideCouponField = (new StoreSettings())->get('hide_coupon_field') === 'yes';
112 $hideCouponField = $hideCouponField || Arr::get($this->cart->checkout_data, 'disable_coupons', 'no') === 'yes';
113 ?>
114 <div class="fct_summary_items">
115 <ul class="fct_summary_items_list">
116 <?php
117 $this->renderSubtotal();
118 ?>
119
120 <?php $this->maybeShowCustomCartSummaries(); ?>
121
122 <?php if ($this->cart->requireShipping()):
123 $this->renderShipping();
124 ?>
125 <?php endif ?>
126
127 <?php $this->renderFees(); ?>
128
129 <?php
130 $extraLines = apply_filters('fluent_cart/checkout/summary_extra_lines', [], [
131 'cart' => $this->cart,
132 ]);
133
134 if (!is_array($extraLines)) {
135 $extraLines = [];
136 }
137
138 foreach ($extraLines as $extraLine) :
139 if (!is_array($extraLine) || !isset($extraLine['label'], $extraLine['amount'])) {
140 continue;
141 }
142 ?>
143 <li>
144 <span class="fct_summary_label"><?php echo esc_html($extraLine['label']); ?></span>
145 <span class="fct_summary_value"><?php echo esc_html(Helper::toDecimal($extraLine['amount'])); ?></span>
146 </li>
147 <?php endforeach; ?>
148
149 <?php do_action('fluent_cart/checkout/before_summary_coupon', [ 'cart' => $this->cart ]);
150 ?>
151
152 <li data-fluent-cart-checkout-page-applied-coupon>
153 <?php $this->showCouponApplied(); ?>
154 </li>
155
156 <?php if (!$hideCouponField): ?>
157 <li>
158 <?php $this->showCouponField(); ?>
159 </li>
160 <?php endif ?>
161
162 <?php do_action('fluent_cart/checkout/before_summary_total', [ 'cart' => $this->cart ]); ?>
163
164 <?php $this->showUpgradeDiscount(); ?>
165 <?php $this->showProrateCredit(); ?>
166 <?php $this->showManualDiscount(); ?>
167
168 <?php
169 $this->renderTotal();
170 ?>
171 </ul>
172 </div>
173 <?php
174 }
175
176 public function renderSubtotal($atts = '')
177 {
178 ?>
179 <li <?php echo $atts; ?>>
180 <span class="fct_summary_label"> <?php esc_html_e('Subtotal', 'fluent-cart'); ?></span>
181 <span class="fct_summary_value" data-fluent-cart-checkout-subtotal>
182 <?php echo esc_html(Helper::toDecimal($this->cart->getItemsSubtotal())); ?>
183 </span>
184 </li>
185 <?php
186 }
187
188 public function renderShipping($atts = '')
189 {
190 if ($atts) {
191 echo '<li ' . $atts . '>';
192 } else {
193 echo '<li class="' . ($this->cart->getShippingTotal() === 0 ? 'shipping-charge-hidden' : '') . '" data-fluent-cart-checkout-shipping-amount-wrapper>';
194 }
195 ?>
196 <span class="fct_summary_label"><?php esc_html_e('Shipping', 'fluent-cart'); ?></span>
197 <span class="fct_summary_value" data-fluent-cart-checkout-shipping-amount data-shipping-method-id="">
198 <?php
199 echo esc_html(Helper::toDecimal($this->cart->getShippingTotal()));
200 ?>
201 </span>
202 <?php
203 echo '</li>';
204 }
205
206 public function renderFees()
207 {
208 $fees = $this->cart->getFees();
209 if (empty($fees)) {
210 return;
211 }
212 foreach ($fees as $fee) {
213 ?>
214 <li class="fct_fee_row" data-fluent-cart-checkout-fee="<?php echo esc_attr($fee['key']); ?>">
215 <span class="fct_summary_label"><?php echo esc_html($fee['label']); ?></span>
216 <span class="fct_summary_value" data-fluent-cart-checkout-fee-amount="<?php echo esc_attr($fee['key']); ?>">
217 <?php echo esc_html(Helper::toDecimal($fee['amount'])); ?>
218 </span>
219 </li>
220 <?php
221 }
222 }
223
224 public function renderTotal($atts = '')
225 {
226 ?>
227 <li <?php echo empty($atts) ? ' class="fct_summary_items_total" data-fluent-cart-checkout-page-current-total' : $atts; ?>>
228 <span class="fct_summary_label"><?php _e('Total','fluent-cart'); ?></span>
229 <span class="fct_summary_value" data-fluent-cart-checkout-estimated-total>
230 <?php
231 echo esc_html(Helper::toDecimal($this->cart->getEstimatedTotal()));
232 ?>
233 </span>
234 </li>
235 <?php
236 }
237
238 public function maybeShowCustomCartSummaries()
239 {
240 $isCustomCheckout = Arr::get($this->cart->checkout_data, 'custom_checkout') === 'yes';
241 if (!$isCustomCheckout) {
242 return '';
243 }
244
245 $customerDiscountAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.discount_total', 0);
246 $formattedCustomDiscountAmount = Helper::toDecimal($customerDiscountAmount);
247 $customShippingAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.shipping_total', 0);
248 $formattedCustomShippingAmount = Helper::toDecimal($customShippingAmount);
249
250 $checkoutShippingData = $this->cart->checkout_data['shipping_data'] ?? [];
251 $shippingMethodId = Arr::get($checkoutShippingData, 'shipping_method_id', '');
252 $shippingCharge = Arr::get($checkoutShippingData, 'shipping_charge', 0); // checking if shipping charge is again set from checkout
253
254 ?>
255 <?php if ($customerDiscountAmount) {
256 $this->renderDiscountDetailRow();
257 }
258 if ($customShippingAmount && !$shippingCharge){
259 $this->renderShippingDetailRow();
260 }
261 }
262
263 public function renderDiscountDetailRow()
264 {
265 $customerDiscountAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.discount_total', 0);
266 $formattedCustomDiscountAmount = Helper::toDecimal($customerDiscountAmount);
267 ?>
268 <li>
269 <span class="fct_summary_label"> <?php esc_html_e('Discount', 'fluent-cart'); ?></span>
270 <span class="fct_summary_value" data-fluent-cart-checkout-subtotal>
271 -<?php echo esc_html($formattedCustomDiscountAmount); ?>
272 </span>
273 </li>
274 <?php
275 }
276
277 public function renderShippingDetailRow()
278 {
279 $customShippingAmount = Arr::get($this->cart->checkout_data, 'custom_checkout_data.shipping_total', 0);
280 $formattedCustomShippingAmount = Helper::toDecimal($customShippingAmount);
281 ?>
282 <li>
283 <span class="fct_summary_label"> <?php esc_html_e('Shipping', 'fluent-cart'); ?></span>
284 <span class="fct_summary_value" data-fluent-cart-checkout-subtotal>
285 <?php echo esc_html($formattedCustomShippingAmount); ?>
286 </span>
287 </li>
288 <?php
289 }
290
291 public function showCouponApplied()
292 {
293 $discounts = $this->cart->getDiscountLines();
294
295 if (!$discounts) {
296 return;
297 }
298
299 ?>
300
301 <div class="fct_coupon_applied" data-fluent-cart-checkout-page-discount-container>
302 <?php foreach ($discounts as $couponCode => $discount_data): ?>
303 <div class="fct_coupon_applied_item">
304 <div class="fct_coupon_info">
305 <span class="fct_coupon">
306 <svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 16 16" fill="none">
307 <ellipse cx="1" cy="1" rx="1" ry="1" transform="matrix(1 0 0 -1 10.6667 5.3335)" stroke="#2F3448"
308 stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
309 <path
310 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"
311 stroke="#2F3448" stroke-width="1.5"/>
312 <path d="M4.66669 9.3335L6.66669 11.3335" stroke="#2F3448" stroke-width="1.5"
313 stroke-linecap="round" stroke-linejoin="round"/>
314 </svg>
315
316 <?php echo esc_html($discount_data['formatted_title']) ?>
317 </span>
318 <a
319 href="#"
320 class="fct_remove_coupon"
321 data-remove-coupon
322 data-coupon="<?php echo esc_attr($couponCode); ?>"
323 >
324 <?php echo esc_html__('Remove', 'fluent-cart'); ?>
325 </a>
326 </div>
327 <div class="fct_coupon_price">
328 &#8211; <?php echo esc_html($discount_data['actual_formatted_discount']) ?>
329 </div>
330 </div>
331 <?php endforeach; ?>
332 </div>
333
334 <?php
335 }
336
337 public function showManualDiscount($atts = '')
338 {
339 $manualDiscount = Arr::get($this->cart->checkout_data, 'manual_discount', []);
340
341 if (!$manualDiscount || !Arr::get($manualDiscount, 'amount', 0)) {
342 return;
343 }
344
345 $title = Arr::get($manualDiscount, 'title', __('Manual Discount', 'fluent-cart'));
346 $amount = Arr::get($manualDiscount, 'amount', 0);
347 $formattedAmount = Helper::toDecimal($amount);
348 ?>
349 <li>
350 <span class="fct_summary_label" aria-label="<?php echo esc_attr($title); ?>"> <?php echo esc_html($title); ?></span>
351 <span class="fct_summary_value" data-fluent-cart-checkout-manual-discount aria-label="<?php echo esc_attr($formattedAmount); ?>">
352 -<?php echo esc_html($formattedAmount); ?>
353 </span>
354 </li>
355 <?php
356 }
357
358 public function showUpgradeDiscount($atts = '')
359 {
360 $upgradeDiscount = Arr::get($this->cart->checkout_data, 'upgrade_discount', []);
361
362 if (!$upgradeDiscount || !Arr::get($upgradeDiscount, 'amount', 0)) {
363 return;
364 }
365
366 $title = Arr::get($upgradeDiscount, 'title', __('Upgrade Discount', 'fluent-cart'));
367 $amount = Arr::get($upgradeDiscount, 'amount', 0);
368 $formattedAmount = Helper::toDecimal($amount);
369 ?>
370 <li>
371 <span class="fct_summary_label" aria-label="<?php echo esc_attr($title); ?>"> <?php echo esc_html($title); ?></span>
372 <span class="fct_summary_value" data-fluent-cart-checkout-upgrade-discount aria-label="<?php echo esc_attr($formattedAmount); ?>">
373 -<?php echo esc_html($formattedAmount); ?>
374 </span>
375 </li>
376 <?php
377 }
378
379 public function showProrateCredit($atts = '')
380 {
381 $prorateCredit = Arr::get($this->cart->checkout_data, 'prorate_credit', []);
382
383 if (!$prorateCredit || !Arr::get($prorateCredit, 'amount', 0)) {
384 return;
385 }
386
387 $title = Arr::get($prorateCredit, 'title', __('Prorate Credit', 'fluent-cart'));
388 $amount = Arr::get($prorateCredit, 'amount', 0);
389 $formattedAmount = Helper::toDecimal($amount);
390 ?>
391 <li>
392 <span class="fct_summary_label" aria-label="<?php echo esc_attr($title); ?>"> <?php echo esc_html($title); ?></span>
393 <span class="fct_summary_value" data-fluent-cart-checkout-prorate-credit aria-label="<?php echo esc_attr($formattedAmount); ?>">
394 -<?php echo esc_html($formattedAmount); ?>
395 </span>
396 </li>
397 <?php
398 }
399
400 public function showCouponField()
401 {
402 ?>
403 <div class="fct_coupon">
404 <div class="fct_coupon_toggle">
405 <a
406 aria-expanded="false"
407 aria-controls="coupon_section"
408 href="#"
409 data-fluent-cart-checkout-page-coupon-field-toggle
410 >
411 <?php echo esc_html__('Have a Coupon?', 'fluent-cart'); ?>
412 </a>
413 </div>
414
415 <div
416 id="coupon_section"
417 class="fct_coupon_field"
418 hidden
419 data-fluent-cart-checkout-page-coupon-container
420 role="region"
421 aria-label="<?php esc_attr_e('Coupon entry area', 'fluent-cart'); ?>"
422 >
423 <label for="coupon" class="sr-only">
424 <?php echo esc_html__('Enter coupon code', 'fluent-cart'); ?>
425 </label>
426
427 <span class="fct_coupon_icon" aria-hidden="true">
428 <svg xmlns="http://www.w3.org/2000/svg" width="18" height="18" viewBox="0 0 18 18" fill="none">
429 <g clip-path="url(#clip0_3365_10538)">
430 <ellipse cx="1.125" cy="1.125" rx="1.125" ry="1.125" transform="matrix(1 0 0 -1 12 6)"
431 stroke="#8b8d9a" stroke-width="1.5" stroke-linecap="round"
432 stroke-linejoin="round"/>
433 <path
434 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"
435 stroke="#8b8d9a" stroke-width="1.5"/>
436 <path d="M5.25002 10.5L7.50002 12.75" stroke="#8b8d9a" stroke-width="1.5"
437 stroke-linecap="round" stroke-linejoin="round"/>
438 </g>
439 <defs>
440 <clipPath id="clip0_3365_10538">
441 <rect width="18" height="18" fill="white"/>
442 </clipPath>
443 </defs>
444 </svg>
445 </span>
446
447 <div data-fluent-cart-checkout-page-form-input-wrapper class="fct_coupon_input_wrapper">
448 <input
449 class="fct_coupon_input"
450 type=text
451 name=coupon
452 placeholder="<?php esc_attr_e('Apply Here', 'fluent-cart'); ?>"
453 data-required=no
454 data-type=input
455 id=coupon
456 autocomplete="off"
457 />
458 </div>
459
460 <button type='submit' data-fluent-cart-checkout-page-coupon-validate>
461 <?php echo esc_html__('Apply', 'fluent-cart'); ?>
462 </button>
463 </div>
464 </div>
465 <?php
466 }
467
468 }
469