load($orderId); if ($this->_processData === null) { $this->_processData = array(); } if ($order->getId() > 0) { if (!isset($this->_processData[$order->getStoreId()])) { $this->_processData[$order->getStoreId()] = array(); $processHelper = Mage::helper('ekomimeetsmage/mail_sending_process'); $type = $processHelper->getProcessType($order->getStoreId()); $status = $processHelper->getProcessStatus($order->getStoreId()); $this->_processData[$order->getStoreId()] = array( "type" => $type, "status" => $status ); } return $this->_processData[$order->getStoreId()]; } return array(); } /** * The link sender for ratings * */ public function checkmails() { $this->_log(""); $this->_log("==== eKomiMeetsMage: Cron Job Sending Rating Links starts"); $this->_log("= Version: ".MeetsEcommerce_Ekomimeetsmage_Model_Version::getVersionName()); $collection = Mage::getModel('ekomimeetsmage/rating_email') ->getCollection() ->addFieldToFilter('sent_status', array('eq'=>'pending')) ->setOrder('send_out_date', 'desc') ->load(); if ($collection->count() > 0) { foreach ($collection as $mail) { $processData = $this->_getProcessDataByOrder($mail->getOrderId()); if (!count($processData) > 0) { // if not set, then set standard $processData["type"] = Mage::getModel('ekomimeetsmage/rating_email_type')->getStandardValue(); $processData["status"] = "complete"; } $order = Mage::getModel('sales/order')->load($mail->getOrderId()); $settings = $this->_getApi()->getSettings($order->getStoreId()); $this->_log(" ------", Zend_Log::DEBUG); $this->_log( " Process Data: ". $processData["type"]. " > ". $processData["status"]. " > ". $order->getId(), Zend_Log::DEBUG ); try{ #the sendOut Date will be set after the Order is send to ekomi $this->getHelper()->setEkomiLink($mail, $order, $settings, $processData["type"]); if ($this->getHelper()->canSend($mail, $order, $processData) == true) { $mail->setSentStatus('waiting'); } $mail->save(); }catch(Exception $e){ $this->_log( " Could not update e-mail for order #". $mail->getOrderId()." for reason: ".$e->getMessage(), Zend_Log::ERR ); } } } } /** * The link sender for ratings * */ public function sendlinks() { $this->_log(""); $this->_log("==== eKomiMeetsMage: Cron Job Sending Rating Links starts"); $this->_log("= Version: ".MeetsEcommerce_Ekomimeetsmage_Model_Version::getVersionName()); $collection = Mage::getModel('ekomimeetsmage/rating_email') ->getCollection() ->addFieldToFilter('sent_status', array('eq'=>'waiting')) ->addFieldToFilter('ekomi_link', array('notnull' => true)) ->setOrder('send_out_date', 'desc') ->setPageSize(100) ->load(); if ($collection->count() > 0) { $sentEmails = 0; $this->_log(" Found ".$collection->count()." e-mail(s) to send out."); foreach ($collection as $mail) { $order = Mage::getModel('sales/order')->load($mail->getOrderId()); $helper = Mage::helper('ekomimeetsmage/mail'); try{ $this->_log( " Try to send mail of ".$order->getCustomerFirstname()." ".$order->getCustomerLastname(). "[".$order->getCustomerEmail()."]", Zend_Log::DEBUG ); if ($helper->sendMailToCustomer($mail, $order)) { $sentEmails++; $this->_log(" Send out ...", Zend_Log::DEBUG); } }catch(Exception $e){ $this->_log( " Could not send e-mail to customer for order #". $mail->getOrderId()." for reason: ".$e->getMessage(), Zend_Log::ERR ); } } $this->_log(" Sent ".$sentEmails." e-mails out."); } else { $this->_log(" No e-mails found to send out."); } $this->_log("==== eKomiMeetsMage: Cron Job Sending Rating Links finished"); } /** * The import * */ public function import() { $this->_log(""); $this->_log("==== eKomiMeetsMage: Cron Job Import starts"); $this->_log("= Version: ".MeetsEcommerce_Ekomimeetsmage_Model_Version::getVersionName()); $data = Mage::helper('ekomimeetsmage'); $api = Mage::helper('ekomimeetsmage/api_data'); if (strlen($data->getStoreType()) > 0) { $this->_log("= Options"); $this->_log(" Storetype: ".$data->getStoreType()); } else { $this->_("= No store configured"); return; } if ($data->getStoreType()=="singlestore") { $apidata = $api->fetch(); $id = $apidata['api_id']; $pass = $apidata['api_pass']; $status = $apidata['api_status']; if ($status==0) { if ($api->verifyAgain($id, $pass)==true) { $api->save($id, $pass); $status = 1; $this->_log(" API access data now valid. Changed to status valid."); } else { $this->_log(" API access data still not valid."); } } $this->getHelper()->importStore($data, $apidata); } elseif ($data->getStoreType()=="multistore") { foreach (Mage::app()->getStores() as $store) { $this->getHelper()->importStore($data, $api->fetch($store->getId()), $store); } } else { $this->_log(" No API data set. Therefore cron job stopped here!"); } $this->_log("==== eKomiMeetsMage: Cron Job Import finished"); } /** * Logger * * @param string $message * @param int $type */ private function _log($message, $type=Zend_Log::INFO) { Mage::helper('ekomimeetsmage')->log($message, $type); } /** * Returns the SOAP Object * * @return SoapClient */ private function _getApi() { if ($this->_api==null) { $this->_api = Mage::getModel('ekomimeetsmage/api'); } return $this->_api; } /** * Returns the SOAP Object * * @return SoapClient */ private function getHelper() { if ($this->_helper==null) { $this->_helper = Mage::helper('ekomimeetsmage/cron'); } return $this->_helper; } }