fix for PHP JSON-serialising empty arrays as []

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

@ -275,7 +275,8 @@ function fulcrm_shoppingcart_person_add_guest_form_submit( $form, &$form_state )
if ( $cart[ 'url' ] ) {
$cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $person_data[ 'uuid' ] ] = $person_data;
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' ];
}
@ -383,7 +384,7 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
$eventbookingtype_id = $form_state[ 'fulcrm_shoppingcart' ][ 'eventbookingtype' ][ 'id' ];
$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' ];
if ( array_key_exists( 'shoppingcart', $form_state[ 'fulcrm_shoppingcart' ] ) )
@ -391,16 +392,17 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
else
$cart = fulcrm_shoppingcart_get_session_cart();
if ( is_array( $cart ) ) {
if ( $cart ) {
if ( $person_uuid ) {
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!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;
}
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;
$patch = TRUE;
}
@ -427,9 +429,10 @@ function fulcrm_shoppingcart_buy_eventbookingtype_form_submit( $form, &$form_sta
$person_uuid, $person_name, $product_id );
}
} else {
$person = $cart[ 'd' ][ 'fulcrm' ][ 'person' ][ $cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ] ];
_fulcrm_shoppingcart_buy_eventbookingtype_create_shoppingitem( $form_state, $cart,
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'uuid' ],
$form_state[ 'fulcrm_shoppingcart' ][ 'person' ][ 'name' ],
$cart[ 'd' ][ 'fulcrm' ][ 'transaction' ][ 'person' ],
$person[ 'name' ],
$product_id );
}
@ -617,7 +620,7 @@ function fulcrm_shoppingcart_buy_generic_product_form_submit( $form, &$form_stat
if ( !array_key_exists( 'fulcrm', $cart[ 'd' ] ) ||
!array_key_exists( 'person', $cart[ 'd' ][ 'fulcrm' ] ) ||
!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;
}
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!';
}
} 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',
'd' => array( 'name' => 'website visitor',
),

Loading…
Cancel
Save