PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.6
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.6
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
← All changes | app/Services/Renderer/CartItemRenderer.php +145 -28 1.3.21 → 1.6.6 View file →
@@ -4,8 +4,9 @@
4 4
5 5 use FluentCart\App\Helpers\Helper;
6 6 use FluentCart\App\Models\Cart;
7 7 use FluentCart\Framework\Support\Arr;
8 +use FluentCart\App\Vite;
8 9
9 10 class CartItemRenderer
10 11 {
11 12 protected $item = [];
@@ -49,31 +50,55 @@
49 50 $promoPriceOriginal = $promoPriceOriginal * Arr::get($this->item, 'quantity', 1);
50 51 } else {
51 52 $promoPriceOriginal = '';
52 53 }
54 +
55 + $couponDiscount = (int) Arr::get($this->item, 'coupon_discount', 0);
56 + $lineTotal = (int) Arr::get($this->item, 'line_total', 0);
57 + $subtotal = (int) Arr::get($this->item, 'subtotal', 0);
58 + $hasCouponDiscount = $couponDiscount > 0 && $lineTotal < $subtotal;
53 59 ?>
54 60 <div class="<?php $this->renderCssAtts($wrapperClassAttributes); ?>" role="listitem">
55 - <div class="fct_line_item_info">
56 - <?php $this->renderImage(); ?>
57 - <div class="fct_item_content">
58 - <?php $this->renderTitle(); ?>
59 - <?php $this->renderChildVariants(); ?>
60 - <?php do_action('fluent_cart/cart/line_item/line_meta', $this->getEventInfo()); ?>
61 - </div>
62 - </div><!-- .fct_line_item_info -->
61 + <div class="fct_line_item_body">
62 + <div class="fct_line_item_info">
63 + <?php $this->renderImage(); ?>
64 + <div class="fct_item_content">
65 + <?php $this->renderTitle(); ?>
66 + <?php $this->renderChildVariants(); ?>
67 + <?php do_action('fluent_cart/cart/line_item/line_meta', $this->getEventInfo()); ?>
68 + </div>
69 + </div><!-- .fct_line_item_info -->
63 70
64 - <div class="fct_line_item_price" aria-label="<?php esc_attr_e('Price information', 'fluent-cart'); ?>">
65 - <?php do_action('fluent_cart/cart/line_item/before_total', $this->getEventInfo()); ?>
66 - <?php if($promoPriceOriginal) : ?>
67 - <div style="text-decoration: line-through;" class="fct_line_item_total fct_promo_price" aria-label="<?php esc_attr_e('Original price', 'fluent-cart'); ?>">
68 - <?php echo esc_html(Helper::toDecimal($promoPriceOriginal)); ?>
69 - </div>
71 + <div class="fct_line_item_price" aria-label="<?php esc_attr_e('Price information', 'fluent-cart'); ?>">
72 + <?php if($promoPriceOriginal) : ?>
73 + <div style="text-decoration: line-through;" class="fct_line_item_total fct_promo_price" aria-label="<?php esc_attr_e('Original price', 'fluent-cart'); ?>">
74 + <?php echo esc_html(Helper::toDecimal($promoPriceOriginal)); ?>
75 + </div>
76 + <?php endif; ?>
77 + <div class="fct_item_price_wrapper">
78 + <?php do_action('fluent_cart/cart/line_item/before_total', $this->getEventInfo()); ?>
79 + <span class="fct_line_item_total<?php echo $hasCouponDiscount ? ' fct_coupon_original_price' : ''; ?>" aria-label="<?php esc_attr_e('Total price', 'fluent-cart'); ?>">
80 + <?php echo esc_html(Helper::toDecimal($subtotal)); ?>
81 + </span>
82 + <?php if ($hasCouponDiscount) : ?>
83 + <span class="fct_line_item_total fct_coupon_discounted_price" aria-label="<?php esc_attr_e('Discounted price', 'fluent-cart'); ?>">
84 + <?php echo esc_html(Helper::toDecimal($lineTotal)); ?>
85 + </span>
86 + <?php endif; ?>
87 + <?php do_action('fluent_cart/cart/line_item/after_total', $this->getEventInfo()); ?>
88 + </div>
89 + </div><!-- .fct_line_item_price -->
90 + </div>
91 + <div class="fct_line_item_footer">
92 + <?php do_action('fluent_cart/cart/line_item/footer_start', $this->getEventInfo()); ?>
93 +
94 + <?php $hasSetupFee = $this->maybeRenderSetupFeeInfo(); ?>
95 + <?php if ($hasSetupFee) : ?>
96 + <?php $this->renderSetupFeeInfo() ?>
97 + <?php do_action('fluent_cart/cart/line_item/after_setup_fee_info', $this->getEventInfo()); ?>
70 98 <?php endif; ?>
71 - <span class="fct_line_item_total" aria-label="<?php esc_attr_e('Total price', 'fluent-cart'); ?>">
72 - <?php echo esc_html(Helper::toDecimal(Arr::get($this->item, 'subtotal', 0))); ?>
73 - </span>
74 - <?php do_action('fluent_cart/cart/line_item/after_total', $this->getEventInfo()); ?>
75 - </div><!-- .fct_line_item_price -->
99 + <?php do_action('fluent_cart/cart/line_item/footer_end', $this->getEventInfo()); ?>
100 + </div>
76 101 </div>
77 102 <?php
78 103 }
79 104
@@ -81,10 +106,14 @@
81 106 {
82 107 $href = Arr::get($this->item, 'view_url', '');
83 108
84 109 $mainTitle = (string) Arr::get($this->item, 'post_title', '');
85 - $subtitle = (string) Arr::get($this->item, 'title', '');
86 110
111 + // The Cart model already resolves & appends variation_display_title on
112 + // every cart item (Cart::getCartDataAttribute); fall back to the raw
113 + // variation title for items it didn't decorate.
114 + $subtitle = (string) Arr::get($this->item, 'variation_display_title', (string) Arr::get($this->item, 'title', ''));
115 +
87 116 $quantity = Arr::get($this->item, 'quantity', 1);
88 117
89 118 ?>
90 119 <div class="fct_item_title">
@@ -114,8 +143,9 @@
114 143 - <?php echo wp_kses_post($subtitle); ?>
115 144 </div>
116 145 <?php endif; ?>
117 146 <?php $this->maybeRenderPaymentTypeInfo(); ?>
147 + <?php $this->maybeRenderPackageInfo(); ?>
118 148
119 149 <?php do_action('fluent_cart/cart/line_item/after_main_title', $this->getEventInfo()); ?>
120 150 </div>
121 151 <?php
@@ -124,9 +154,9 @@
124 154 public function renderImage()
125 155 {
126 156 $image = Arr::get($this->item, 'featured_media');
127 157 if (!$image) {
128 - return;
158 + $image = Vite::getAssetUrl('images/placeholder.svg');
129 159 }
130 160 $href = Arr::get($this->item, 'view_url', '');
131 161 $altText = sprintf(
132 162 /* translators: %s: product title */
@@ -155,9 +185,9 @@
155 185 {
156 186 $otherInfo = Arr::get($this->item, 'other_info', []);
157 187 $paymentType = Arr::get($otherInfo, 'payment_type', '');
158 188 $itemPrice = Arr::get($this->item, 'unit_price', 0);
159 -
189 +
160 190 if (isset($this->item['recurring_discounts'])) {
161 191 $otherInfo['recurring_discounts'] = $this->item['recurring_discounts'];
162 192 }
163 193
@@ -162,9 +192,8 @@
162 192 }
163 193
164 194 if ($paymentType === 'subscription') {
165 195 $subscriptionInfo = Helper::generateSubscriptionInfo($otherInfo, $itemPrice);
166 - $setupFeeInfo = Helper::generateSetupFeeInfo($otherInfo);
167 196 $trialInfo = Helper::generateTrialInfo($otherInfo);
168 197 ?>
169 198 <div class="fct_item_payment_info">
170 199 <span class="sr-only"><?php esc_html_e('Payment information', 'fluent-cart'); ?></span>
@@ -172,11 +201,8 @@
172 201 <span> <?php echo wp_kses($subscriptionInfo, ['del' => true]); ?> </span>
173 202 <?php if ($trialInfo): ?>
174 203 <span class="trial-days"> <?php echo esc_html($trialInfo); ?> </span>
175 204 <?php endif; ?>
176 - <?php if (!empty($setupFeeInfo)): ?>
177 - <span class="setup-fee"> <?php echo esc_html($setupFeeInfo); ?> </span>
178 - <?php endif; ?>
179 205 </div>
180 206 <?php
181 207 return;
182 208 }
@@ -188,11 +214,102 @@
188 214 }
189 215 ?>
190 216 <div class="fct_item_payment_info">
191 217 <?php
192 - /* translators: %s is the item price */
193 - printf(esc_html__('%s each', 'fluent-cart'), esc_html(Helper::toDecimal($itemPrice)));
218 + /* translators: %1$s: formatted unit price */
219 + printf(esc_html__('%1$s each', 'fluent-cart'), esc_html(Helper::toDecimal($itemPrice)));
194 220 ?>
221 + <?php do_action('fluent_cart/cart/line_item/unit_price_hint', $this->getEventInfo()); ?>
222 + </div>
223 + <?php
224 + }
225 +
226 + protected function maybeRenderSetupFeeInfo()
227 + {
228 + $paymentType = Arr::get($this->item, 'other_info.payment_type', '');
229 + if ($paymentType !== 'subscription') {
230 + return false;
231 + }
232 +
233 + $otherInfo = Arr::get($this->item, 'other_info', []);
234 + $setupFeeInfo = Helper::generateSetupFeeInfo($otherInfo);
235 + if (empty($setupFeeInfo)) {
236 + return false;
237 + }
238 + return true;
239 + }
240 +
241 + protected function renderSetupFeeInfo()
242 + {
243 +
244 + $otherInfo = Arr::get($this->item, 'other_info', []);
245 + $setupFeeInfo = Helper::generateSetupFeeInfo($otherInfo, true);
246 + $setupFeeName = Arr::get($setupFeeInfo, 'signup_fee_name', '');
247 + $setupFeePrice = Arr::get($setupFeeInfo, 'signup_fee_formatted', 0);
248 +
249 + ?>
250 + <div class="fct_item_payment_info">
251 + <div class="fct_setup_fee_info">
252 + <span class="setup-fee"><?php esc_html_e($setupFeeName) ?></span>
253 + <span class="setup-fee-amount">
254 + <?php esc_html_e($setupFeePrice) ?>
255 + <?php do_action('fluent_cart/cart/line_item/setup_fee_price_info', $this->getEventInfo()); ?>
256 + </span>
257 + </div>
258 + </div>
259 + <?php
260 +
261 + return true;
262 + }
263 +
264 + protected function maybeRenderPackageInfo()
265 + {
266 + if (Arr::get($this->item, 'fulfillment_type') !== 'physical') {
267 + return;
268 + }
269 +
270 + $otherInfo = Arr::get($this->item, 'other_info', []);
271 + if (!is_array($otherInfo)) {
272 + return;
273 + }
274 +
275 + $packageSlug = Arr::get($otherInfo, 'package_slug', '');
276 + $package = Helper::getPackageBySlug($packageSlug);
277 + if (!$package) {
278 + return;
279 + }
280 +
281 + $name = Arr::get($package, 'name', '');
282 + $type = Arr::get($package, 'type', '');
283 +
284 + $parts = [];
285 + if ($name) {
286 + $parts[] = $name;
287 + }
288 +
289 + $storeWeightUnit = Helper::shopConfig('weight_unit') ?: 'kg';
290 + $productWeight = floatval(Arr::get($otherInfo, 'weight', 0));
291 + $productWeightUnit = Arr::get($otherInfo, 'weight_unit', $storeWeightUnit);
292 + $convertedProductWeight = Helper::convertWeight($productWeight, $productWeightUnit, $storeWeightUnit);
293 + $packageWeight = floatval(Arr::get($package, 'weight', 0));
294 + $packageWeightUnit = Arr::get($package, 'weight_unit', $storeWeightUnit);
295 + $convertedPackageWeight = Helper::convertWeight($packageWeight, $packageWeightUnit, $storeWeightUnit);
296 + $totalWeight = $convertedProductWeight + $convertedPackageWeight;
297 +
298 + if ($totalWeight) {
299 + $formatted = rtrim(rtrim(number_format($totalWeight, 2), '0'), '.');
300 + $parts[] = $formatted . ' ' . $storeWeightUnit;
301 + }
302 +
303 + if (!$parts) {
304 + return;
305 + }
306 +
307 + $icon = ShippingMethodsRender::getPackageTypeIcon($type ?: 'box');
308 + ?>
309 + <div class="fct_item_package_info">
310 + <?php echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
311 + <span><?php echo esc_html(implode(' · ', $parts)); ?></span>
195 312 </div>
196 313 <?php
197 314 }
198 315