Skip to content

Commit

Permalink
fix(nrh): sync only basic fields; normalize on Newspack_Newsletters_C…
Browse files Browse the repository at this point in the history
…ontacts::upsert
  • Loading branch information
dkoo committed Feb 24, 2025
1 parent 3b2a079 commit 0b38bc2
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 0 additions & 2 deletions includes/reader-activation/sync/class-esp-sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ public static function sync( $contact, $context = '' ) {
*/
$contact = \apply_filters( 'newspack_esp_sync_contact', $contact, $context );

$contact = Sync\Metadata::normalize_contact_data( $contact );

$result = \Newspack_Newsletters_Contacts::upsert( $contact, $master_list_id, $context );

return \is_wp_error( $result ) ? $result : true;
Expand Down
14 changes: 13 additions & 1 deletion includes/reader-activation/sync/class-metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Newspack\Reader_Activation\Sync;

use Newspack\Donations;
use Newspack\Reader_Activation;
use Newspack\Logger;

Expand Down Expand Up @@ -35,19 +36,29 @@ class Metadata {
*/
public static $keys = [];

/**
* Initializes hooks.
*/
public static function init_hooks() {
\add_filter( 'newspack_newsletters_contact_data', [ __CLASS__, 'normalize_contact_data' ] );
}

/**
* Get the metadata keys map for Reader Activation.
*
* @return array List of fields.
*/
public static function get_keys() {
if ( empty( self::$keys ) ) {
// Only get Woo fields if using Woo.
$fields = Donations::is_platform_wc() ? self::get_all_fields() : self::get_basic_fields();

/**
* Filters the list of key/value pairs for metadata fields to be synced to the connected ESP.
*
* @param array $keys The list of key/value pairs for metadata fields to be synced to the connected ESP.
*/
self::$keys = \apply_filters( 'newspack_ras_metadata_keys', self::get_all_fields() );
self::$keys = \apply_filters( 'newspack_ras_metadata_keys', $fields );
}
return self::$keys;
}
Expand Down Expand Up @@ -446,3 +457,4 @@ public static function normalize_contact_data( $contact ) {
return apply_filters( 'newspack_esp_sync_normalize_contact', $contact );
}
}
Metadata::init_hooks();
2 changes: 1 addition & 1 deletion includes/reader-activation/sync/class-woocommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static function should_sync_order( $order ) {
* @return \WC_Order|false Order object or false.
*/
private static function get_current_product_order_for_sync( $customer ) {
if ( ! is_a( $customer, 'WC_Customer' ) ) {
if ( ! is_a( $customer, 'WC_Customer' || ! function_exists( 'WC' ) ) ) {
return false;
}

Expand Down
8 changes: 5 additions & 3 deletions src/wizards/readerRevenue/views/donation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
TextControl,
Wizard,
} from '../../../../components/src';
import { READER_REVENUE_WIZARD_SLUG } from '../../constants';
import { NEWSPACK, READER_REVENUE_WIZARD_SLUG } from '../../constants';

type FrequencySlug = 'once' | 'month' | 'year';

Expand Down Expand Up @@ -349,6 +349,8 @@ const BillingFields = () => {
const Donation = () => {
const wizardData = Wizard.useWizardData( 'reader-revenue' ) as WizardData;
const { saveWizardSettings } = useDispatch( Wizard.STORE_NAMESPACE );
const { platform_data } = wizardData;
const usedPlatform = platform_data?.platform;
const onSaveDonationSettings = () =>
saveWizardSettings( {
slug: READER_REVENUE_WIZARD_SLUG,
Expand Down Expand Up @@ -407,7 +409,7 @@ const Donation = () => {
) }
<DonationAmounts />
</ActionCard>
<ActionCard
{ NEWSPACK === usedPlatform && ( <ActionCard
description={ __( 'Configure options for modal checkouts.', 'newspack-plugin' ) }
hasGreyHeader={ true }
isMedium
Expand All @@ -419,7 +421,7 @@ const Donation = () => {
}
>
<BillingFields />
</ActionCard>
</ActionCard> ) }
</>
);
};
Expand Down

0 comments on commit 0b38bc2

Please sign in to comment.