@extends('layouts.customer') @section('title',$product->name) @section('content')
{{ $ratings->count() }} ratings
@if($product->productPrices->isNotEmpty())
@php
// Fetch the latest active price
$latestActivePrice = $product->productPrices()
->where('is_active', 1)
->latest('created_at')
->first();
// Fetch the previous active price
$previousActivePrice = null;
if ($latestActivePrice) {
$previousActivePrice = $product->productPrices()
->where('is_active', 1)
->where('created_at', '<', $latestActivePrice->created_at)
->latest('created_at')
->first();
}
// Calculate the discount
$discountedPrice = $latestActivePrice ? $latestActivePrice->price : null;
$originalPrice = $previousActivePrice ? $previousActivePrice->price : null;
$discountPercent = $originalPrice && $discountedPrice ? (($originalPrice - $discountedPrice) / $originalPrice) * 100 : null;
@endphp
@if($discountedPrice && $discountPercent > 0)
₱ {{ number_format($discountedPrice, 2, '.', ',') }}
@if($originalPrice)
₱ {{ number_format($originalPrice, 2, '.', ',') }}
@endif
({{ number_format($discountPercent, 2) }}% off)
@else
₱ {{ number_format($discountedPrice, 2, '.', ',') }}
@endif
@endif
{!! $product->description !!}
{!! $product->small_description !!}
only {{$product->qty}} left in stock!
@endifNo ratings available for this product.
@else