1

I want to be able to show a message when my user clicks on the "checkout" button. Because I need to check if the final cart amount isn't lower then 30€.

So I figured it'll be best to show the message when the user clicks the checkout button.

I created this .xml, but don't know if that's the event to use "sales"

<config>
<modules>
    <Curiosidade_CompraInicial>
        <version>1.0.0.0</version>
    </Curiosidade_CompraInicial>
</modules>
<global>
    <models>
        <curiosidade_comprainicial>
            <class>Curiosidade_CompraInicial_Model</class>
        </curiosidade_comprainicial>
    </models>
    <helpers>
        <curiosidade_comprainicial>
            <class>Curiosidade_CompraInicial_Helper</class>
        </curiosidade_comprainicial>
    </helpers>      
</global>
<frontend>
    <events>
        <sales_quote_save_before> 
            <observers>
                <curiosidade_comprainicial_enforceSingleOrderLimit>
                    <class>curiosidade_comprainicial/observer</class>
                    <method>enforceCompraInicialLimit</method>
                </curiosidade_limitedinheiro_enforceSingleOrderLimit>
            </observers>
        </sales_quote_save_before>
    </events>
</frontend>
<default>
    <sales>
        <curiosidade_comprainicial>
            <active>1</active>
            <compra_inicial_montante>1500</compra_inicial_montante>
            <compra_inicial_montante_msg><![CDATA[Não pode fazer uma compra acima de %s.]]></compra_inicial_montante_msg>
        </curiosidade_comprainicial>
    </sales>
</default>

1 Answer 1

0

You can set minimum order from admin. Login into your admin account, go to system--> configuration -->sales(from left side bar) --> Minimum order amount. Enter your minimum order amount here, save it..That's it..!

Update: So you want set min order amount for a customer's first order only, Here we go..! For that you would need to override following event observer

controller_action_predispatch_checkout_onepage_index_handler

so for that, create a module and your Mypackage/Minorder/etc/config.xml file would be,

<?xml version="1.0"?>
<config>
  <modules>
    <Mypackage_Minorder>
      <version>0.1.0</version>
    </Mypackage_Minorder>
  </modules>
  <global>
    <helpers>
      <minorder>
        <class>Mypackage_Minorder_Helper</class>
      </minorder>
    </helpers>
    <models>
      <minorder>
        <class>Mypackage_Minorder_Model</class>
        <resourceModel>minorder_mysql4</resourceModel>
      </minorder>
    </models>
    <events>
      <controller_action_predispatch_checkout_onepage_index> <!-- identifier of the event we want to catch -->
        <observers>
          <controller_action_predispatch_checkout_onepage_index_handler> <!-- identifier of the event handler -->
            <type>model</type> <!-- class method call type; valid are model, object and singleton -->
            <class>minorder/observer</class> <!-- observers class alias -->
            <method>minorderAction</method>  <!-- observer's method to be called -->
            <args></args> <!-- additional arguments passed to observer -->
          </controller_action_predispatch_checkout_onepage_index_handler>
        </observers>
      </controller_action_predispatch_checkout_onepage_index>
    </events>
  </global>
</config> 

And Mypackage/Minorder/Model/Observer.php,

<?php
class Mypackage_Minorder_Model_Observer
{

   public function minorderAction(Varien_Event_Observer $observer)
    {

        if (Mage::getSingleton('customer/session')->isLoggedIn()) {

        /* Get the customer data */
         $customer = Mage::getSingleton('customer/session')->getCustomer();


        $orders = Mage::getResourceModel('sales/order_collection')
        ->addFieldToSelect('*')
        ->addFieldToFilter('customer_id', $customer->getId());

         if (Mage::getSingleton('customer/session')->isLoggedIn() && (!$orders->getSize()))
          { 
         // has never placed an order 

               $subtotal = Mage::helper('checkout/cart')->getQuote()->getSubtotal();

                if($subtotal <= '4000') {

                    echo "Minimum order amount is Rs.4000";
                    exit;
                }
                else {

                    return true;

                    }

                exit;
}

}


            }

}

And Mypackage/Minorder/Model/Helper.php,

<?php
class Mypackage_Minorder_Helper_Data extends Mage_Core_Helper_Abstract
{
}

update:2

And app/etc/Mypackage_Minorder.xml,

<?xml version="1.0"?>
<config>
  <modules>
    <Mypackage_Minorder>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Mypackage_Minorder>
  </modules>
</config>

I have checked this, this is working fine.Here I set min order amount is 4000, you can change it as your wish.. If you have any doubt, let me know..! cheers ..!

11
  • But I just want for the first purchase, not always May 5, 2014 at 10:17
  • For that you should hardcoded your application..
    – Elavarasan
    May 5, 2014 at 10:28
  • I'm trying to build an extension May 5, 2014 at 10:34
  • I ll help you for that ..
    – Elavarasan
    May 5, 2014 at 10:56
  • so your requirement is, you want to set min order amount for a customer's first order only, right ..?
    – Elavarasan
    May 5, 2014 at 11:10

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.