From 29f63445090ae51507b71ae886970786a492a98a Mon Sep 17 00:00:00 2001 From: Marek Isalski Date: Sun, 20 May 2018 23:50:24 +0100 Subject: [PATCH] fix for PHP JSON-serialising empty arrays as [] --- fulcrm_shoppingcart.module | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/fulcrm_shoppingcart.module b/fulcrm_shoppingcart.module index 04b77b2..965202d 100644 --- a/fulcrm_shoppingcart.module +++ b/fulcrm_shoppingcart.module @@ -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', ),