Skip to content

Fix addon checkout item field parsing#3106

Merged
Saksham-Sirohi merged 2 commits intofossasia:devfrom
ArnavBallinCode:fix/addons-checkout-selection-bug
Mar 31, 2026
Merged

Fix addon checkout item field parsing#3106
Saksham-Sirohi merged 2 commits intofossasia:devfrom
ArnavBallinCode:fix/addons-checkout-selection-bug

Conversation

@ArnavBallinCode
Copy link
Copy Markdown
Member

@ArnavBallinCode ArnavBallinCode commented Mar 31, 2026

Screenshot 2026-03-31 at 12 38 22 PM Screenshot 2026-03-31 at 12 38 33 PM

Summary by Sourcery

Bug Fixes:

  • Fix addon selection parsing by supporting both _item_ and legacy _product_ POST parameter formats for quantities and prices.

Copilot AI review requested due to automatic review settings March 31, 2026 07:01
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Mar 31, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts add-on checkout parsing to support both new item POST field names and legacy product names when extracting quantity and price for non-variation add-ons.

Sequence diagram for updated add-on item field parsing

sequenceDiagram
    participant Request
    participant AddOnsStep
    participant POSTData

    Request->>AddOnsStep: call _clean_category(form, category)
    loop non_variation_addon_items
        AddOnsStep->>AddOnsStep: build item_key
        AddOnsStep->>AddOnsStep: build legacy_product_key

        AddOnsStep->>POSTData: get item_key
        POSTData-->>AddOnsStep: quantity_or_none
        AddOnsStep->>POSTData: get legacy_product_key (fallback)
        POSTData-->>AddOnsStep: legacy_quantity_or_none
        AddOnsStep->>AddOnsStep: val = int(item_quantity or legacy_quantity or 0)

        AddOnsStep->>POSTData: get item_key_price
        POSTData-->>AddOnsStep: price_or_none
        AddOnsStep->>POSTData: get legacy_product_key_price (fallback)
        POSTData-->>AddOnsStep: legacy_price_or_none
        AddOnsStep->>AddOnsStep: price = item_price or legacy_price or 0

        AddOnsStep->>AddOnsStep: if val > 0: selected[i, None] = (val, price)
    end
    AddOnsStep-->>Request: cleaned category selections
Loading

File-Level Changes

Change Details Files
Update POST field parsing for non-variation add-ons to be backward compatible with both new and legacy field name conventions.
  • Replace use of product POST key prefix with item for the primary lookup when reading add-on quantity and price.
  • Introduce fallback to legacy product POST keys when item keys are absent for both quantity and price.
  • Ensure the selected add-on entries are still only stored when a non-zero quantity is provided.
app/eventyay/presale/checkoutflowstep/add_ons_step.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • Consider extracting the repeated POST key lookup logic for val and price into a small helper to reduce duplication and make the precedence between _item_ and _product_ keys clearer.
  • It might be worth adding a brief code comment explaining that _item_ is the new format and _product_ is kept for backward compatibility, so future maintainers understand why both are checked.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider extracting the repeated POST key lookup logic for `val` and `price` into a small helper to reduce duplication and make the precedence between `_item_` and `_product_` keys clearer.
- It might be worth adding a brief code comment explaining that `_item_` is the new format and `_product_` is kept for backward compatibility, so future maintainers understand why both are checked.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a mismatch between the add-on checkout form field names and the backend parsing logic in the presale checkout flow, so selected add-ons without variations are correctly recognized during checkout.

Changes:

  • Update add-on quantity parsing to read cp_<cartpos>_item_<item_id> (current template/test format).
  • Add backward-compatible fallback to the legacy cp_<cartpos>_product_<item_id> field name for both quantity and free-price fields.

Copy link
Copy Markdown
Collaborator

@Saksham-Sirohi Saksham-Sirohi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Saksham-Sirohi Saksham-Sirohi merged commit 299a2a1 into fossasia:dev Mar 31, 2026
5 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in Eventyay Next Mar 31, 2026
@ArnavBallinCode ArnavBallinCode deleted the fix/addons-checkout-selection-bug branch April 4, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants