Magento – Magento Credit Memo – Qty to refund problem

creditmemomagento-1.7

I've creating a new table in which I capture all order states and statuses.
I've got everything working fine including refunds.
I've run into an issue though! I've put a scenario below so you can see what I mean

Order 001

  • Product 1 – qty 4 – price – 20.00
  • Product 2 – qty 2 – price – 15.00

If I refund 1 of product 1 a new row will be inserted in the DB as a negative number which is correct. Something along the lines of:-

 TableID  Name            Qty          Price
 1        Product1        -1           -20.00

If I then want to refund another of product 1, I want the table to look like the following:-

TableID  Name            Qty          Price
 1        Product1        -1           -20.00
 2        Product1        -1           -20.00

BUT what is actually inserting is this:-

TableID  Name            Qty          Price
 1        Product1        -1           -20.00
 2        Product1        -2           -20.00

So if we then look to tally up how many refunds occurred against product one it looks like there was three. Actually there was only two.

I was doing something like :

private function _getOrderItemDataXm1($order) {
   $i = array();
   foreach($order->getAllItems() as $item) {
         $i[‘qty’] = $item->getQtyRefunded();
   }
}

What this is actually returning is the amount that has already been refunded and the amount that is about to be refunded.
I just want to return the amount that is about to be refunded as a new row in the DB.

Anyone any ideas? Bit stuck with this

Thanks

Best Answer

So the quickest thing I can suggest is what Douglas has mentioned in the comments. You can look up the number you already have your table and do a simple deduction.

Any other suggestions would need more information. If you are doing your addition in the class Mage_Sales_Model_Order_Creditmemo_Item or one of its events you might be able to hook onto the value before it is saved in the register function.

When dealing with Mage_Sales_Model_Order_Creditmemo_Item a call to $this->getQty should give you the number that is currently being refunded.

Related Topic