diff --git a/app/Repositories/Shop/Offers.php b/app/Repositories/Shop/Offers.php index 6350dda9..a312f104 100644 --- a/app/Repositories/Shop/Offers.php +++ b/app/Repositories/Shop/Offers.php @@ -3,6 +3,7 @@ namespace App\Repositories\Shop; use App\Models\Shop\Offer; +use App\Models\Shop\PriceList; use App\Models\Shop\PriceListValue; use App\Models\Shop\SaleChannel; use App\Traits\Model\Basic; @@ -185,20 +186,44 @@ class Offers ->with([ 'article', 'tariff:id,status_id', + 'variation', ]) ->get(); return $channels->map(function ($channel) use ($offers) { $priceValue = null; $candidateOffer = null; + $allOffersForChannel = []; foreach ($offers as $offer) { $priceCandidate = self::getPrice($offer->id, 1, $channel->id); if ($priceCandidate && (float) $priceCandidate->price_taxed > 0) { - $priceValue = $priceCandidate; - $candidateOffer = $offer; - break; + // Get price list name + $priceListName = null; + if ($priceCandidate) { + $priceListModel = PriceList::find($priceCandidate->price_list_id); + $priceListName = $priceListModel ? $priceListModel->name : null; + } + + // Collect all offers with their details + $allOffersForChannel[] = [ + 'id' => $offer->id, + 'variation_name' => $offer->variation ? $offer->variation->name : null, + 'stock_current' => (int) $offer->stock_current, + 'status_id' => (int) $offer->status_id, + 'is_active' => (int) $offer->status_id === 1, + 'tariff_id' => $offer->tariff_id ? (int) $offer->tariff_id : null, + 'price_taxed' => (float) $priceCandidate->price_taxed, + 'quantity' => (int) $priceCandidate->quantity, + 'price_list_name' => $priceListName, + ]; + + // Keep first valid offer as the main candidate + if (!$candidateOffer) { + $priceValue = $priceCandidate; + $candidateOffer = $offer; + } } } @@ -209,6 +234,7 @@ class Offers $offerHasStock = $candidateOffer && $candidateOffer->stock_current !== null ? (float) $candidateOffer->stock_current > 0 : null; + $offerTariffId = $candidateOffer && $candidateOffer->tariff_id ? (int) $candidateOffer->tariff_id : null; return [ 'id' => $channel->id, @@ -221,6 +247,8 @@ class Offers 'offer_stock_current' => $offerStock, 'offer_has_stock' => $offerHasStock, 'tariff_status_id' => $offerTariffStatus, + 'tariff_id' => $offerTariffId, + 'all_offers' => $allOffersForChannel, ]; })->toArray(); } diff --git a/resources/views/Shop/Articles/show.blade.php b/resources/views/Shop/Articles/show.blade.php index 694d33c5..ae038d56 100644 --- a/resources/views/Shop/Articles/show.blade.php +++ b/resources/views/Shop/Articles/show.blade.php @@ -48,8 +48,8 @@