| @@ -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"> |
| @@ -124,11 +152,10 @@ | ||
| 124 | 152 | |
| 125 | 153 | public function renderImage() |
| 126 | 154 | { |
| 127 | 155 | $image = Arr::get($this->item, 'featured_media'); |
| 128 | - if (!$image) { | |
| 129 | - return; | |
| 130 | - } | |
| 156 | + // Also maps the old generic icon a pre-existing cart row may still store. | |
| 157 | + $image = Helper::productImageOrPlaceholder($image); | |
| 131 | 158 | $href = Arr::get($this->item, 'view_url', ''); |
| 132 | 159 | $altText = sprintf( |
| 133 | 160 | /* translators: %s: product title */ |
| 134 | 161 | __('Image of %s', 'fluent-cart'), Arr::get($this->item, 'title', __('product', 'fluent-cart'))); |
| @@ -156,9 +183,9 @@ | ||
| 156 | 183 | { |
| 157 | 184 | $otherInfo = Arr::get($this->item, 'other_info', []); |
| 158 | 185 | $paymentType = Arr::get($otherInfo, 'payment_type', ''); |
| 159 | 186 | $itemPrice = Arr::get($this->item, 'unit_price', 0); |
| 160 | - | |
| 187 | + | |
| 161 | 188 | if (isset($this->item['recurring_discounts'])) { |
| 162 | 189 | $otherInfo['recurring_discounts'] = $this->item['recurring_discounts']; |
| 163 | 190 | } |
| 164 | 191 | |
| @@ -163,9 +190,8 @@ | ||
| 163 | 190 | } |
| 164 | 191 | |
| 165 | 192 | if ($paymentType === 'subscription') { |
| 166 | 193 | $subscriptionInfo = Helper::generateSubscriptionInfo($otherInfo, $itemPrice); |
| 167 | - $setupFeeInfo = Helper::generateSetupFeeInfo($otherInfo); | |
| 168 | 194 | $trialInfo = Helper::generateTrialInfo($otherInfo); |
| 169 | 195 | ?> |
| 170 | 196 | <div class="fct_item_payment_info"> |
| 171 | 197 | <span class="sr-only"><?php esc_html_e('Payment information', 'fluent-cart'); ?></span> |
| @@ -173,11 +199,8 @@ | ||
| 173 | 199 | <span> <?php echo wp_kses($subscriptionInfo, ['del' => true]); ?> </span> |
| 174 | 200 | <?php if ($trialInfo): ?> |
| 175 | 201 | <span class="trial-days"> <?php echo esc_html($trialInfo); ?> </span> |
| 176 | 202 | <?php endif; ?> |
| 177 | - <?php if (!empty($setupFeeInfo)): ?> | |
| 178 | - <span class="setup-fee"> <?php echo esc_html($setupFeeInfo); ?> </span> | |
| 179 | - <?php endif; ?> | |
| 180 | 203 | </div> |
| 181 | 204 | <?php |
| 182 | 205 | return; |
| 183 | 206 | } |
| @@ -189,17 +212,60 @@ | ||
| 189 | 212 | } |
| 190 | 213 | ?> |
| 191 | 214 | <div class="fct_item_payment_info"> |
| 192 | 215 | <?php |
| 193 | - /* translators: %s is the item price */ | |
| 194 | - 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))); | |
| 195 | 218 | ?> |
| 219 | + <?php do_action('fluent_cart/cart/line_item/unit_price_hint', $this->getEventInfo()); ?> | |
| 196 | 220 | </div> |
| 197 | 221 | <?php |
| 198 | 222 | } |
| 199 | 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 | + | |
| 200 | 262 | protected function maybeRenderPackageInfo() |
| 201 | 263 | { |
| 264 | + if (Arr::get($this->item, 'fulfillment_type') !== 'physical') { | |
| 265 | + return; | |
| 266 | + } | |
| 267 | + | |
| 202 | 268 | $otherInfo = Arr::get($this->item, 'other_info', []); |
| 203 | 269 | if (!is_array($otherInfo)) { |
| 204 | 270 | return; |
| 205 | 271 | } |