1

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;
    }
}
  • Post your Model and Helper code. – Slimshadddyyy Aug 28 '14 at 12:19
  • helper : class Excellence_Fee_Helper_Data extends Mage_Core_Helper_Abstract { public function formatFee($amount){ return Mage::helper('fee')->__('Fee'); } } – Surya prakash Patel Aug 28 '14 at 12:59
2

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;

  • problem is same, how i get the data(free_amount) from input field(t_credit) at cart page. i am using Mage::app()->getRequest()->getParam('t_credit') but not work.. – Surya prakash Patel Aug 28 '14 at 13:17
  • If you're really setting the param from model or helper, you can fetch it. If printing it gives you null then the value is not set. – Slimshadddyyy Aug 28 '14 at 13:21
  • I got problem... I was using the POST parameter at Helper, but when cart controller again load the cart/index after updatecart action Helper losses the at parameter and return "0"....... so we can set the POST value to a variable in Updatecart action and then can use it for cart/index page. .... In my case i save that value in Quote table then use it in cart page... problem solved. – Surya prakash Patel Aug 29 '14 at 6:57

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.