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