Commit 2fab9a7b authored by nicola85's avatar nicola85

ROOMS-82: Separate "commerce_price" and "base_price"

parent 7fed2ed9
......@@ -325,14 +325,6 @@ function bam_api_services_resources() {
'access arguments' => array('access add booking service'),
'help' => t('Add a new Rooms Unit.'),
'args' => array(
array(
'name' => 'name',
'type' => 'string',
'description' => t('Name'),
'source' => array('data' => 'name'),
'optional' => TRUE,
'default value' => '',
),
array(
'name' => 'type',
'type' => 'string',
......@@ -370,7 +362,7 @@ function bam_api_services_resources() {
}
/**
* Retrive a list of units.
* Retrieve a list of units.
*
* @param $unit_ids
*/
......@@ -411,7 +403,11 @@ function bam_api_services_units_index($unit_ids, $offset, $limit) {
$object_handler = new $class(rooms_unit_load($unit->unit_id));
$field_type = $object_handler->getFieldType();
$units[$unit->unit_id]['fields'][$field_type] = $object_handler->getFieldInfo();
$field_info = $object_handler->getFieldInfo();
if (!empty($field_info)) {
$units[$unit->unit_id]['fields'][$field_type] = $field_info;
}
}
}
......@@ -667,14 +663,13 @@ function bam_api_services_booking_index($unit_ids, $start_date, $duration) {
* @param $start_date
* @param $end_date
*/
function bam_api_services_add_booking($name, $type, $start_date, $end_date, $unit_id) {
function bam_api_services_add_booking($type, $start_date, $end_date, $unit_id) {
$return = new stdClass();
$return->sessid = session_id();
if (rooms_booking_type_load($type) !== FALSE) {
$booking = rooms_booking_create(
array(
'name' => $name,
'type' => $type,
'start_date' => $start_date,
'end_date' => $end_date,
......
<?php
$plugin = array(
'label' => t('Base Price'),
'handler' => array(
'class' => 'RoomsUnitFieldHandlerBasePrice',
),
);
class RoomsUnitFieldHandlerBasePrice extends RoomsUnitFieldHandlerBase {
public function getFieldType() {
return 'base_price';
}
public function getFieldInfo() {
$price_fields = array();
$rooms_unit_type = rooms_unit_type_load($this->unit->type);
$base_price_field = NULL;
if (isset($rooms_unit_type->data['pricing_field'])) {
$base_price_field = $rooms_unit_type->data['pricing_field'];
}
$fields = field_info_instances('rooms_unit', $this->unit->type);
foreach ($fields as $field) {
$field_info = field_info_field($field['field_name']);
if ($field_info['type'] == 'commerce_price') {
$field_array = $this->unit->{$field['field_name']};
if ($field['field_name'] == $base_price_field) {
if (isset($field_array[LANGUAGE_NONE][0]['amount'])) {
$price_fields[$field['field_name']] = array(
'amount' => $field_array[LANGUAGE_NONE][0]['amount'],
'currency_code' => $field_array[LANGUAGE_NONE][0]['currency_code'],
);
}
else {
$price_fields[$field['field_name']] = array();
}
}
}
}
return $price_fields;
}
}
......@@ -16,6 +16,12 @@ class RoomsUnitFieldHandlerCommercePrice extends RoomsUnitFieldHandlerBase {
public function getFieldInfo() {
$price_fields = array();
$rooms_unit_type = rooms_unit_type_load($this->unit->type);
$base_price_field = NULL;
if (isset($rooms_unit_type->data['pricing_field'])) {
$base_price_field = $rooms_unit_type->data['pricing_field'];
}
$fields = field_info_instances('rooms_unit', $this->unit->type);
foreach ($fields as $field) {
$field_info = field_info_field($field['field_name']);
......@@ -23,14 +29,16 @@ class RoomsUnitFieldHandlerCommercePrice extends RoomsUnitFieldHandlerBase {
if ($field_info['type'] == 'commerce_price') {
$field_array = $this->unit->{$field['field_name']};
if (isset($field_array[LANGUAGE_NONE][0]['amount'])) {
$price_fields[$field['field_name']] = array(
'amount' => $field_array[LANGUAGE_NONE][0]['amount'],
'currency_code' => $field_array[LANGUAGE_NONE][0]['currency_code'],
);
}
else {
$price_fields[$field['field_name']] = array();
if ($field['field_name'] != $base_price_field) {
if (isset($field_array[LANGUAGE_NONE][0]['amount'])) {
$price_fields[$field['field_name']] = array(
'amount' => $field_array[LANGUAGE_NONE][0]['amount'],
'currency_code' => $field_array[LANGUAGE_NONE][0]['currency_code'],
);
}
else {
$price_fields[$field['field_name']] = array();
}
}
}
}
......
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