@php
$shouldShowStoreName = $showStoreName ?? true;
$emailStoreName = null;
if ($shouldShowStoreName && is_plugin_active('marketplace')) {
$emailStoreName = $order->store?->name;
if (! $emailStoreName) {
foreach ($products ?? $order->products as $orderProduct) {
$emailStoreName = data_get($orderProduct, 'product.original_product.store.name')
?: data_get($orderProduct, 'product.store.name')
?: Arr::get($orderProduct->options ?? [], 'store_name');
if (! $emailStoreName && $orderProduct->product_id) {
$product = \Botble\Ecommerce\Models\Product::query()
->with(['store', 'variationInfo.configurableProduct.store'])
->find($orderProduct->product_id);
$emailStoreName = data_get($product, 'original_product.store.name')
?: data_get($product, 'store.name')
?: data_get($product, 'variationInfo.configurableProduct.store.name');
}
if ($emailStoreName) {
break;
}
}
}
if (! $emailStoreName) {
$emailStoreName = get_ecommerce_setting('company_name_for_invoicing', get_ecommerce_setting('store_name')) ?: config('app.name');
}
}
@endphp
@if ($emailStoreName)
@lang('plugins/marketplace::store.forms.store') : {{ $emailStoreName }}
@endif
@if (!$order->dont_show_order_info_in_product_list)
{{ trans('plugins/ecommerce::email.view_order') }}
@endif
|
{{ trans('plugins/ecommerce::products.form.quantity') }} |
{{ trans('plugins/ecommerce::products.form.total') }} |
@foreach($products ?? $order->products as $orderProduct)
@php
$isFreeGift = (bool) Arr::get($orderProduct->options, 'is_free_gift') || ((float) $orderProduct->price <= 0 && (float) $orderProduct->original_price > 0 && $orderProduct->offer_rule_id);
$qty = (int) $orderProduct->qty;
$originalPrice = (float) ($orderProduct->original_price ?: $orderProduct->price);
$displayPrice = (float) $orderProduct->price;
$offerReason = (string) $orderProduct->offer_reason;
$offerType = (string) Arr::get($orderProduct->options, 'offer_type', '');
$isQuantityBasedOffer = $offerType === 'quantity_based' || str_contains(strtolower($offerReason), 'or more');
$offerPercent = 0;
$buyQty = 0;
if (preg_match('/get\s+([0-9]+(?:\.[0-9]+)?)%\s+off/i', $offerReason, $matches)) {
$offerPercent = (float) $matches[1];
} elseif (! $isFreeGift && $originalPrice > 0 && $displayPrice > 0 && $displayPrice < $originalPrice) {
$offerPercent = round((($originalPrice - $displayPrice) / $originalPrice) * 100, 2);
}
if (preg_match('/buy\s+([0-9]+)/i', $offerReason, $matches)) {
$buyQty = max((int) $matches[1], 0);
}
$offerDiscountQty = (int) Arr::get($orderProduct->options, 'offer_discount_qty', 0);
$hasExplicitOfferDiscountQty = $offerDiscountQty > 0;
$offerOriginalUnitPrice = (float) Arr::get($orderProduct->options, 'offer_original_unit_price', $originalPrice);
$offerDiscountedUnitPrice = (float) Arr::get($orderProduct->options, 'offer_discounted_unit_price', $displayPrice);
if (! $offerPercent && Arr::get($orderProduct->options, 'offer_discount_percent')) {
$offerPercent = (float) Arr::get($orderProduct->options, 'offer_discount_percent');
}
if (
! $isFreeGift
&& $offerPercent > 0
&& $originalPrice > 0
&& $displayPrice >= $originalPrice
&& ($isQuantityBasedOffer || ! ($buyQty > 0 && $qty <= $buyQty))
) {
$displayPrice = max($originalPrice - ($originalPrice * ($offerPercent / 100)), 0);
}
if (! $hasExplicitOfferDiscountQty && ! $isFreeGift && ! $isQuantityBasedOffer && $buyQty > 0 && $qty > $buyQty && $offerPercent > 0 && $originalPrice > 0) {
$computedDiscountedUnitPrice = max($originalPrice - ($originalPrice * ($offerPercent / 100)), 0);
$unitDiscount = $originalPrice - $computedDiscountedUnitPrice;
$discountAmount = (float) ($order->discount_amount ?? 0);
$discountQtyFromAmount = $unitDiscount > 0 && $discountAmount > 0
? (int) round($discountAmount / $unitDiscount)
: 0;
$offerDiscountQty = $discountQtyFromAmount > 0
? $discountQtyFromAmount
: min((int) floor($qty / ($buyQty + 1)), $qty - 1);
$offerOriginalUnitPrice = $originalPrice;
$offerDiscountedUnitPrice = $computedDiscountedUnitPrice;
}
$unitDiscount = $offerOriginalUnitPrice - $offerDiscountedUnitPrice;
$discountAmount = (float) ($order->discount_amount ?? 0);
$discountQtyFromAmount = $unitDiscount > 0 && $discountAmount > 0
? (int) round($discountAmount / $unitDiscount)
: 0;
if (! $hasExplicitOfferDiscountQty && $discountQtyFromAmount > 0 && $discountQtyFromAmount <= $qty) {
$offerDiscountQty = $discountQtyFromAmount;
}
$offerDiscountQty = min(max($offerDiscountQty, 0), $qty);
$offerRegularQty = max($qty - $offerDiscountQty, 0);
$shouldRenderSplitEmailRows = ! $isFreeGift
&& $offerDiscountQty > 0
&& $offerRegularQty > 0
&& $offerOriginalUnitPrice > $offerDiscountedUnitPrice;
$emailProductRows = $shouldRenderSplitEmailRows
? [
[
'qty' => $offerDiscountQty,
'price' => $offerDiscountedUnitPrice,
'original_price' => $offerOriginalUnitPrice,
'show_offer' => true,
],
[
'qty' => $offerRegularQty,
'price' => $offerOriginalUnitPrice,
'original_price' => $offerOriginalUnitPrice,
'show_offer' => false,
],
]
: [
[
'qty' => $qty,
'price' => $displayPrice,
'original_price' => $originalPrice,
'show_offer' => ! $isFreeGift && $offerPercent > 0 && $originalPrice > $displayPrice,
],
];
@endphp
@foreach ($emailProductRows as $emailProductRow)
@php
$emailRowQty = (int) $emailProductRow['qty'];
$emailRowPrice = (float) $emailProductRow['price'];
$emailRowOriginalPrice = (float) $emailProductRow['original_price'];
$emailRowTotal = $emailRowPrice * $emailRowQty;
$emailRowOriginalTotal = $emailRowOriginalPrice * $emailRowQty;
@endphp
|
{{ $orderProduct->product_name }}
@if ($isFreeGift)
{{ __('Free Gift') }}
@endif
@if ($attributes = Arr::get($orderProduct->options, 'attributes'))
{{ $attributes }}
@endif
@if ($orderProduct->product_options_implode)
{{ $orderProduct->product_options_implode }}
@endif
@if ($emailProductRow['show_offer'])
{{ format_price($emailRowOriginalPrice) }}
{{ format_price($emailRowPrice) }}
{{ (float) $offerPercent }}% {{ __('off') }}
@elseif ($isFreeGift)
{{ __('Free') }}
@if ($emailRowOriginalPrice > 0)
{{ format_price($emailRowOriginalPrice) }}
@endif
@else
{{ trans('plugins/ecommerce::products.form.price') }}: {{ format_price($emailRowPrice) }}
@endif
|
x {{ $emailRowQty }} |
@if ($isFreeGift)
{{ __('FREE') }}
@if ($emailRowOriginalPrice > 0)
{{ format_price($emailRowOriginalTotal) }}
@endif
@elseif ($emailProductRow['show_offer'])
{{ format_price($emailRowOriginalTotal) }}
{{ format_price($emailRowTotal) }}
@else
{{ format_price($emailRowTotal) }}
@endif
|
@endforeach
@endforeach
@if (!$order->dont_show_order_info_in_product_list && ! ($hideOrderSummary ?? false))
@include('plugins/ecommerce::emails.partials.order-summary', ['orders' => collect([$order])])
@endif