2

I have developed one module for membership.There are three option for membership on order review section.Custom fee will add the based on the membership selection.I have download the custom fee module and implement it.But how can i set the fee based on the selection.

Please see this image.

enter image description here

I have created the custom model and controller file.If i use default model file and put the static value of fee then it works fine.

My Model File.

<?php
/**
 * Created by Magentix
 * Based on Module from "Excellence Technologies" (excellencetechnologies.in)
 *
 * @category   Magentix
 * @package    Magentix_Fee
 * @author     Matthieu Vion (http://www.magentix.fr)
 * @license    This work is free software, you can redistribute it and/or modify it
 */

class Magentix_Fee_Model_Sales_Quote_Address_Total_Fee extends Mage_Sales_Model_Quote_Address_Total_Abstract
{

    protected $_code = 'fee';

    /**
     * Collect fee address amount
     *
     * @param Mage_Sales_Model_Quote_Address $address
     * @return Magentix_Fee_Model_Sales_Quote_Address_Total_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;
        }

        $quote = $address->getQuote();

        if (Magentix_Fee_Model_Fee::canApply($address)) {

            $totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals(); //Total object
            $subtotal = $totals["subtotal"]->getValue(); //Subtotal value

            $percentage = 10;
            $totalWidth = $subtotal;

            $new_width = ($percentage / 100) * $totalWidth;

            $balance = $new_width;

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

            $quote->setFeeAmount($balance);

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

        return $this;
    }

    /**
     * Add fee information to address
     *
     * @param Mage_Sales_Model_Quote_Address $address
     * @return Magentix_Fee_Model_Sales_Quote_Address_Total_Fee
     */
    public function fetch(Mage_Sales_Model_Quote_Address $address)
    {
        $amount = $address->getFeeAmount();
        $address->addTotal(array(
            'code' => $this->getCode(),
            'title' => Mage::helper('fee')->__('Fee'),
            'value' => $amount
        ));
        return $this;
    }

}

In the phtml file I have run the controller using ajax.

<input type = "radio" name = "radSize" class = "radio" id = "sizeLarge" value = "10"/>Membership 1yr
<input type = "radio" name = "radSize" class = "radio" id = "sizeLarge" value = "20"/> Membership 2yr
<input type = "radio" name = "radSize" class = "radio" id = "sizeLarge" value = "30" /> Membership 3yr

<script>
jQuery(".radio").on('change', function(e){ 


   jQuery.ajax({
                type: "POST",
                url: '<?php echo Mage::getBaseUrl()?>fee/cc/subscribe',
                data: "fsdf", //--> send id of checked checkbox on other page
                success: function(data) {


                   }
            });

    });
</script> 

This is my controller file.

<?php


class Magentix_Fee_CcController extends Mage_Core_Controller_Front_Action
{

     public function subscribeAction()
        {

                $quote = Mage::getSingleton('checkout/session')->getQuote();

                $canAddItems = $quote->isVirtual() ? ('billing') : ('shipping');
                foreach ($quote->getAllAddresses() as $address) {


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

            $quote->setFeeAmount($balance);

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

                    echo $block = $this->getLayout()->createBlock('checkout/cart_totals')->setTemplate('checkout/onepage/review/totals.phtml')->toHtml();
                    }
                }

    }

Now i want to set the fee value using the controller or anyhow when select the radio button. can anyone please help me??

1 Answer 1

1

You need to create one column in Quote table and when controller action call than time you set fee value as per your need

and get that price to dispay in total

4
  • Where i set my custom fee? In the model file? Mar 29, 2018 at 11:23
  • no in ther controller action Mar 30, 2018 at 5:53
  • and get that valur in model file Mar 30, 2018 at 5:54
  • i did the same way as you said , but it does not works . in the model file it the shipping method set to zero.i don't know why!!! Mar 30, 2018 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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