fix for PHP JSON-serialising empty arrays as []

master
Marek Isalski 7 years ago
parent 2bdf1ce2c7
commit 29f6344509

@ -275,7 +275,8 @@ function fulcrm_shoppingcart_person_add_guest_form_submit( $form, &$form_state )
if ( $cart[ 'url' ] ) { if ( $cart[ 'url' ] ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_data[ 'uuid' ] ] = $person_data; $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_data[ 'uuid' ] ] = $person_data;
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) || if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) { !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ||
is_null( $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_data[ 'uuid' ]; $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_data[ 'uuid' ];
} }
@ -383,7 +384,7 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
$eventbookingtype_id = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'id' ]; $eventbookingtype_id = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'id' ];
$person_uuid = NULL; $person_uuid = NULL;
if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ] ) ) if ( array_key_exists( 'uuid', $form_state[ 'fulcrm_shoppingcart' ][ 'person' ] ) )
$person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ]; $person_uuid = $form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ];
if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) ) if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
@ -391,16 +392,17 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
else else
$cart = fulcrm_shoppingcart_get_session_cart(); $cart = fulcrm_shoppingcart_get_session_cart();
if ( is_array( $cart ) ) { if ( $cart ) {
if ( $person_uuid ) { if ( $person_uuid ) {
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) || if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) || !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) { !array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array(); $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array( 'uuid' => $person_uuid );
$patch = TRUE; $patch = TRUE;
} }
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) || if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ) { !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ] ) ||
is_null( $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_uuid; $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] = $person_uuid;
$patch = TRUE; $patch = TRUE;
} }
@ -427,9 +429,10 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
$person_uuid, $person_name, $product_id ); $person_uuid, $person_name, $product_id );
} }
} else { } else {
$person = $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] ];
_fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart, _fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ], $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ],
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'name' ], $person[ 'name' ],
$product_id ); $product_id );
} }
@ -617,7 +620,7 @@ function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_stat
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) || if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) || !array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) { !array_key_exists( $person_uuid, $cart[ 'd' ][ 'fulcrm' ][ 'person' ] ) ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array(); $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_uuid ] = array( 'uuid' => $person_uuid );
$patch = TRUE; $patch = TRUE;
} }
if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) || if ( !array_key_exists( 'transaction', $cart[ 'd' ][ 'fulcrm' ] ) ||
@ -716,7 +719,7 @@ function fulcrm_shoppingcart_buy( $product_id, $hmac ) {
return 'error while fetching your details!'; return 'error while fetching your details!';
} }
} else { } else {
$person_data = array( 'data' => array( 'uuid' => fulcrm_uuid_uuid4(), $person_data = array( 'data' => array( 'uuid' => NULL, // initialise as NULL so first item added takes over
'name' => 'website visitor', 'name' => 'website visitor',
'd' => array( 'name' => 'website visitor', 'd' => array( 'name' => 'website visitor',
), ),

Loading…
Cancel
Save