1

I added an extra fee. It's working well at the checkout. enter image description here

But at the admin panel -> sales -> orders -> my order it doesn't show. enter image description here

But price is well. At the invoice too

enter image description here

How can I show it? I tried :

<fieldsets>
     <sales_convert_quote_address>
         <insurance><to_order>*</to_order></insurance>
         <insurance><to_order>*</to_order></insurance>
         <insurance><to_invoice_item>*</to_invoice_item></insurance>
     </sales_convert_quote_address>
</fieldsets>

But it doesn't help. Thanks advance.

EDIT:

class Cart_InsuranceUpsell_Model_Paymentinsurance extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
    protected $_code = 'Insurance Upsell';

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        if (Mage::getSingleton('checkout/session')->getInsuranceUpsellApply()) {
        parent::collect($address);

        $this->_setAmount(0);

        $items = $this->_getAddressItems($address);
        if (!count($items)) {
            return $this;
        }

        $quote = $address->getQuote();

            $exist_amount = $quote->getFeeAmount();
            $fee = $address->getGrandTotal() * (Mage::getStoreConfig('cart_insurance_upsells/configuration/discount_rate',Mage::app()->getStore())/100);
            $balance = $fee - $exist_amount;
            $address->setInsurance($balance);
            $quote->setInsurance($balance);
            $address->setGrandTotal($address->getGrandTotal() + $address->getInsurance());
        }
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
            $amt = $address->getInsurance();
            if ($amt > 0){
                $address->addTotal(array(
                    'code' => $this->getCode(),
                    'title' => 'Insurance Upsell',
                    'value' => $amt
                ));
                return $this;
            }
        return true;
    }
}

Config.xml :

  <config>
       <global>

        <pdf>
            <totals>
                <insurance>
                    <title>Upsell Insurance</title>
                    <model>cart_insurance_upsell/pdf_earning</model>
                    <font_size>7</font_size>
                    <display_zero>0</display_zero>
                    <sort_order>3</sort_order>
                </insurance>
            </totals>
        </pdf>

        <fieldsets>
            <sales_convert_quote_address>
                <insurance><to_order>*</to_order></insurance>
                <insurance><to_order>*</to_order></insurance>
                <insurance><to_invoice_item>*</to_invoice_item></insurance>
            </sales_convert_quote_address>
        </fieldsets>

        <sales>
            <quote>
                <totals>
                    <insurance>
                        <class>cart_insurance_upsell/paymentinsurance</class>
                    </insurance>
                </totals>
            </quote>
            <order_invoice>
                <totals>
                    <insurance>
                        <class>cart_insurance_upsell/earning</class>
                        <after>subtotal</after>
                    </insurance>
                </totals>
            </order_invoice>
        </sales>
 </global>
    </config>

And for the invoice:

class  Cart_InsuranceUpsell_Model_Earning extends Mage_Sales_Model_Order_Invoice_Total_Abstract
{
    public function collect(Mage_Sales_Model_Order_Invoice $invoice) {
        $order = $invoice->getOrder();
        $insurance = $order->getInsurance();

        $invoice->setInsurance($insurance);

        $invoice->setGrandTotal($invoice->getGrandTotal() + $insurance);

        return $this;
    }
}

And can u explain pls, how to work in config.xml that:

   <order_invoice>
                     <totals>
                         <insurance>
1
+50

Step 1 : Modify your config.xml code like this.

<global>
    <sales>
            <quote>
                <totals>
                    <insurance>
                        <class>cart_insurance_upsell/paymentinsurance</class>
                    </insurance>
                </totals>
            </quote>
            <order>
                <totals>
                    <insurance>
                        <class>cart_insurance_upsell/order_total_paymentinsurance</class>
                    </insurance>
                </totals>
            </order>
            <order_invoice>
                <totals>
                    <insurance>
                        <class>cart_insurance_upsell/earning</class>
                        <after>subtotal</after>
                    </insurance>
                </totals>
            </order_invoice>
        </sales>
    </global>
    <adminhtml>
        <layout>
            <updates>
                <insurance>
                    <file>insurance.xml</file>
                </insurance>
            </updates>
        </layout>
    </adminhtml>

Step 2 : create insurance.xml with below code at this location.

app\design\adminhtml\default\default\layout\insurance.xml

<?xml version="1.0"?>
<layout version="0.1.0">
    <adminhtml_sales_order_view>
        <reference name="order_totals">
            <block name="paymentinsurance" type="cart_insurance_upsell/adminhtml_sales_order_totals" />
        </reference>
    </adminhtml_sales_order_view>
</layout>

Step 3 : Create totals.php at this location with below code.

app\code\local\Vendor\Extension\Block\Adminhtml\Sales\Totals.php

<?php
class Vendor_Extension_Block_Adminhtml_Sales_Order_Totals extends Mage_Adminhtml_Block_Sales_Order_Totals 
{

    public function initTotals() 
    {
        if ($this->getSource()->getInsurance()!= 0)
        {
            $parent = $this->getParentBlock();

            $insurancefee = new Varien_Object(array(
            'code'  => 'insurance',
            'field' => 'insurance',
            'value' => $this->getSource()->getInsurance(),
            'label' => 'Insurance'
           ));

           $parent->addTotalBefore($insurancefee, 'grand_total');   
        }
        return $this;
    }
}

Step 4 : create Paymentinsurance.php with below code at this location.

app\code\local\Vendor\Extension\Model\Order\Total\Paymentinsurance.php

<?php
class Vendor_Extension_Model_Order_Total_Paymentinsurance extends Mage_Sales_Model_Order_Total_Abstract {

    public function collect(Mage_Sales_Model_Order_Order $order) 
    {
       $insurancefee = $order->getOrder()->getInsurance();
       $order->setInsurance($insurancefee);

    $order->setGrandTotal($order->getGrandTotal() + $insurancefee);
    $order->setBaseGrandTotal($order->getBaseGrandTotal() + $insurancefee);
    return $this;
    }
}  

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.