Skip to content

quality-debt: inc/checkout/class-cart.php — PR #1278 review feedback (high) #1289

@superdav42

Description

@superdav42

Unactioned Review Feedback

Source PR: #1278
File: inc/checkout/class-cart.php
Reviewers: coderabbit
Findings: 1
Max severity: high


HIGH: coderabbit (coderabbitai[bot])

File: inc/checkout/class-cart.php:356
⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Skipped carts still validate as usable.

If this filter returns true, the constructor exits with $this->errors empty and no cart state built. Cart::is_valid() will still return true, so Checkout::process_order() can keep going with a zero-item cart instead of stopping the flow.

💡 Suggested fix
-		if (apply_filters('wu_cart_skip_initialization', false, $args, $this)) {
+		$skip_initialization = apply_filters('wu_cart_skip_initialization', false, $args, $this);
+
+		if ($skip_initialization) {
+			if ($skip_initialization instanceof \WP_Error) {
+				$this->errors->merge_from($skip_initialization);
+			} elseif ( ! $this->errors->has_errors()) {
+				$this->errors->add('cart_initialization_skipped', __('This checkout is not available.', 'ultimate-multisite'));
+			}
+
 			return;
 		}

As per coding guidelines, "Use WP_Error for validation/operation failures instead of exceptions; check return values with is_wp_error()".

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

		$skip_initialization = apply_filters('wu_cart_skip_initialization', false, $args, $this);

		if ($skip_initialization) {
			if ($skip_initialization instanceof \WP_Error) {
				$this->errors->merge_from($skip_initialization);
			} elseif ( ! $this->errors->has_errors()) {
				$this->errors->add('cart_initialization_skipped', __('This checkout is not available.', 'ultimate-multisite'));
			}

			return;
		}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@inc/checkout/class-cart.php` around lines 354 - 356, The constructor
early-return when apply_filters('wu_cart_skip_initialization', ...) leaves
$this->errors empty so Cart::is_valid() still returns true; instead, when the
filter returns true populate $this->errors with a WP_Error (e.g. 'cart_skipped'
code and a short message) in the same block before returning so downstream
callers like Checkout::process_order() can detect the failure via
is_wp_error()/is_valid checks; modify the block around the apply_filters call in
the Cart class constructor (same scope as the existing apply_filters line) to
set a WP_Error on $this->errors and then return.

View comment



Auto-generated by quality-feedback-helper.sh scan-merged. Review each finding and either fix the code or dismiss with a reason.


aidevops.sh v3.19.5 automated scan.

Metadata

Metadata

Assignees

Labels

origin:workerAuto-created by pulse labelless backfill (t2112)priority:highHigh severity — significant quality issuequality-debtUnactioned review feedback from merged PRssolved:workerTask was solved by a headless workersource:review-feedbackAuto-created by quality-feedback-helper.sh

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions