get person2person relationships for booking buddies, etc

master
Marek Isalski 8 years ago
parent b77423e5af
commit 4e2a878b88

@ -104,7 +104,7 @@ function fulcrm_shoppingcart_buy_url( $product_id ) {
return url( 'fulcrm/buy/' . $product_id . '/' . $hmac );
}
function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $eventbookingtype, $product ) {
function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $person, $eventbookingtype, $product ) {
$form = array();
$form[ 'title_event' ] = array( '#type' => 'markup',
@ -117,6 +117,40 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $ev
'#markup' => '<h3>' . check_plain( $product[ 'name' ] ) . '</h3>',
);
if ( array_key_exists( 'id', $person ) )
$persons = array( $person[ 'id' ] => 'myself' );
else
$persons = array( 0 => 'myself' );
if ( array_key_exists( 'related_from_person2persons', $person ) ) {
foreach ( $person[ 'related_from_person2persons' ] as $p2p ) {
$persons[ $p2p[ 'related_from' ][ 'id' ] ] = $p2p[ 'related_from' ][ 'name' ] . ' (your ' . $p2p[ 'relationship' ][ 'name' ] . ')';
}
}
if ( array_key_exists( 'related_to_person2persons', $person ) ) {
foreach ( $person[ 'related_to_person2persons' ] as $p2p ) {
$persons[ $p2p[ 'related_to' ][ 'id' ] ] = $p2p[ 'related_to' ][ 'name' ] . ' (your ' . $p2p[ 'relationship' ][ 'name' ] . ')';
}
}
$form[ 'tickets_for_persons' ] = array( '#type' => 'checkboxes',
'#title' => 'Who is coming to the event?',
'#description' => 'Tick the box next to each person for whom you want to buy a ticket.',
'#options' => $persons,
);
$form[ 'tickets_for_others' ] = array( '#type' => 'select',
'#title' => 'How many tickets would you like for other people?',
'#description' => 'Choose how many tickets you are getting for other people. You\'ll be asked their names soon.',
'#options' => array( 0 => 'just the named people above',
1 => '1 more',
2 => '2 more',
3 => '3 more',
4 => '4 more',
),
);
$form[ 'person' ] = array( '#type' => 'markup',
'#markup' => '<pre>' . print_r( $person, 1 ) . '</pre>' );
$form[ 'eventbookingtype' ] = array( '#type' => 'markup',
'#markup' => '<pre>' . print_r( $eventbookingtype, 1 ) . '</pre>' );
$form[ 'product' ] = array( '#type' => 'markup',
@ -126,6 +160,8 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form( $form, &$form_state, $ev
}
function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
global $user;
$real_hmac = _fulcrm_shoppingcart_buy_hmac( $product_id );
if ( hash_equals( $real_hmac, $hmac ) ) {
@ -138,6 +174,26 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
'transaction_ddatacollection',
'lineitem_ddatacollection',
) ) ) );
if ( user_is_logged_in() )
$person_id = fulcrm_webhook_get_pk_for_entity_type( 'user', $user->uid, 'person' );
else
$person_id = null;
if ( $person_id ) {
$person_data = fulcrm_apiv2_GET( 'person/' . $person_id . '/',
$query = array( 'expand' => implode( ',', array( 'd',
'related_from_person2persons',
'related_from_person2persons.related_from',
'related_from_person2persons.related_from.d',
'related_from_person2persons.relationship',
'related_to_person2persons',
'related_to_person2persons.related_to',
'related_to_person2persons.related_to.d',
'related_to_person2persons.relationship',
) ) ) );
} else {
$person_data = array( 'data' => array() );
}
if ( $product_data[ 'success' ] ) {
switch ( fulcrm_apiv2_url_to_type( $product_data[ 'data' ][ 'content_object' ][ 'url' ] ) ) {
@ -145,7 +201,7 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
$eventbookingtype_data = fulcrm_apiv2_GET( $product_data[ 'data' ][ 'content_object' ][ 'url' ],
$query = array( 'expand' => implode( ',', array( 'event' ) ) ) );
if ( $eventbookingtype_data[ 'success' ] ) {
return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] );
return drupal_get_form( 'fulcrm_shoppingcart_buy_eventbookingtype_form', $person_data[ 'data' ], $eventbookingtype_data[ 'data' ], $product_data[ 'data' ] );
}
break;
default:

@ -13,4 +13,12 @@
<?php print theme( 'fulcrm_shoppingcart_items', array( 'items' => $cart[ 'shoppingitems' ] ) ); ?>
</tbody>
<tfoot>
<tr>
<td><a class="btn btn-success" href="<?php check_plain( variable_get( 'fulcrm_shoppingcart_proceed_url', url('<front>') ) )?>"><?php print check_plain( variable_get( 'fulcrm_shoppingcart_proceed_text', '' ) ); ?></a></td>
<td>&nbsp;</td>
<td class="text-right"><a class="btn btn-primary" href="<?php print url('fulcrm/checkout'); ?>">Proceed to Checkout</a></td>
</tr>
</tfoot>
</table>

Loading…
Cancel
Save