Skip to content

Instantly share code, notes, and snippets.

@phuclh
Created February 12, 2015 12:03
Show Gist options
  • Select an option

  • Save phuclh/70d198fb2d73a7b46d15 to your computer and use it in GitHub Desktop.

Select an option

Save phuclh/70d198fb2d73a7b46d15 to your computer and use it in GitHub Desktop.
$arrival = new DateTime(date('Y-m-d', strtotime($arrival)));
$departure = new DateTime(date('Y-m-d', strtotime($departure)));
$apartment = Cart::contents();
$apartment = reset($apartment);
$days = $arrival == $departure ? $days = 1 : $departure->diff($arrival)->format("%a");
$total = 0;
for ($i = 0; $i < $days; $i++)
{
$dynamicPriceFlag = false;
foreach ($apartment->dynamic_prices as $dynamic_price)
{
if ($arrival >= new DateTime($dynamic_price['date_from'] . ' 00:00:00')
&& $arrival <= new DateTime($dynamic_price['date_to'] . ' 23:59:59')
)
{
echo $arrival->format('d-m-Y') . ': ' . $dynamic_price['price'] . '<br/>';
$total += $dynamic_price['price'];
$dynamicPriceFlag = true;
break;
}
}
if (!$dynamicPriceFlag) {
echo $arrival->format('d-m-Y') . ': ' . $apartment->price . '<br/>';
$total += $apartment->price;
}
$arrival->modify('+1 day');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment