1

Am trying to set discount price without using coupon. Discount apply but i have creating a checkbox in checkout/onepage if i click checkbox discount apply else discount don't apply here.

enter image description here

Following my code:

PHTML:

<div class="panel panel-default">
    <div class="panel-heading" style="padding: 2px 15px;">
        <label class="checkbox">
            <input id="epayment" value="" type="checkbox" name="payment[method]" title="Payment By Your EPayment" onclick=""  class="pull-left" autocomplete="off" data-toggle="collapse" data-target="#demo">
               Payment By EPayment     
        </label>
    </div>
    <div class="panel-body collapse" id="demo">
        <div class="row">
            <div class="col-md-4">
                <label>Payment To Be Made</label>
                <input type="text" name="cart_amount" id="cart_amount" value="1900">
            </div>
            <div class="col-md-4">
                <label>Your Balance Amount</label>
                <input type="text" name="epayment_amount" id="epayment_amount" value="2000">
            </div>
            <div class="col-md-4">
                <label id="left_amount_label">Left Amount To Be Pay</label>
                <input type="text" name="left_amount" id="left_amount" value="">
            </div>
        </div>
    </div>
</div>
<!-- ajax for subtract grand total -->
<script type="text/javascript">
    jQuery('#epayment').click(function() {
        var result = document.getElementById('cart_amount').value;
        var mageurl = "<?php echo Mage::getBaseUrl() ?>epayment/index/getepayment";
        jQuery.ajax({
            url     : mageurl,
            type    : "POST",
            dataType : "json",
            data    : {"cart_amount" : result},
            success : function(data){
                console.log(data);
            }});
    });
</script>
<!-- ajax for subtract grand total -->

Controller:

class EPayment_EPayment_IndexController extends Mage_Core_Controller_Front_Action{
  public function getepaymentAction()
  {
    $params = $this->getRequest()->getParams();
    $cart_amount = $params['cart_amount'];
    if($cart_amount > 0){
      //Mage::dispatchEvent('sales_quote_collect_totals_after', array('cart_amount' => $cart_amount));
      Mage::dispatchEvent('sales_quote_collect_totals_after', ['cart_amount' => $cart_amount]);
      $this->getResponse()->setHeader('Content-type', 'application/json');
      $this->getResponse()->setBody($cart_amount);
    }
  }
}

Model/Observer:

class EPayment_EPayment_Model_Observer
{

public function setDiscount($observer)
{
$quote = $observer->getEvent()->getQuote();
$quote = $observer->getEvent()->getQuote();
  $cart_amount = $quote->getBaseSubtotal();
  $quoteid = $quote->getId();

  $discountAmount = $total;
   // some code here
   // ...
   // ...
}
}

I have pass cart_amount using ajax, And then get ajax data in controller.

Your Answer

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

Browse other questions tagged or ask your own question.