Conversation
minicart offers support added
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThis pull request adds mini-cart offer functionality to the HelloExtend Protection plugin. A new public method Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@helloextend-protection/includes/class-helloextend-protection-cart-offer.php`:
- Around line 287-295: The loop in class HelloExtend_Protection_Cart_Offer
(method where $categories is iterated) uses the wrong variable name: it checks
$ignored instead of the lookup table $ignored_set, so ignored categories never
get skipped; update the conditional inside the foreach to test
isset($ignored_set[(int)($cat ?? 0)]) and invert the logic so you only break
when the category is not in $ignored_set (i.e., if
(!isset($ignored_set[(int)($cat ?? 0)])) { $category = $term ?? 'Uncategorized';
break; }), ensuring you reference $ignored_set rather than $ignored.
- Around line 267-317: Initialize $cart_contents as an empty array before the
foreach over WC()->cart->get_cart(), and inside the loop skip any
warranty/Extend rows by checking for the extend marker (e.g., if ( isset(
$cart_item['extendData'] ) ) continue; ), so they are not serialized into
$cart_contents; also fix the variable-name bug by using $ignored_set (not
$ignored) when checking ignored categories in the foreach that assigns
$category.
- Around line 249-253: minicart_offers() and cart_offers() both call
wp_localize_script with the same global name ExtendCartIntegration, causing one
payload to overwrite the other; change the localization keys so they are unique
(e.g., use ExtendMinicartIntegration for minicart_offers() and keep
ExtendCartIntegration for cart_offers()), update the corresponding
wp_localize_script calls and any client-side references to those globals, and
ensure the script handle passed to wp_localize_script still matches the enqueued
script in both functions.
- Around line 297-305: minicart_offers() is passing price_raw as WooCommerce's
decimal string while after_cart_item_name() expects a cents integer (converted
via (int) floatval($price * 100)), causing mini-cart prices to be 100x too low;
update minicart_offers() to normalize price_raw to cents by converting the
product price (e.g., $product->get_price()) to an integer cents value using the
same logic as after_cart_item_name() before including it in the $item array so
Extend.buttons.renderSimpleOffer() receives a cents integer; ensure you update
the 'price_raw' assignment in the array built in minicart_offers() and keep
'price_formatted' as the human-readable wc_price() string.
In `@helloextend-protection/js/helloextend-minicart-offers.js`:
- Around line 20-29: The code pulls item fields from the stale global
ExtendCartIntegration.cart_contents using cart_item_key inside
initMiniCartOffers instead of using the fresh cart payload passed from
getCart(); update initMiniCartOffers (and other spots using
ExtendCartIntegration.cart_contents such as the blocks around the
sku/name/price/quantity/category and the occurrences noted at the other
locations) to read item metadata from the incoming cart parameter (e.g.,
cart.items or cart.contents) for the given cart_item_key, falling back to
ExtendCartIntegration.cart_contents only if the cart param is absent; ensure
getCart()'s fresh cart is actually consumed so AJAX fragment updates produce
correct item data.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 788c5dad-77fa-42c8-9ba6-61ad90712452
📒 Files selected for processing (3)
helloextend-protection/includes/class-helloextend-protection-cart-offer.phphelloextend-protection/includes/class-helloextend-protection.phphelloextend-protection/js/helloextend-minicart-offers.js
- variable $cart_Contents was not properly initialized - cart normalization did not exist in the minicart.
minicart offers support added
Summary by CodeRabbit