Не отображать удаленные дни, а отображать следующие доступные дни

У меня есть сайт, который отображает следующие 5 дней доставки. 5 дней завтра и следующие 4 рабочих дня.

Это отображается так

$daysOff = ['Sat', 'Sun'];

for ($days = 1; $days <= 7; $days++) {
$day = date("D", strtotime("today + $days day"));
if (!in_array($day, $daysOff)) {
$daysOnRearranged[] = date("D, j M", strtotime("today + $days day"));
}
}

Затем я перебираю и показываю другую информацию о ценах. Я не буду показывать все это здесь.

    foreach ($daysOnRearranged as $key => $day) {

$product = Product::where('id', $order->product_id)->first();


$product->date             = $day;
$product->deal             = $deal;
$product->units            = $order['units'];
$product->amountExclVat    = $order->price->priceExclVat($amount);
$product->amountVat        = $order->price->vatTotal($amount);
$product->unitPriceInclVat = $unit_price;
$product->unitPriceExclVat = $order->price->unitPriceExclVat($unit_price);
$product->deliveryRate     = $deliveryRate;
$product->vat              = $product['vat'];



//Add product to collection

$today = Carbon::parse($product->date)->format('Y-m-d');
$nonDeliveryDays = Day::where('sale_at', $today)->where('is_not_delivery_day', 1)->first();


if(is_null($nonDeliveryDays)){
$products->push($product);
}
}

Это мнение тогда

      @foreach($products as $key => $product)

<div class="delivery-dates-tab @if ($product->deal === 1){{'is-deal'}}@endif">
<input type="radio" value="{{ $key }}" name="delivery_date" id="date-price-tab-{{$loop->index}}" {{$product->deal === 1 ? 'checked' : ''}}>
<label class="btn btn-primary not-active" for="date-price-tab-{{$loop->index}}">

<p class="delivery-dates-tab__date">{{ date('D M d', strtotime($product->date)) }}</p>
<p class="delivery-dates-tab__price">€{{ $product->amountInclVat }}</p>
<small>{{ $product->units }} L</small>
<details>
<summary>Price Details</summary>
<p><b>Price Per Litre:</b></p><br />
<p>&euro;{{ $product->unitPriceInclVat }}<small> inc. VAT</small> </p><br />
<p>&euro;{{ $product->unitPriceExclVat }}<small> ex. VAT</small></p><br />
<p name="delivery" value={{ $product->deliveryRate }}><b>Delivery</b> &euro;{{ $product->deliveryRate }}</p><br />

<br />
<summary>Breakdown</summary>
<p>Amount ex. VAT: &euro;{{ $product->amountExclVat}}</p>
<p>Total VAT({{ $product->vat }}%): &euro;{{ $product->amountVat}} </p>
</details>

</label>
</div>
@endforeach

Я могу удалить дни доставки, используя переменную nonDeliveryDays. Но если есть 2 критерия соответствия, показывается только 3 дня. Как мне показать следующие 2 доступных дня, если два будут удалены?

0

Решение

Вы можете объединить два for петли в один while, вот так:

$products = [];
$days = 1;

//repeat until we have 5 products in the list
while (sizeof($products) < 5) {

$day = date("D, j M", strtotime("today + $days day"));

$product = Product::where('id', $order->product_id)->first();

$product->date             = $day;
$product->deal             = $deal;
$product->units            = $order['units'];
$product->amountExclVat    = $order->price->priceExclVat($amount);
$product->amountVat        = $order->price->vatTotal($amount);
$product->unitPriceInclVat = $unit_price;
$product->unitPriceExclVat = $order->price->unitPriceExclVat($unit_price);
$product->deliveryRate     = $deliveryRate;
$product->vat              = $product['vat'];



//Add product to collection

$today = Carbon::parse($product->date)->format('Y-m-d');
$nonDeliveryDays = Day::where('sale_at', $today)->where('is_not_delivery_day', 1)->first();


if(is_null($nonDeliveryDays)){
$products->push($product);
}

// go to the next day
$days++;
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector