Skip to content

Conversation

@piotraifwc
Copy link
Owner

@piotraifwc piotraifwc commented Jun 9, 2025

CodeAnt-AI Description

  • Introduced the aroundPrepareItemsQty method as a plugin to intercept the invoice item quantity preparation process.
  • When the $force parameter is set to true, the method sets all item quantities in the result to 1, overriding the original values.
  • This change provides greater control and extensibility for customizing invoice item quantities during invoice creation.

This PR enhances the invoice preparation workflow by allowing forced adjustment of item quantities, supporting scenarios where all items should be invoiced in a fixed quantity. It improves the flexibility and customizability of the invoice process.


Changes walkthrough

Relevant files
Enhancement
AddTransactionCommentAfterCapture.php
Add plugin method to override invoice item quantities during
preparation

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

  • Added a new aroundPrepareItemsQty plugin method to intercept and
    modify invoice item quantities.
  • Allows forcing all item quantities in the result array to 1 when the
    $force parameter is true.
  • Enhances flexibility in the invoice preparation process by enabling
    custom quantity handling.
  • +26/-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

    Doc Block Inconsistency
    The doc comment for the method aroundPrepareItemsQty does not include documentation for the $order parameter. Consider adding a @param Order $order annotation to clarify its purpose.

    Code Readability
    The block inside the if ($force) condition (lines 79–83) sets all item quantities to 1 without explanation. Adding an inline comment to describe the business rationale, or refactoring the loop (for example, with array_map) for clarity could improve maintainability.

    @codeant-ai
    Copy link

    codeant-ai bot commented Jun 9, 2025

    CodeAnt AI finished reviewing your PR.

    * @param array $orderItemsQtyToInvoice
    * @param bool $force
    */
    public function aroundPrepareItemsQty(
    Copy link
    Owner Author

    Choose a reason for hiding this comment

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

    @CodeAnt-AI ask: Are you sure I can create an around plugin here? I’m trying to do it for a method that is private.

    Copy link

    Choose a reason for hiding this comment

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

    Answer:

    Magento plugins only intercept public methods. If you’re trying to apply an around plugin to a private method, it won’t work because Magento’s interception mechanism doesn't support private methods.

    For example, if you intended to intercept a method named prepareItemsQty, ensure that the target method in the subject class is public. If it’s private, you might need to refactor the method to be public or consider an alternative approach (like using a preference) to modify its behavior.

    Hope this clarifies the issue. Let me know if you have any more questions!

    @piotraifwc
    Copy link
    Owner Author

    @CodeAnt-AI: review

    @codeant-ai codeant-ai bot added size:S This PR changes 10-29 lines, ignoring generated files and removed size:S This PR changes 10-29 lines, ignoring generated files labels 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

    Documentation Issue
    The PHPDoc block for the aroundPrepareItemsQty method does not document the $order parameter present in the method signature. Consider updating the doc block to include all parameters for better clarity and maintainability.

    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