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