0

This is my class for add some custom totals to invoice:

class Devpassion_Rowtotal_Model_Order_Invoice_Total_Totalpopust extends Mage_Sales_Model_Order_Invoice_Total_Abstract{

public function collect(Mage_Sales_Model_Order_Invoice $invoice)
{

    $order = $invoice->getOrder();
    $items  = $invoice->getAllItems();


    foreach ($items as $item){
            $subtotaldisc = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount() - $item->getDiscountAmount();  
        }

    $invoice->setTotalpopustAmount($subtotaldisc);


    return $this;
}

   public function fetch(Mage_Sales_Model_Quote_Address $invoice)
{
    if ($invoice->getTotalpopust() > 0)
    {
        $invoice->addTotal(array(
            'code'  => $this->getCode(),
            'title' => Mage::helper('rowtotal')->__('Test tekst'),
            'value' => $invoice->getTotalpopust()
        ));
    }
    return $this;
}

}

And this is my inittotals() function:

class Devpassion_Rowtotal_Block_Sales_Total_Totalpopust
extends Mage_Core_Block_Abstract{
public function initTotals()
{
    $parent = $this->getParentBlock();

    $value = $parent->getSource()->getTotalpopust();



 //   if ($value > 0)
 //   {
        $total = new Varien_Object(array(
        'code'  => 'totalpopust',
        'value' => $parent->getSource()->getResult(),
        'base_value' => $parent->getSource()->getResult(),
        'label' => $this->__('Cijena sa popustom'),
        'field' => 'totalpopust'
        ));
        $parent->addTotal($total, 'totalpopust');
 //   }
    return $this;
}

}

Please can someone advice what is wrong in definition of this classes, because nothing shows up on Invoice, neither on print pdf (I have defined in config.xml to show in pdf), neither on adminhtml (I have defined layout for adminhtml).

4
  • Here is a nice tutorial on how to add a new total: turnkeye.com/blog/magento-development-add-total-row-checkout See if you missed something. – Marius Jul 9 '13 at 7:16
  • ok I see in this tutorial that setting up new and add new value to grand totals: $invoice->setGrandTotal($invoice->getGrandTotal() + $amount); – srdan Jul 9 '13 at 7:21
  • but I need new value, which won't add to grandtotals. How can I do that? As you can see from my class above I did it in that way: $invoice->setTotalpopustAmount($subtotaldisc); and before that I set up $subtotalsdisc like: $subtotaldisc = $item->getRowTotal() + $item->getTaxAmount() + $item->getHiddenTaxAmount() - $item->getDiscountAmount(); – srdan Jul 9 '13 at 7:21
  • I've never added a new total to the order, but I've used this extension: magentocommerce.com/magento-connect/cashondelivery.html. Maybe that could serve you as inspiration. – Marius Jul 9 '13 at 7:51
2

Did you add the entry to yout config.xml?

<global>
     <sales>
         <order_invoice>
             <totals>
                 <turnkeye_insurance>
                     <class>turnkeye_insurance/total_screen_invoice</class>
                     <after>subtotal</after>
                     <before>tax</before>
                 </turnkeye_insurance>
             </totals>
         </order_invoice>
     </sales>
</global>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.