diff --git a/src/DonationForms/V2/DonationFormsAdminPage.php b/src/DonationForms/V2/DonationFormsAdminPage.php index 5154bcc277..06114ead38 100644 --- a/src/DonationForms/V2/DonationFormsAdminPage.php +++ b/src/DonationForms/V2/DonationFormsAdminPage.php @@ -334,6 +334,7 @@ public function getSupportedAddons(): array 'Zapier' => defined('GIVE_ZAPIER_VERSION'), 'Salesforce' => defined('GIVE_SALESFORCE_VERSION'), 'Donation Upsells for WooCommerce' => class_exists('Give_WooCommerce'), + 'Constant Contact' => class_exists('Give_Constant_Contact'), 'MailChimp' => class_exists('Give_MailChimp'), // 'Manual Donations' => class_exists('Give_Manual_Donations'), 'Funds' => defined('GIVE_FUNDS_ADDON_NAME'), @@ -349,7 +350,6 @@ public function getSupportedAddons(): array // 'Per Form Confirmations' => class_exists('Per_Form_Confirmations_4_GIVEWP'), // 'Form Countdown' => class_exists('Give_Form_Countdown'), // 'ActiveCampaign' => class_exists('Give_ActiveCampaign'), - // 'Constant Contact' => class_exists('Give_Constant_Contact'), ]; $output = []; diff --git a/src/FormMigration/FormMetaDecorator.php b/src/FormMigration/FormMetaDecorator.php index d6ecbc2fb2..78efb87ec9 100644 --- a/src/FormMigration/FormMetaDecorator.php +++ b/src/FormMigration/FormMetaDecorator.php @@ -510,6 +510,54 @@ public function getFeeRecoverySettings(): array ]; } + /** + * @unreleased + */ + public function isConstantContactEnabled(): bool + { + $isFormEnabled = give_is_setting_enabled($this->getMeta('_give_constant_contact_enable'),'true'); + + $isFormDisabled = give_is_setting_enabled($this->getMeta('_give_constant_contact_disable'),'true'); + + $isGloballyEnabled = give_is_setting_enabled(give_get_option('give_constant_contact_show_checkout_signup'), 'on'); + + return !($isFormDisabled || ( !$isGloballyEnabled && !$isFormEnabled)); + } + + /** + * @unreleased + */ + public function getConstantContactLabel(): string + { + $defaultMeta = give_get_option('give_constant_contact_label', __('Subscribe to our newsletter?')); + + return $this->getMeta('_give_constant_contact_custom_label', $defaultMeta); + } + + /** + * @unreleased + */ + public function getConstantContactDefaultChecked(): bool + { + $defaultMeta = give_is_setting_enabled( + give_get_option('give_constant_contact_checked_default', + true), + 'on' + ); + + return $this->getMeta('_give_constant_contact_checked_default', $defaultMeta); + } + + /** + * @unreleased + */ + public function getConstantContactSelectedLists(): array + { + $defaultMeta = give_get_option('give_constant_contact_list', []); + + return (array)$this->getMeta('_give_constant_contact', $defaultMeta); + } + /** * @since 3.3.0 */ @@ -542,7 +590,6 @@ public function getMailchimpDefaultChecked(): bool give_get_option('give_mailchimp_checked_default', true))); } - /** * @unreleased add global setting as default. * @since 3.3.0 diff --git a/src/FormMigration/ServiceProvider.php b/src/FormMigration/ServiceProvider.php index 4911aa0f20..3af7de2f45 100644 --- a/src/FormMigration/ServiceProvider.php +++ b/src/FormMigration/ServiceProvider.php @@ -45,6 +45,7 @@ public function register() Steps\FormMeta::class, Steps\PdfSettings::class, Steps\FeeRecovery::class, + Steps\ConstantContact::class, Steps\PerFormGateways::class, Steps\Mailchimp::class, Steps\FundsAndDesignations::class, diff --git a/src/FormMigration/Steps/ConstantContact.php b/src/FormMigration/Steps/ConstantContact.php new file mode 100644 index 0000000000..561ad21555 --- /dev/null +++ b/src/FormMigration/Steps/ConstantContact.php @@ -0,0 +1,37 @@ +formV2->isConstantContactEnabled(); + } + + /** + * @unreleased + */ + public function process(): void + { + $block = BlockModel::make([ + 'name' => 'givewp/constantcontact', + 'attributes' =>[ + 'label' => $this->formV2->getConstantContactLabel(), + 'checked' => $this->formV2->getConstantContactDefaultChecked(), + 'selectedEmailLists' => $this->formV2->getConstantContactSelectedLists(), + ], + ]); + + $this->fieldBlocks->insertAfter('givewp/email', $block); + } +} diff --git a/tests/Feature/FormMigration/Steps/TestConstantContact.php b/tests/Feature/FormMigration/Steps/TestConstantContact.php new file mode 100644 index 0000000000..2825d02d61 --- /dev/null +++ b/tests/Feature/FormMigration/Steps/TestConstantContact.php @@ -0,0 +1,95 @@ + 'Subscribe to our newsletter?', + '_give_constant_contact_checked_default' => 'on', + '_give_constant_contact' => ['1928414891'], + ]; + + $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); + + $payload = FormMigrationPayload::fromFormV2($formV2); + + $constantContact = new ConstantContact($payload); + + $constantContact->process(); + + $block = $payload->formV3->blocks->findByName('givewp/constantcontact'); + + $this->assertTrue(true, $block->getAttribute('checked' === 'on')); + $this->assertSame($meta['_give_constant_contact_custom_label'], $block->getAttribute('label')); + $this->assertSame($meta['_give_constant_contact'], $block->getAttribute('selectedEmailLists')); + } + + /** + * @unreleased + */ + public function testProcessShouldUpdateConstantContactBlockAttributesWithGlobalSettings(): void + { + $meta = [ + 'give_constant_contact_label' => 'Subscribe to our newsletter?', + 'give_constant_contact_checked_default' => 'on', + 'give_constant_contact_list' => ['1928414891'], + ]; + + $formV2 = $this->createSimpleDonationForm(['meta' => $meta]); + + $payload = FormMigrationPayload::fromFormV2($formV2); + + foreach ($meta as $key => $value) { + give_update_option($key, $value); + } + + $constantContact = new ConstantContact($payload); + + $constantContact->process(); + + $block = $payload->formV3->blocks->findByName('givewp/constantcontact'); + + $this->assertTrue(true, $block->getAttribute('checked' === 'on')); + $this->assertSame($meta['give_constant_contact_label'], $block->getAttribute('label')); + $this->assertSame($meta['give_constant_contact_list'], $block->getAttribute('selectedEmailLists')); + } + + /** + * @unreleased + */ + public function testProcessShouldUpdateConstantContactBlockAttributesWhenNoMeta(): void + { + $formV2 = $this->createSimpleDonationForm(); + + $payload = FormMigrationPayload::fromFormV2($formV2); + + $constantContact = new ConstantContact($payload); + + $constantContact->process(); + + $block = $payload->formV3->blocks->findByName('givewp/constantcontact'); + + $this->assertTrue(true, $block->getAttribute('checked' === 'on')); + $this->assertSame('Subscribe to our newsletter?', $block->getAttribute('label')); + $this->assertNull(null, $block->getAttribute('selectedEmailLists')); + } +}