Question

I have created a custom field in cart page named "t_price". NOw i need to calculate this price in cart page. I am using an extension "SSTech_Extracharge" to calculate extra price in cart and checkout page. Now i want to use that that custom field(t_price') in this extension.

This extension defines a constant variable in it's model, how i use the value from post.

class SSTech_Extracharge_Model_Extracharge extends Varien_Object{
const FEE_AMOUNT  = 10;
const XML_PATH_ENABLED = "extracharge/extracharge/enabled";

public static function getExtracharge(){
    if(Mage::getStoreConfigFlag(self::XML_PATH_ENABLED)){
        $extracharge = Mage::getStoreConfig(self::FEE_AMOUNT);
        return $extracharge;
    }
}
public static function canApply($address){

    return true;

}
}

Some one explain it, i am using const FEE_AMOUNT = Mage::app()->getRequest()->getParam('t_credit'); but it's not getting result.

Observer :

<?php
class Excellence_Fee_Model_Observer{
    public function invoiceSaveAfter(Varien_Event_Observer $observer)
    {
        $invoice = $observer->getEvent()->getInvoice();
        if ($invoice->getBaseFeeAmount()) {
            $order = $invoice->getOrder();
            $order->setFeeAmountInvoiced($order->getFeeAmountInvoiced() + $invoice->getFeeAmount());
            $order->setBaseFeeAmountInvoiced($order->getBaseFeeAmountInvoiced() + $invoice->getBaseFeeAmount());
        }
        return $this;
    }
    public function creditmemoSaveAfter(Varien_Event_Observer $observer)
    {
        /* @var $creditmemo Mage_Sales_Model_Order_Creditmemo */
        $creditmemo = $observer->getEvent()->getCreditmemo();
        if ($creditmemo->getFeeAmount()) {
            $order = $creditmemo->getOrder();
            $order->setFeeAmountRefunded($order->getFeeAmountRefunded() + $creditmemo->getFeeAmount());
            $order->setBaseFeeAmountRefunded($order->getBaseFeeAmountRefunded() + $creditmemo->getBaseFeeAmount());
        }
        return $this;
    }
    public function updatePaypalTotal($evt){
        $cart = $evt->getPaypalCart();
        $cart->updateTotal(Mage_Paypal_Model_Cart::TOTAL_SUBTOTAL,$cart->getSalesEntity()->getFeeAmount());
    }
}

Model :

 class Excellence_Fee_Model_Sales_Quote_Address_Total_Fee extends Mage_Sales_Model_Quote_Address_Total_Abstract{
    protected $_code = 'fee';

    public function collect(Mage_Sales_Model_Quote_Address $address)
    {
        parent::collect($address);

        $this->_setAmount(0);
        $this->_setBaseAmount(0);

        $items = $this->_getAddressItems($address);
        if (!count($items)) {
            return $this; //this makes only address type shipping to come through
        }


        $quote = $address->getQuote();

        if(Excellence_Fee_Model_Fee::canApply($address)){
            $exist_amount = $quote->getFeeAmount();
            $fee = Excellence_Fee_Model_Fee::getFee();
            $balance = $fee - $exist_amount;
            //          $balance = $fee;

            //$this->_setAmount($balance);
            //$this->_setBaseAmount($balance);

            $address->setFeeAmount($balance);
            $address->setBaseFeeAmount($balance);

            $quote->setFeeAmount($balance);

            $address->setGrandTotal($address->getGrandTotal() + $address->getFeeAmount());
            $address->setBaseGrandTotal($address->getBaseGrandTotal() + $address->getBaseFeeAmount());

        }
    }

    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        $amt = $address->getFeeAmount();
        $address->addTotal(array(
                'code'=>$this->getCode(),
                'title'=>Mage::helper('fee')->__('Fee'),
                'value'=> $amt
        ));
        return $this;
    }
}
Was it helpful?

Solution

Your Model file should look something like this

<?php
class Excellence_Fee_Model_Fee extends Varien_Object{
    const FEE_AMOUNT = 10;

    public static function getFee(){
        return self::FEE_AMOUNT;
    }
    public static function canApply($address){
        //put here your business logic to check if fee should be applied or not
        //if($address->getAddressType() == 'billing'){
        return true;
        //}
    }
}

where const FEE_AMOUNT = 10; is your defined Fee Amount.

Or you can do the same in your Helper file using something like below

<?php

class Excellence_Fee_Helper_Data extends Mage_Core_Helper_Abstract
{
        const FEE_AMOUNT = 10;

    public function formatFee($amount){
        return Mage::helper('fee')->__('Fee');
    }

    public static function getFee(){
        return self::FEE_AMOUNT;
    }
}

and to retrieve the value you can use

$feeValue = Mage::helper('module/model')->getFee(); echo $feeValue;

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top