@php $miamiTz = config('app.deals_display_timezone', 'America/New_York'); $marketingFeeDefaults = $marketingFeeDefaults ?? \App\Models\MarketingSetting::get()->discountModalDefaults(); $feeGatewayPct = (float) ($marketingFeeDefaults['fee_gateway_pct'] ?? 3.5); $feeCommission = (float) ($marketingFeeDefaults['fee_commission_amt'] ?? 50); $feeShipping = (float) ($marketingFeeDefaults['fee_shipping_amt'] ?? 50); $feeExtra = (float) ($marketingFeeDefaults['fee_extra_amt'] ?? 0); $feeDefaultGateway = (bool) ($marketingFeeDefaults['fee_default_gateway'] ?? true); $feeDefaultCommission = (bool) ($marketingFeeDefaults['fee_default_commission'] ?? false); $feeDefaultShipping = (bool) ($marketingFeeDefaults['fee_default_shipping'] ?? true); $feeDefaultExtra = (bool) ($marketingFeeDefaults['fee_default_extra'] ?? false); @endphp @if($abandonedCheckouts->isEmpty())

No abandoned checkouts at the moment. When a customer enters checkout (email, phone, etc.) but does not complete the purchase, they will appear here.

@else
@foreach($abandonedCheckouts as $checkout) @php $openOffers = $checkout->open_offer_products ?? $checkout->accepted_offer_product_titles ?? []; $isStoryPurchaseCard = (bool) ($checkout->is_instagram_story_purchase ?? false); $blockStampReason = null; if ($isStoryPurchaseCard) { $blockStampReason = 'Instagram Story'; } elseif (count($openOffers) > 0) { $firstOffer = $openOffers[0] ?? []; $offerStatus = trim((string) ($firstOffer['status_label'] ?? '')); $blockStampReason = $offerStatus !== '' ? 'Open offer · ' . $offerStatus : 'Open offer'; } elseif (($checkout->has_previously_purchased_products ?? false) && !($checkout->create_discount_can ?? true)) { $blockStampReason = 'Previously ordered'; } @endphp
@if($blockStampReason)
Blocked {{ $blockStampReason }}
@endif
@if($checkout->completed_at) Recovered @else Abandoned checkout {{ $checkout->created_at->diffForHumans() }} @endif
Name {{ $checkout->full_name }}
Email @if($checkout->email) {{ $checkout->email }} @else — @endif
Phone @if($checkout->phone) {{ $checkout->phone }} @else — @endif
@php $latestDiscount = $checkout->checkoutDiscounts->first(); $feeCalcItems = []; if ($latestDiscount && $latestDiscount->status === 'active') { $cartSaleTotal = 0; foreach ($checkout->line_items ?? [] as $i) { $cartSaleTotal += ((float) ($i['price'] ?? 0)) * ((int) ($i['quantity'] ?? 1)); } if ($cartSaleTotal > 0) { $dType = $latestDiscount->discount_type ?? 'percentage'; $dVal = (float) ($latestDiscount->discount_value ?? 0); $discountAmount = $dType === 'percentage' ? $cartSaleTotal * $dVal / 100 : min($dVal, $cartSaleTotal); $totalFinal = $cartSaleTotal - $discountAmount; foreach ($checkout->line_items ?? [] as $item) { $itemSaleTotal = ((float) ($item['price'] ?? 0)) * ((int) ($item['quantity'] ?? 1)); $itemCostTotal = ((float) ($item['cost'] ?? 0)) * ((int) ($item['quantity'] ?? 1)); if ($itemSaleTotal > 0 && $totalFinal > 0) { $itemFinal = $itemSaleTotal - ($discountAmount * ($itemSaleTotal / $cartSaleTotal)); $itemProfitDisplay = $itemFinal - $itemCostTotal; $feeCalcItems[] = ['gross' => $itemProfitDisplay, 'final' => $itemFinal, 'share' => $itemFinal / $totalFinal]; } } } } @endphp
Products in checkout
    @forelse($checkout->line_items ?? [] as $item) @php $itemVid = trim(preg_replace('#^gid://shopify/ProductVariant/#', '', trim((string) ($item['variant_id'] ?? '')))); $itemPid = trim(preg_replace('#^gid://shopify/Product/#', '', trim((string) ($item['product_id'] ?? '')))); $itemKey = $itemVid !== '' ? $itemVid : ($itemPid !== '' ? 'p-' . $itemPid : ''); $itemPurchased = $itemKey !== '' && array_key_exists($itemKey, $productPurchasedByCheckoutId[$checkout->id] ?? []); $itemPrice = (float) ($item['price'] ?? 0); $itemCost = (float) ($item['cost'] ?? 0); $itemQty = (int) ($item['quantity'] ?? 1); $itemSaleTotal = $itemPrice * $itemQty; $itemCostTotal = $itemCost * $itemQty; $itemProfitDisplay = null; $itemProfitAfterFees = null; if ($latestDiscount && $latestDiscount->status === 'active' && $itemSaleTotal > 0) { $cartSaleTotal = 0; foreach ($checkout->line_items ?? [] as $i) { $cartSaleTotal += ((float) ($i['price'] ?? 0)) * ((int) ($i['quantity'] ?? 1)); } if ($cartSaleTotal > 0) { $dType = $latestDiscount->discount_type ?? 'percentage'; $dVal = (float) ($latestDiscount->discount_value ?? 0); $discountAmount = $dType === 'percentage' ? $cartSaleTotal * $dVal / 100 : min($dVal, $cartSaleTotal); $itemFinal = $itemSaleTotal - ($discountAmount * ($itemSaleTotal / $cartSaleTotal)); $itemProfitDisplay = $itemFinal - $itemCostTotal; $totalFinal = $cartSaleTotal - $discountAmount; if ($totalFinal > 0) { $itemShare = $itemFinal / $totalFinal; $feeGw = $feeDefaultGateway ? $itemFinal * $feeGatewayPct / 100 : 0; $feeComm = $feeDefaultCommission ? $feeCommission * $itemShare : 0; $feeShip = $feeDefaultShipping ? $feeShipping * $itemShare : 0; $feeExt = $feeDefaultExtra ? $feeExtra * $itemShare : 0; $itemProfitAfterFees = $itemProfitDisplay - $feeGw - $feeComm - $feeShip - $feeExt; } } } @endphp
  • @if(!empty($item['image']))
    @endif
    {{ $item['title'] ?? 'Product' }} × {{ $itemQty }} @if($itemPurchased) Order completed @endif
    Cost: @if($itemCost > 0)${{ number_format($itemCost, 1) }}@else—@endif Sale: @if($itemPrice > 0)${{ number_format($itemPrice, 2) }}@else—@endif @if($itemProfitDisplay !== null) Profit: ${{ number_format($itemProfitDisplay, 2) }} @if($itemProfitAfterFees !== null) Profit (after fees): ${{ number_format($itemProfitAfterFees, 2) }} @if($loop->first) @endif @endif @endif
  • @empty
  • —
  • @endforelse
@php $lineItemsCopy = $checkout->line_items ?? []; $currentProductIds = collect($lineItemsCopy)->map(fn ($i) => isset($i['product_id']) ? (string) $i['product_id'] : null)->filter()->unique()->sort()->values()->all(); $activeDiscountsList = $checkout->checkoutDiscounts->whereIn('status', ['active', 'paused_deal']); $allAssignedIds = []; $anyDiscountAppliesToAll = false; foreach ($activeDiscountsList as $d) { $pids = $d->product_ids; if (!is_array($pids) || count($pids) === 0) { $anyDiscountAppliesToAll = true; break; } foreach ($pids as $id) { $allAssignedIds[(string) $id] = true; } } if ($anyDiscountAppliesToAll) { $allAssignedIds = array_flip($currentProductIds); } $hasProductsWithoutDiscount = count($lineItemsCopy) > 0 && count($currentProductIds) > 0 && ( $anyDiscountAppliesToAll ? false : collect($currentProductIds)->contains(fn ($id) => !isset($allAssignedIds[$id])) ); @endphp @foreach($activeDiscountsList as $discount) @php $codeAppliesToProducts = false; $discountProductIds = $discount->product_ids; $discountIdsNormalized = is_array($discountProductIds) && count($discountProductIds) > 0 ? collect($discountProductIds)->map(fn ($id) => (string) $id)->unique()->sort()->values()->all() : null; if ($discountIdsNormalized === null) { $codeAppliesToProducts = count($currentProductIds) > 0; } else { $currentSet = array_flip($currentProductIds); $codeAppliesToProducts = collect($discountIdsNormalized)->contains(fn ($id) => isset($currentSet[$id])); } $discountProductImage = $discount->product_image_url ?? null; $isFirstDiscount = $loop->first; @endphp
@if($isFirstDiscount && !empty($feeCalcItems)) @endif
@if($discountProductImage)
@endif
Discount code
{{ ($discount->auto_apply ?? true) && (trim((string)($discount->code ?? '')) === '') ? 'Automatic' : ($discount->code ?? '') }} {{ $discount->status_label }} {{ $discount->discount_type === 'percentage' ? round((float) $discount->discount_value, 1) . '% off' : '$' . number_format((float) $discount->discount_value, 2) . ' off' }}

@if($codeAppliesToProducts) This code applies to the product(s) shown above. @else This discount is not assigned to the product(s) in this checkout. @endif

Created: {{ $discount->created_at->copy()->timezone($miamiTz)->format('M j, Y g:i A') }} Apply at checkout: {{ ($discount->auto_apply ?? true) ? 'Automatic' : 'Manual (customer enters code)' }} Expires: {{ $discount->ends_at ? $discount->ends_at->copy()->timezone($miamiTz)->format('M j, Y') : 'No expiration' }} @if($discount->status === 'paused_deal' && $discount->paused_by_deal_ends_at) Active again after deal ends: {{ $discount->paused_by_deal_ends_at->copy()->timezone($miamiTz)->format('M j, Y g:i A') }} @endif
@if($discount->discount_email_sent_at)
Email sent: {{ $discount->discount_email_sent_at->copy()->timezone($miamiTz)->format('M j, Y g:i A') }} @if($discount->discount_email_opened_at) Opened: Yes ({{ $discount->discount_email_opened_at->copy()->timezone($miamiTz)->format('M j, Y g:i A') }}) @else Opened: No @endif
@endif @if($discount->discount_sms_sent_at)
SMS sent: {{ $discount->discount_sms_sent_at->copy()->timezone($miamiTz)->format('M j, Y g:i A') }} @if($discount->discount_sms_delivered_at) Status: Delivered ({{ $discount->discount_sms_delivered_at->copy()->timezone($miamiTz)->format('M j, Y g:i A') }}) @elseif(!empty($discount->discount_sms_status)) @php $twilioStatus = ucfirst(strtolower($discount->discount_sms_status)); @endphp Status: {{ $twilioStatus }}@if(!empty($discount->discount_sms_fail_reason)) ({{ $discount->discount_sms_fail_reason }})@endif @else Status: Sent @endif
@endif
@php $openOfferPidSetForNotify = array_flip(array_map('strval', $checkout->open_offer_product_ids ?? [])); $storyPidSetForNotify = array_flip(array_map('strval', $checkout->instagram_story_product_ids ?? [])); $discountPidsForNotify = is_array($discount->product_ids) ? array_map('strval', $discount->product_ids) : []; $discountBlockedByOpenOffer = false; $discountBlockedByStory = (bool) ($checkout->is_instagram_story_purchase ?? false); if (!$discountBlockedByStory && count($storyPidSetForNotify) > 0) { if (count($discountPidsForNotify) === 0) { $discountBlockedByStory = true; } else { foreach ($discountPidsForNotify as $dpid) { $dpidNorm = preg_replace('#^gid://shopify/Product/#', '', $dpid); if (isset($storyPidSetForNotify[$dpidNorm]) || isset($storyPidSetForNotify[$dpid])) { $discountBlockedByStory = true; break; } } } } if (count($openOfferPidSetForNotify) > 0) { if (count($discountPidsForNotify) === 0) { $discountBlockedByOpenOffer = true; } else { foreach ($discountPidsForNotify as $dpid) { $dpidNorm = preg_replace('#^gid://shopify/Product/#', '', $dpid); if (isset($openOfferPidSetForNotify[$dpidNorm]) || isset($openOfferPidSetForNotify[$dpid])) { $discountBlockedByOpenOffer = true; break; } } } } @endphp @if($discountBlockedByStory)

Notify blocked — Instagram Story Purchase.

@elseif($discountBlockedByOpenOffer)

Notify blocked — open offer on this product.

@elseif(($checkout->email || $checkout->phone) && $discount->status !== 'paused_deal') @endif
@endforeach @if($checkout->completed_at)

@php $orderNum = trim((string)($checkout->recovered_order_number ?? '')); if ($orderNum === '' && $checkout->purchases->isNotEmpty()) { $first = $checkout->purchases->first(); $fromPurchase = trim((string)($first->order_number ?? '')); if ($fromPurchase !== '') { $orderNum = $fromPurchase; } } $orderNum = $orderNum !== '' ? ltrim($orderNum, '#') : ''; if ($orderNum === '') { $orderNum = '—'; } @endphp Customer completed order — Order #{{ $orderNum }} placed on {{ $checkout->completed_at->copy()->timezone($miamiTz)->format('F j, Y') }} at {{ $checkout->completed_at->copy()->timezone($miamiTz)->format('g:i A') }}.

@elseif(($checkout->email || $checkout->phone) && count($checkout->line_items ?? []) > 0)
@if($checkout->create_discount_can ?? true) @if(!$checkout->email && $checkout->phone)

No email on file — notification will be sent by SMS only.

@endif @elseif(!$blockStampReason && $checkout->checkoutDiscounts->whereIn('status', ['active', 'paused_deal'])->isEmpty())

{{ $checkout->create_discount_reason ?? 'This customer already has an active discount for these products.' }}

@endif
@endif
@endforeach
@endif