log("new state".$state); $processHelper = Mage::helper('ekomimeetsmage/mail_sending_process'); $ekomitype = $processHelper->getProcessType($this->getStoreId()); $ekomistatus = $processHelper->getProcessStatus($this->getStoreId()); $collection = Mage::getModel('ekomimeetsmage/rating_email') ->getCollection() ->addFieldToFilter('sent_status', array('eq'=>'pending')) ->addFieldToFilter('order_id', array('eq'=>$this->getId())) ->load(); $mail = current($collection->getIterator()); // If order is canceled, the mail process get stopped and marked as canceled if ($state == self::STATE_CANCELED && $mail) { $mail->setSentStatus('canceled')->save(); $this->log(" Order #".$this->getIncrementId()." is canceled. Skip to next mail ..."); } elseif ($state == $ekomistatus && $mail && !$mail->getSendOutDate()) { switch($ekomitype) { case MeetsEcommerce_Ekomimeetsmage_Model_Rating_Email_Type::TYPE_BY_STATUS: // BY STATUS $mail->setSendOutDate(time()); break; case MeetsEcommerce_Ekomimeetsmage_Model_Rating_Email_Type::TYPE_BY_DATE_AND_STATUS: // BY DATE AND STATUS $settings = $this->_getApi()->getSettings($this->getStoreId()); $date = time() + (Mage::helper('ekomimeetsmage')->isDeveloper() ? 0 : 60*60*24 * max(1, (int)$settings['mail_delay']) ); $mail->setSendOutDate($date); break; } $mail->save(); } return parent::_setState($state, $status, $comment, $isCustomerNotified, $shouldProtectState); } /** * Returns the SOAP Object * * @return SoapClient */ private function _getApi() { if ($this->_api==null) { $this->_api = Mage::getModel('ekomimeetsmage/api'); } return $this->_api; } /** * eKomi Logger * * @param mixed $message */ private function log($message, $type=Zend_Log::INFO) { Mage::helper('ekomimeetsmage')->log($message, $type); } }