Skip to content

PHP Fatal error in 3.5.3 on CouponChannelVisibilityMetaBox - missing is_setup_complete context property #3287

@hardweb-it

Description

@hardweb-it

Describe the bug:

Critical (Fatal error, breaks coupon creation/editing page).

PHP Fatal error: Uncaught Automattic\WooCommerce\GoogleListingsAndAds\View\ViewException: 
The property "is_setup_complete" could not be found within the context of the currently rendered view.
in src/View/ViewException.php:70

The view template views/meta-box/coupon_channel_visibility.php accesses $this->is_setup_complete at line 40, but the method CouponChannelVisibilityMetaBox::get_view_context() in src/Admin/MetaBox/CouponChannelVisibilityMetaBox.php does not include is_setup_complete in the context array passed to the view.

Steps to reproduce:

  1. Install and activate Google Listings & Ads with Merchant Center connected
  2. Navigate to WooCommerce > Marketing > Coupons > Add coupon (/wp-admin/post-new.php?post_type=shop_coupon)
  3. The page throws a PHP Fatal error

Expected behavior:

The view expects these context properties: coupon_id, coupon, channel_visibility, field_id, is_setup_complete, is_channel_supported, get_started_url, sync_status, issues.

Actual behavior:

get_view_context() only provides 8 of these 9 properties, omitting is_setup_complete.
This produce a PHP Fatal error by opening /wp-admin/post-new.php?post_type=shop_coupon

Additional details:

Suggested fix:

Add the missing property to the context array in CouponChannelVisibilityMetaBox::get_view_context():

return [
    'field_id'             => $this->get_visibility_field_id(),
    'coupon_id'            => $coupon_id,
    'coupon'               => $coupon,
    'channel_visibility'   => $this->coupon_helper->get_channel_visibility( $coupon ),
    'sync_status'          => $this->meta_handler->get_sync_status( $coupon ),
    'issues'               => $this->coupon_helper->get_validation_errors( $coupon ),
    'is_setup_complete'    => $this->merchant_center->is_setup_complete(), // <-- missing line
    'is_channel_supported' => $this->merchant_center->is_promotion_supported_country( $target_country ),
    'get_started_url'      => $this->get_start_url(),
];

MerchantCenterService::is_setup_complete() already exists and is used elsewhere in the plugin. No additional dependencies are needed.

Tested: Fix confirmed working. After the change, the coupon creation page loads without errors.

Metadata

Metadata

Labels

Type

No fields configured for Bug.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions