Bagisto Forum

    Bagisto

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups

    How can i apply the new qty to refund items of refund object?

    General Discussion
    2
    2
    1120
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      enamulislamjisan last edited by

      96aaa080-740c-4837-a4fa-876103fe4b2a-image.png

      I want to change the refund qty for partial refund fails. If i update mannually in refund item that does not update order calculation and refund calculation even if collectTotals called.

      V 1 Reply Last reply Reply Quote 0
      • V
        vaibahv_bagisto @enamulislamjisan last edited by

        @enamulislamjisan
        Updating only the qty on a refund item is not enough. The collectTotals() methods do not recalculate item amounts from the quantity—they only sum the values already stored on the refund items.

        Because of this, changing refund_item.qty alone leaves fields such as total, base_total, tax_amount, and discount_amount unchanged, so the refund and order totals remain the same.

        Recommended approach

        If you're modifying the refund quantity for a partial refund, update the quantity before creating the refund. The RefundRepository::create() method calculates all refund item amounts, refund totals, order totals, and inventory adjustments based on the quantities provided in the input data.

        For example:

        $data['refund']['items'][$orderItemId] = $newQty;
        
        $refund = $refundRepository->create($data);
        

        This ensures all related calculations are performed correctly.

        If the refund has already been created

        If you need to modify an existing refund, changing the qty alone is insufficient. You must also recalculate the refund item's monetary fields (such as total, base_total, tax_amount, and discount_amount) based on the new quantity, then call the appropriate collectTotals() methods to update the refund and order aggregates.

        Keep in mind that if the refund quantity changes after creation, you may also need to adjust inventory manually, as inventory updates are handled during refund creation and are not recalculated by collectTotals().

        1 Reply Last reply Reply Quote 0
        • First post
          Last post