-
Notifications
You must be signed in to change notification settings - Fork 319
Add EDD Enhanced Conversions integration. #11486
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Add EDD Enhanced Conversions integration. #11486
Conversation
Size Change: +92 B (0%) Total Size: 2.01 MB ℹ️ View Unchanged
|
Build files for e5707f7 are ready:
|
b2b034d
to
6e4518b
Compare
6e4518b
to
5ee3661
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work, @abdelmalekkkkk! The changes look good. However, there are some feedback to be addressed before we merge.
We also need unit test coverage for the following methods, and we can mock the EDD methods if necessary:
register_hooks
get_enhanced_conversions_data_from_session
extract_user_data_from_session
if ( ! edd_is_success_page() ) { | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we check if the function exists?
if ( ! edd_is_success_page() ) { | |
return; | |
} | |
if ( ! function_exists( 'edd_is_success_page' ) || ! edd_is_success_page() ) { | |
return; | |
} |
return; | ||
} | ||
|
||
$purchase_session = edd_get_purchase_session(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Let's check if the function exists.
$purchase_session = edd_get_purchase_session(); | |
if ( ! function_exists( 'edd_get_purchase_session' ) ) { | |
return; | |
} | |
$purchase_session = edd_get_purchase_session(); |
* | ||
* @return array | ||
*/ | ||
protected function get_enhanced_conversions_data_from_session( $session ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
protected function get_enhanced_conversions_data_from_session( $session ) { | |
protected function get_enhanced_conversions_data_from_session( $session_data ) { |
* @return array | ||
*/ | ||
protected function get_enhanced_conversions_data_from_session( $session ) { | ||
if ( ! is_array( $session ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if ( ! is_array( $session ) ) { | |
if ( ! is_array( $session_data ) ) { |
return array(); | ||
} | ||
|
||
$user_data = $this->extract_user_data_from_session( $session ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$user_data = $this->extract_user_data_from_session( $session ); | |
$user_data = $this->extract_user_data_from_session( $session_data ); |
// Attempt to get full region name. | ||
$region = edd_get_state_name( $user_data['address']['country'], $region ); | ||
$address_data['region'] = Enhanced_Conversions::get_normalized_value( $region ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's check the edd_get_state_name
function existence and have a fallback.
// Attempt to get full region name. | |
$region = edd_get_state_name( $user_data['address']['country'], $region ); | |
$address_data['region'] = Enhanced_Conversions::get_normalized_value( $region ); | |
// Attempt to retrieve the full region name if the EDD function exists and the country is available. | |
if ( function_exists( 'edd_get_state_name' ) && ! empty( $country ) ) { | |
$region = edd_get_state_name( $country, $region ); | |
} | |
$address_data['region'] = Enhanced_Conversions::get_normalized_value( $region ); |
$email = $session_info['email'] ?? $session['user_email']; | ||
$first_name = $session_info['first_name']; | ||
$last_name = $session_info['last_name']; | ||
|
||
if ( isset( $session['user_info']['address'] ) ) { | ||
$session_address = $session_info['address']; | ||
|
||
$phone_number = $session_address['phone']; | ||
$street = $session_address['line1']; | ||
$city = $session_address['city']; | ||
$region = $session_address['state']; | ||
$postal_code = $session_address['zip']; | ||
$country = $session_address['country']; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variables are declared inside the if block. This causes "Undefined array key" errors when the if
condition is false.
Either we should declare the variable early, or add null coalescing (??
) fallbacks when extracting user data. This would have been evident with unit test coverage.
$email = $session_info['email'] ?? $session['user_email'] ?? '';
$first_name = $session_info['first_name'] ?? '';
$last_name = $session_info['last_name'] ?? '';
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I tried adding null coalescing to all the variables at first but that increased the class complexity. I went with another (slightly more verbose) approach and just verify the existence (!empty
) of every item in the $session_data
array.
* @var Easy_Digital_Downloads | ||
*/ | ||
private $contactform; | ||
private $edd; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add unit test coverage for other methods as well?
Thanks for the review @hussain-t. I addressed your comments and improved the EDD class coverage. Please take another look. |
The pipeline failures seem unrelated. |
Summary
Addresses issue:
Relevant technical choices
PR Author Checklist
Do not alter or remove anything below. The following sections will be managed by moderators only.
Code Reviewer Checklist
Merge Reviewer Checklist