@foreach ($shipment->order->products as $orderProduct) @php $product = $orderProduct->product->original_product; $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 ($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 ($offerPercent > 0 && $originalPrice > 0 && $displayPrice >= $originalPrice && ($isQuantityBasedOffer || ! ($buyQty > 0 && $qty <= $buyQty))) { $displayPrice = max($originalPrice - ($originalPrice * ($offerPercent / 100)), 0); } if (! $hasExplicitOfferDiscountQty && ! $isQuantityBasedOffer && $buyQty > 0 && $qty > $buyQty && $offerPercent > 0 && $originalPrice > 0) { $computedDiscountedUnitPrice = max($originalPrice - ($originalPrice * ($offerPercent / 100)), 0); $unitDiscount = $originalPrice - $computedDiscountedUnitPrice; $discountAmount = (float) ($shipment->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) ($shipment->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); $shouldRenderSplitShipmentRows = $offerDiscountQty > 0 && $offerRegularQty > 0 && $offerOriginalUnitPrice > $offerDiscountedUnitPrice; $shipmentProductRows = $shouldRenderSplitShipmentRows ? [ [ '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' => $offerPercent > 0 && $originalPrice > $displayPrice, ], ]; @endphp @foreach ($shipmentProductRows as $shipmentProductRow)
{{ $product->name }}
{{ $orderProduct->product_name }} @if ($attributes = Arr::get($orderProduct->options, 'attributes'))
{{ $attributes }}
@endif @if ($sku = Arr::get($orderProduct->options, 'sku') ?: ($product && $product->sku ? $product->sku : null))

{{ trans('plugins/ecommerce::shipping.sku') }}: {{ $sku }}

@endif @if ($shipmentProductRow['show_offer'])
{{ __('Offer') }}: {{ $orderProduct->offer_reason }}
@endif
{{ $shipmentProductRow['qty'] }} × @if ($shipmentProductRow['show_offer']) {{ format_price($shipmentProductRow['original_price']) }} {{ format_price($shipmentProductRow['price']) }} @else {{ format_price($shipmentProductRow['price']) }} @endif @if ($shipmentProductRow['show_offer']) {{ format_price($shipmentProductRow['original_price'] * $shipmentProductRow['qty']) }} {{ format_price($shipmentProductRow['price'] * $shipmentProductRow['qty']) }} @else {{ format_price($shipmentProductRow['price'] * $shipmentProductRow['qty']) }} @endif
@endforeach @endforeach
@if ($orderEditRouteName) {{ trans('plugins/ecommerce::shipping.view_order', ['order_id' => $shipment->order->code]) }} @endif