2

I need to listen to the events in the checkout onepage with an observer. The goal is to count the number of times that a command is passed by a user and at the end of the tenth command, I offer him/her a gift.

So this is my config.xml with event

<frontend>
    <events>
        <checkout_onepage_controller_success_action>
            <observers>
                <observe_order_pour_mails>
                    <type>singleton</type>
                    <class>mymodule_custom/observer</class>
                    <method>countOrder</method>
                </observe_order_pour_mails>
            </observers>
        </checkout_onepage_controller_success_action>
    </events>
</frontend>

and this is my observer

<?php 

 class Mymodule_Custom_Model_Observer extends Varien_Event_Observer {


 public function __construct() {}

/**
 * @param $observer
 */
public function countOrder($observer) {

    //$from_date = date("Y-m-d h:m:s", strtotime(2016-9-11));
    //$to_date = date("Y-m-d h:m:s", strtotime(2017-9-13));

    $customer_groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

    $ii = 0 ; // init counter 
    $order = $observer->getEvent()->getOrderIds(); // get event of orderIds

    Mage::log(count($order), null, 'order.log'); // count order , always equals 1 in log 

    if(count($order) > 0 ){ 

        $ii++; // counter

        Mage::log( $ii, null, 'counter.log');

        if ($ii = 10){ // if counter of order = 2 , one customer win

             Mage::log('win', null, 'win.log');
             $ii = 0 ; // réinit counter when order = 2 
        }   

    }
 }

I need that at the end of the command, the user wins and receives an email to warn him/her that he/she has won. I would like that once this is done, the count will reset to zero and that another user can also win for a given period.

Thank you for helping me because I am a little lost

  • Which type of command? – ARVIND KARKAR Sep 13 '17 at 9:08
  • When status of command is processing – devmagento Sep 13 '17 at 10:19
  • where you store command status? and where to use that command? – ARVIND KARKAR Sep 13 '17 at 11:40
  • explain more on command – ARVIND KARKAR Sep 13 '17 at 11:41
  • In fact, when a customer validates his order and payment is ok, the customer is redirecting to the sucess page, I want to count the number of orders that are ok and at the 10th command give a gift to my customer. For this I use the observe in checkout_onepage_controller_success_action. how do I count the number of events up to 10 – devmagento Sep 13 '17 at 12:20
0

Try this:

public function countOrder($observer) {

$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
$_orders = Mage::getModel('sales/order')->getCollection()->addFieldToFilter('customer_id',$order->getCustomerId());                        
$_orderCnt = $_orders->count();

//stuff here 

 }

This may help you.

| improve this answer | |

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.