0

Task: Give discount(%) without coupon code to user when create order from admin . it override default coupon code

  1. what I was trying provide discount(%) to user when create order from admin panel.
  2. Discount shouldn't show on front end because it's for back-end admin order create.

4.it should be shown on invoice & email templates also.

reference : [https://github.com/erenkarayigit/Fee][2]

[http://magentoexplorer.com/how-to-add-fee-or-discount-to-order-totals-in-magento-1-9][3]

here's my observer:

class Lalit_Discount_Model_Observer
{
    public function orderAfter(Varien_Event_Observer $observer)
    {

        $event = $observer->getEvent();
        $order = $event->getOrder();


        $order_id = $order->getId();
        $prams = Mage::app()->getRequest()->getParams();


        $dis = $prams['discountmanually']*0.01;

         $order = Mage::getModel('sales/order')->load($order_id);
         $order->setDiscountManually($dis);
         $order->save();
    }   
}

app\code\local\Lalit\Discount\etc

<?xml version="1.0"?>
<config>
  <modules>
    <Lalit_Discount>
      <version>0.1.0</version>
    </Lalit_Discount>
  </modules>
  <global>
    <helpers>
      <discount>
        <class>Lalit_Discount_Helper</class>
      </discount>
    </helpers>
    <blocks>
      <discount>
        <class>Lalit_Discount_Block</class>
      </discount>

    </blocks>
    <models>
      <discount>
        <class>Lalit_Discount_Model</class>
        <resourceModel>discount_mysql4</resourceModel>
      </discount>
    </models>
    <resources>
      <salesattribute1462007764_setup>
        <setup>
          <module>Lalit_Discount</module>
          <class>Mage_Sales_Model_Mysql4_Setup</class>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </salesattribute1462007764_setup>
      <salesattribute1462007764_write>
        <connection>
          <use>core_write</use>
        </connection>
      </salesattribute1462007764_write>
      <salesattribute1462007764_read>
        <connection>
          <use>core_read</use>
        </connection>
      </salesattribute1462007764_read>
    </resources>

  </global>
  <admin>
    <routers>
      <discount>
        <use>admin</use>
        <args>
          <module>Lalit_Discount</module>
          <frontName>admin_discount</frontName>
        </args>
      </discount>
    </routers>
  </admin>
  <adminhtml>
    <events>
      <sales_order_place_after> <!-- identifier of the event we want to catch -->
        <observers>
          <sales_order_place_after> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>discount/observer</class> <!-- observers class alias -->
            <method>orderAfter</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </sales_order_place_after>
        </observers>
      </sales_order_place_after>
    </events>

    <layout>
      <updates>
        <discount>
          <file>discount.xml</file>
        </discount>
      </updates>
    </layout>
  </adminhtml>
</config>

app\code\local\Lalit\Discount\sql\salesattribute1462007764_setup\mysql4-install-0.1.0.php

$installer = $this;
$installer->startSetup();

$installer->addAttribute("order", "discountmanually", array("type"=>"varchar"));
$installer->endSetup();

app\code\local\Lalit\Discount\controllers\Adminhtml\DiscountbackendController.php

class Lalit_Discount_Adminhtml_DiscountbackendController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
       $this->loadLayout();
       $this->_title($this->__("Backend Page Title"));
       $this->renderLayout();
    }
}

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

<?xml version="1.0"?>
<layout version="0.1.0">
  <discount_adminhtml_discountbackend_index>
    <reference name="content">
      <block type="discount/adminhtml_discountbackend" name="discountbackend" template="discount/discountbackend.phtml"/>
    </reference>
  </discount_adminhtml_discountbackend_index>

  <adminhtml_sales_order_create_index>
    <reference name="items">
        <action method="setTemplate">
            <template>discount/discount-discount-form.phtml</template>
        </action>
    </reference>
  </adminhtml_sales_order_create_index>

  <adminhtml_sales_order_create_load_block_items>
  <reference name="items">
        <action method="setTemplate">
            <template>discount/discount-form.phtml</template>
        </action>
    </reference>
  </adminhtml_sales_order_create_load_block_items>

  <adminhtml_sales_order_create_load_block_data>
  <reference name="items">
        <action method="setTemplate">
            <template>discount/discount-form.phtml</template>
        </action>
    </reference>
  </adminhtml_sales_order_create_load_block_data>

  <adminhtml_sales_order_view>
    <reference name="order_info">
        <action method="setTemplate">
            <template>discount/discount-info.phtml</template>
        </action>
    </reference>
  </adminhtml_sales_order_view>

</layout>

app\design\adminhtml\default\default\template\discount\discount-form.phtml

<div class="entry-edit">
    <div class="entry-edit-head">
        <h4 class="icon-head head-cart"><?php echo $this->getHeaderText() ?></h4>
        <div class="form-buttons"><?php echo $this->getButtonsHtml() ?></div>
    </div>
    <?php echo $this->getChildHtml() ?>
</div>

<div class=""><div class="entry-edit" style="position: relative;">
    <div class="entry-edit-head">
        <div style="float: right;"></div>
        <h4 class="fieldset-legend head-shipping-method icon-head">Discount offer</h4>
    </div>
    <div class="fieldset">

        Discount: <input type="text" name="discountmanually" class="required-entry"/><br><br>


    </div>
    </div>
</div>
  • what's the question here? – Marius Nov 15 '16 at 8:33
  • const FEE_AMOUNT = 20 get this data from database – lalit mohan Nov 15 '16 at 8:34
  • then edit the question and explain exactly what you need. – Marius Nov 15 '16 at 8:35
  • @Marius I updated my Question – lalit mohan Dec 13 '16 at 7:19

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.