3

I have had a drupal rooms site running for a few months now, and the client has come back to me asking for the selected room to be shown in the confirmation email sent to the customer.

I have had a look through the available tokens that come with rooms, but there isn't one to display Bookable Unit Name, probably because it can be a multiple value field if more than one room is booked.

Or even a way to display the Rooms Unit name in the line items, then that would print in the notification email under the line items token?

I have gone to products > room products > manage display > line items, but there is nothing there to display the name.

0

You could create a custom token to pull that info in. Hook_token_info is the hook that makes a token available.

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_token_info/7

While hook_token is the hook that actually replaces it.

https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_tokens/7

Since it's a multivalue field, you may need to include a numeric operator on the end (e.g. node_room_field_room_number:0) for the delta on the field.

0

There is a much better way of doing this provided in the Rooms issue queue here... https://www.drupal.org/node/2307413

This can be done with Rules. The idea is you create a rule that modifies the line-item label to add the unit id, unit name, or whatever field you want from the unit to the line item.

Here is an export of a rule we're using to alter the format of the line item for apartment rentals:

{ "roomify_lingo_alter_line_item_label" : {
    "LABEL" : "Roomify Lingo: Alter Line item label",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "commerce_cart" ],
    "ON" : { "commerce_cart_product_add" : [] },
    "IF" : [
      { "entity_has_field" : { "entity" : [ "commerce-line-item" ], "field" : "rooms_booked_unit_id" } }
    ],
    "DO" : [
      { "entity_fetch" : {
          "USING" : {
            "type" : "rooms_unit",
            "id" : [ "commerce-line-item:rooms-booked-unit-id" ]
          },
          "PROVIDE" : { "entity_fetched" : { "booked_unit" : "Booked unit" } }
        }
      },
      { "data_set" : {
          "data" : [ "commerce-line-item:line-item-label" ],
          "value" : "[booked-unit:name] [commerce-line-item:rooms-booking-dates:duration] reservation - [commerce-line-item:rooms-booking-dates:value:custom:l, M jS Y] to [commerce-line-item:rooms-booking-dates:value2:custom:l, M jS Y] [commerce-line-item:deposit-remainder]"
        }
      }
    ]
  }
}

In our case, the value we used from the booked unit was the [booked-unit:name], but this could be modified and substituted with other tokens on the unit entity.

The methodology used here requires first checking for presence of the "rooms_booked_unit_id" field in the commerce line item. This has the benefit of once you check for the field, you can then use the field in subsequent actions in the rule, where we can then load the booked unit entity, and subsequently use any fields attached to the entity in other actions on the rule.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.