Skip to content

Conversation

@piotraifwc
Copy link
Owner

@piotraifwc piotraifwc commented Jun 9, 2025

CodeAnt-AI Description

  • Introduced an aroundPrepareInvoice plugin method to intercept and modify the behavior of invoice preparation.
  • When the $force parameter is true, the method sets the quantity to invoice for each eligible order item to 1, overriding the original $qtys array.
  • The modified quantities are then passed to the original prepareInvoice method, ensuring controlled invoice creation under specific conditions.

This enhancement provides greater flexibility and control over invoice creation by allowing forced single-quantity invoicing for all items in an order. It is particularly useful for scenarios where a uniform invoicing approach is required regardless of the original requested quantities.


Changes walkthrough

Relevant files
Enhancement
AddTransactionCommentAfterCapture.php
Add around plugin to modify invoice preparation quantities when forced

app/code/Magento/Sales/Plugin/Model/Service/Invoice/AddTransactionCommentAfterCapture.php

  • Added a new aroundPrepareInvoice method as a plugin interceptor.
  • Implements logic to modify the $qtys parameter when $force is true,
    setting each invoiceable order item quantity to 1.
  • Ensures the modified $qtys is passed to the original prepareInvoice
    method.
  • Includes full PHPDoc block for the new method.
  • +24/-0   
    💡 Usage Guide

    Checking Your Pull Request

    Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

    Talking to CodeAnt AI

    Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

    @codeant-ai ask: Your question here
    

    This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

    Retrigger review

    Ask CodeAnt AI to review the PR again, by typing:

    @codeant-ai: review
    

    Check Your Repository Health

    To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

    @codeant-ai
    Copy link

    codeant-ai bot commented Jun 9, 2025

    CodeAnt AI is reviewing your PR.

    @codeant-ai codeant-ai bot added the size:S This PR changes 10-29 lines, ignoring generated files label Jun 9, 2025
    @codeant-ai
    Copy link

    codeant-ai bot commented Jun 9, 2025

    Pull Request Feedback 🔍

    🔒 No security issues identified
    ⚡ Recommended areas for review

    Invoice Quantity Override
    In the new aroundPrepareInvoice method, when the $force flag is true, the code overrides the invoice quantities by setting each qualifying item's value to 1. Please verify that this behavior meets the intended business logic and does not inadvertently ignore any customized quantity values.

    Type Hinting and Documentation
    The method signature uses the Order type without a fully qualified namespace in the diff. Ensure that the Order class is properly imported or namespaced. Also, consider adding an explicit return type declaration in the method signature for improved clarity and consistency.

    Comment on lines 74 to 81
    if ($force) {
    $modifiedQtys = [];
    foreach ($order->getAllItems() as $orderItem) {
    if ($orderItem->getQtyToInvoice() > 0) {
    $modifiedQtys[$orderItem->getId()] = 1;
    }
    }
    $qtys = $modifiedQtys;
    Copy link

    Choose a reason for hiding this comment

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

    Suggestion: Use the actual available invoicable quantity obtained from getQtyToInvoice() instead of hardcoding the value to 1 when the force flag is enabled. [Business Logic Update]

    Suggested change
    if ($force) {
    $modifiedQtys = [];
    foreach ($order->getAllItems() as $orderItem) {
    if ($orderItem->getQtyToInvoice() > 0) {
    $modifiedQtys[$orderItem->getId()] = 1;
    }
    }
    $qtys = $modifiedQtys;
    if ($force) {
    $modifiedQtys = [];
    foreach ($order->getAllItems() as $orderItem) {
    if ($orderItem->getQtyToInvoice() > 0) {
    $modifiedQtys[$orderItem->getId()] = $orderItem->getQtyToInvoice();
    }
    }
    $qtys = $modifiedQtys;
    }

    @codeant-ai
    Copy link

    codeant-ai bot commented Jun 9, 2025

    CodeAnt AI finished reviewing your PR.

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    size:S This PR changes 10-29 lines, ignoring generated files

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants