Skip to content
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

Fix fatal error when fetching marketing campaigns for Marketing Channel #2423

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/MultichannelMarketing/GLAChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,20 @@ public function __construct( MerchantCenterService $merchant_center, AdsCampaign
$this->product_sync_stats = $product_sync_stats;
$this->campaign_types = [];

if ( apply_filters( 'woocommerce_gla_enable_mcm', false ) === true ) {
if ( $this->is_mcm_enabled() ) {
$this->campaign_types = $this->generate_campaign_types();
}
}

/**
* Determines if the multichannel marketing is enabled.
*
* @return bool
*/
protected function is_mcm_enabled(): bool {
return apply_filters( 'woocommerce_gla_enable_mcm', false ) === true;
}

/**
* Returns the unique identifier string for the marketing channel extension, also known as the plugin slug.
*
Expand Down Expand Up @@ -176,7 +185,7 @@ public function get_supported_campaign_types(): array {
* @return MarketingCampaign[]
*/
public function get_campaigns(): array {
if ( ! $this->ads->ads_id_exists() ) {
if ( ! $this->ads->ads_id_exists() || ! $this->is_mcm_enabled() ) {
return [];
}

Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/MultichannelMarketing/GLAChannelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,16 @@ public function test_disabled_filter_returns_no_campaign_types() {
$this->assertEquals( [], $channel->get_supported_campaign_types() );
}

public function test_get_campaigns_returns_empty_if_filter_is_disabled() {
remove_filter( 'woocommerce_gla_enable_mcm', '__return_true' );
$this->ads->expects( $this->once() )->method( 'ads_id_exists' )->willReturn( true );
$this->ads_campaign
->expects( $this->never() )
->method( 'get_campaigns' );

$this->assertEmpty( $this->gla_channel->get_campaigns() );
}

/**
* Runs before each test is executed.
*/
Expand Down