Commit 727a943c authored by nicola85's avatar nicola85

Fix error on SalepriceResolver when there isn’t a booking entity

parent 954ca572
......@@ -41,44 +41,44 @@ class SalepriceResolver implements PriceResolverInterface {
$bee_settings = \Drupal::config('node.type.' . $node->bundle())->get('bee');
$booking = $order_item->get('field_booking')->entity;
if ($booking = $order_item->get('field_booking')->entity) {
$start_date = new \DateTime($booking->get('booking_start_date')->value);
$end_date = new \DateTime($booking->get('booking_end_date')->value);
$start_date = new \DateTime($booking->get('booking_start_date')->value);
$end_date = new \DateTime($booking->get('booking_end_date')->value);
$interval = $start_date->diff($end_date);
$interval = $start_date->diff($end_date);
$reservation_context = [
'order_item' => $order_item,
'booking' => $booking,
'node' => $node,
];
$reservation_context = [
'order_item' => $order_item,
'booking' => $booking,
'node' => $node,
];
$base_price = $node->get('field_price')->number;
$currency_code = $node->get('field_price')->currency_code;
$base_price = $node->get('field_price')->number;
$currency_code = $node->get('field_price')->currency_code;
if ($bee_settings['bookable_type'] == 'daily') {
$days = $interval->days;
$amount = number_format($base_price * $days, 2, '.', '');
}
else {
$field_price_frequency = $node->get('field_price_frequency')->value;
if ($field_price_frequency == 'hour') {
$hours = ($interval->days * 24) + $interval->h;
$amount = number_format($base_price * $hours, 2, '.', '');
if ($bee_settings['bookable_type'] == 'daily') {
$days = $interval->days;
$amount = number_format($base_price * $days, 2, '.', '');
}
else {
$minutes = ($interval->days * 24 * 60) + ($interval->h * 60) + $interval->i;
$amount = number_format($base_price * $minutes, 2, '.', '');
$field_price_frequency = $node->get('field_price_frequency')->value;
if ($field_price_frequency == 'hour') {
$hours = ($interval->days * 24) + $interval->h;
$amount = number_format($base_price * $hours, 2, '.', '');
}
else {
$minutes = ($interval->days * 24 * 60) + ($interval->h * 60) + $interval->i;
$amount = number_format($base_price * $minutes, 2, '.', '');
}
}
}
$price = new Price($amount, $currency_code);
$price = new Price($amount, $currency_code);
\Drupal::moduleHandler()->alter('bee_reservation_price', $price, $reservation_context);
\Drupal::moduleHandler()->alter('bee_reservation_price', $price, $reservation_context);
return $price;
return $price;
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment