Example #1
0
 /**
  * Load data
  *
  * @return  Varien_Data_Collection_Db
  */
 public function load($printQuery = false, $logQuery = false)
 {
     if ($this->isLoaded()) {
         return $this;
     }
     $this->_beforeLoad();
     $this->_renderFilters()->_renderOrders()->_renderLimit();
     $this->printLogQuery($printQuery, $logQuery);
     $data = $this->getData();
     $this->resetData();
     $stores = Mage::getResourceModel('core/store_collection')->setWithoutDefaultFilter()->load()->toOptionHash();
     $this->_items = array();
     foreach ($data as $v) {
         $storeObject = new Varien_Object($v);
         $storeId = $v['store_id'];
         $storeName = isset($stores[$storeId]) ? $stores[$storeId] : null;
         $storeObject->setStoreName($storeName)->setWebsiteId(Mage::app()->getStore($storeId)->getWebsiteId())->setAvgNormalized($v['avgsale'] * $v['num_orders']);
         $this->_items[$storeId] = $storeObject;
         foreach ($this->_totals as $key => $value) {
             $this->_totals[$key] += $storeObject->getData($key);
         }
     }
     if ($this->_totals['num_orders']) {
         $this->_totals['avgsale'] = $this->_totals['base_lifetime'] / $this->_totals['num_orders'];
     }
     $this->_setIsLoaded();
     $this->_afterLoad();
     return $this;
 }
 public function inviteajaxAction()
 {
     $url = trim($_POST["url_link"]);
     $post = trim($_POST["email"]);
     $message = trim($_POST["message"]);
     if ($post == "" || $message == "") {
         header('content-type: text/javascript');
         $mw_email = 1;
         $mw_message = 1;
         if ($post == "") {
             $mw_email = 0;
         }
         if ($message == "") {
             $mw_message = 0;
         }
         $jsondata = array("message" => $mw_message, "email" => $mw_email, "error" => 0, "success" => 0);
         echo json_encode($jsondata);
         die;
     }
     $post = trim($post, " ,");
     $emails = explode(',', $post);
     $validator = new Zend_Validate_EmailAddress();
     $error = array();
     foreach ($emails as $email) {
         $name = $email;
         $_name = $this->getStringBetween($email, '"', '"');
         $_email = $this->getStringBetween($email, '<', '>');
         if ($_email !== false && $_name !== false) {
             $email = $_email;
             $name = $_name;
         } else {
             if ($_email !== false && $_name === false) {
                 if (strpos($email, '"') === false) {
                     $email = $_email;
                     $name = $email;
                 }
             }
         }
         $email = trim($email);
         if ($validator->isValid($email)) {
             // Send email to friend
             $store_id = Mage::app()->getStore()->getId();
             $store_name = Mage::getStoreConfig('general/store_information/name', $store_id);
             $template = self::EMAIL_TO_RECIPIENT_TEMPLATE_XML_PATH;
             $postObject = new Varien_Object();
             $customer = $this->_getSession()->getCustomer();
             $postObject->setSender($customer);
             $postObject->setMessage($message);
             $postObject->setData('invitation_link', $url);
             $postObject->setStoreName($store_name);
             $this->_sendEmailTransaction($email, $name, $template, $postObject->getData());
         } else {
             $error[] = $email;
         }
     }
     if (sizeof($error)) {
         $err = implode("<br>", $error);
         $mw_error = $this->__("These emails are invalid, the invitation message will not be sent to:<br>%s", $err);
         header('content-type: text/javascript');
         $jsondata = array("message" => 1, "email" => 1, "error" => $mw_error, "success" => 0);
         echo json_encode($jsondata);
         die;
     }
     $msg = 1;
     if (sizeof($emails) > 1) {
         $msg = 2;
     }
     //$msg = "Your Emails were sent successfully";
     if (sizeof($emails) > sizeof($error)) {
         header('content-type: text/javascript');
         $jsondata = array("message" => 1, "email" => 1, "error" => 0, "success" => $msg);
         echo json_encode($jsondata);
         die;
     }
 }
 public function sendAction()
 {
     $store_id = Mage::app()->getStore()->getId();
     if (!Mage::helper('rewardpoints')->moduleEnabled()) {
         $this->norouteAction();
         return;
     }
     if (!Mage::helper('rewardpoints')->allowSendRewardPointsToFriend($store_id)) {
         $this->norouteAction();
         return;
     }
     $this->_initLayoutMessages('customer/session');
     $this->_initLayoutMessages('checkout/session');
     if ($this->getRequest()->getPost()) {
         /*if($this->_getHelper()->enabledCapcha($store_id)){
               $require = dirname(dirname(__FILE__))."/Helper/Capcha/Securimage.php";
               require($require);
                 $img = new Securimage();
                 $valid = $img->check($this->getRequest()->getPost("code"));
           }else{
               $valid = true;
           }*/
         $valid = true;
         if ($valid) {
             $_customer = Mage::getModel('rewardpoints/customer')->load($this->_getSession()->getCustomer()->getId());
             //current customer
             $point = $this->getRequest()->getPost("amount");
             if ($point < 0) {
                 $point = -$point;
             }
             if ($_customer->getMwRewardPoint() >= $point) {
                 //send reward point
                 $website_id = Mage::getModel('core/store')->load($store_id)->getWebsiteId();
                 $customer = Mage::getModel('customer/customer')->setWebsiteId($website_id)->loadByEmail($this->getRequest()->getPost("email"));
                 if ($customer->getId() != $_customer->getId()) {
                     if ($customer->getId()) {
                         //Add reward points to friend
                         Mage::helper('rewardpoints/data')->checkAndInsertCustomerId($customer->getId(), 0);
                         $mwCustomer = Mage::getModel('rewardpoints/customer')->load($customer->getId());
                         $mwCustomer->addRewardPoint($point);
                         $results = Mage::helper('rewardpoints/data')->getTransactionExpiredPoints($point, $store_id);
                         $expired_day = $results[0];
                         $expired_time = $results[1];
                         $point_remaining = $results[2];
                         $historyData = array('type_of_transaction' => MW_RewardPoints_Model_Type::RECIVE_FROM_FRIEND, 'amount' => $point, 'balance' => $mwCustomer->getMwRewardPoint(), 'transaction_detail' => $_customer->getId(), 'transaction_time' => Mage::getSingleton('core/date')->gmtDate(), 'expired_day' => $expired_day, 'expired_time' => $expired_time, 'point_remaining' => $point_remaining, 'status' => MW_RewardPoints_Model_Status::COMPLETE);
                         $mwCustomer->saveTransactionHistory($historyData);
                         // send mail when points changed
                         Mage::helper('rewardpoints')->sendEmailCustomerPointChanged($customer->getId(), $historyData, $store_id);
                         //Subtract reward points of current customer
                         $_customer->addRewardPoint(-$point);
                         $historyData = array('type_of_transaction' => MW_RewardPoints_Model_Type::SEND_TO_FRIEND, 'amount' => $point, 'balance' => $_customer->getMwRewardPoint(), 'transaction_detail' => $customer->getId(), 'transaction_time' => Mage::getSingleton('core/date')->gmtDate(), 'status' => MW_RewardPoints_Model_Status::COMPLETE);
                         $_customer->saveTransactionHistory($historyData);
                         // process expired points when spent point
                         Mage::helper('rewardpoints/data')->processExpiredPointsWhenSpentPoints($_customer->getId(), $point);
                         // send mail when points changed
                         Mage::helper('rewardpoints')->sendEmailCustomerPointChanged($_customer->getId(), $historyData, $store_id);
                         $this->_getSession()->addSuccess($this->__("Your reward points were sent successfuly"));
                         $this->_redirect('rewardpoints/rewardpoints/index');
                     } else {
                         //Subtract reward points of current customer
                         $_customer->addRewardPoint(-$point);
                         $historyData = array('type_of_transaction' => MW_RewardPoints_Model_Type::SEND_TO_FRIEND, 'amount' => $point, 'balance' => $_customer->getMwRewardPoint(), 'transaction_detail' => $this->getRequest()->getPost("email"), 'transaction_time' => Mage::getSingleton('core/date')->gmtDate(), 'status' => MW_RewardPoints_Model_Status::PENDING);
                         $_customer->saveTransactionHistory($historyData);
                         // process expired points when spent point
                         Mage::helper('rewardpoints/data')->processExpiredPointsWhenSpentPoints($_customer->getId(), $point);
                         // send mail when points changed
                         Mage::helper('rewardpoints')->sendEmailCustomerPointChanged($_customer->getId(), $historyData, $store_id);
                         //customer dose not exist
                         $this->_getSession()->addSuccess($this->__("Your reward points were sent successfully"));
                     }
                     if (Mage::helper('rewardpoints')->allowSendEmailNotifications($store_id)) {
                         //Send mail to frend
                         $store_name = Mage::getStoreConfig('general/store_information/name', $store_id);
                         $sender = Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $store_id);
                         $mailto = $this->getRequest()->getPost('email');
                         $name = $this->getRequest()->getPost('name');
                         $template = self::EMAIL_TO_RECIPIENT_TEMPLATE_XML_PATH;
                         $postObject = new Varien_Object();
                         $postObject->setData($this->getRequest()->getPost());
                         $postObject->setSender($_customer->getCustomerModel());
                         $postObject->setData('login_link', Mage::app()->getStore($store_id)->getUrl('customer/account/login'));
                         $postObject->setData('customer_link', Mage::app()->getStore($store_id)->getUrl('rewardpoints/rewardpoints/index'));
                         $postObject->setData('register_link', Mage::app()->getStore($store_id)->getUrl('customer/account/create'));
                         $postObject->setStoreName($store_name);
                         Mage::helper('rewardpoints')->_sendEmailTransaction($sender, $mailto, $name, $template, $postObject->getData(), $store_id);
                     }
                     /*
                                                 if(Mage::helper('rewardpoints')->allowSendEmailToSender($store_id))
                                                 {
                                                     //Send mail to sender
                                                     $sender = Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $store_id);
                                                     $mailto = $_customer->getCustomerModel()->getEmail();
                                                     $name = $_customer->getCustomerModel()->getName();
                                                     $template = self::EMAIL_TO_SEMDER_TEMPLATE_XML_PATH;
                                                     $postObject = new Varien_Object();
                                                     $postObject->setData('amount',$this->getRequest()->getPost('amount'));
                                                     $postObject->setData('name',$name);
                                                     Mage::helper('rewardpoints')->_sendEmailTransaction($sender,$mailto, $name, $template, $postObject->getData(),$store_id);
                                                 }*/
                 } else {
                     $this->_getSession()->addError($this->__("You can not send reward points to yourself"));
                 }
             } else {
                 //Current total reward points do not enought to send
                 $this->_getSession()->addError($this->__("You do not have enough points to send to your friend"));
             }
         } else {
             //return error
             $this->_getSession()->addError($this->__("Your security code is incorrect"));
         }
     } else {
         $this->_getSession()->addError($this->__("You do not have permission!"));
     }
     $this->_redirect('rewardpoints/rewardpoints/index');
 }
 public function sendAction()
 {
     $store_id = Mage::app()->getStore()->getId();
     $customer_id = Mage::getSingleton("customer/session")->getCustomer()->getId();
     if (!Mage::helper('storecreditpro')->moduleEnabled()) {
         $this->norouteAction();
         return;
     }
     if (!Mage::helper('storecreditpro')->allowSendEmailNotifications($store_id)) {
         $this->norouteAction();
         return;
     }
     $this->_initLayoutMessages('customer/session');
     $this->_initLayoutMessages('checkout/session');
     if ($this->getRequest()->getPost()) {
         $_customer = Mage::getModel('storecreditpro/customer')->load($customer_id);
         $credit = (int) $this->getRequest()->getPost("amount");
         if ($_customer->getCreditBalance() >= $credit) {
             $website_id = Mage::getModel('core/store')->load($store_id)->getWebsiteId();
             $customer_friend = Mage::getModel('customer/customer')->setWebsiteId($website_id)->loadByEmail($this->getRequest()->getPost("email"));
             if ($customer_friend->getId() != $_customer->getId()) {
                 if ($customer_friend->getId()) {
                     Mage::helper('storecreditpro')->checkAndInsertCustomerId($customer_friend->getId());
                     $mwCustomer = Mage::getModel('storecreditpro/customer')->load($customer_friend->getId());
                     $mwCustomer->addCredit($credit);
                     $email = Mage::getModel('customer/customer')->load($_customer->getId())->getEmail();
                     $transaction_detail = Mage::helper('storecreditpro')->__('Receive credit from friend %s', $email);
                     $historyData = array('customer_id' => $customer_friend->getId(), 'transaction_type' => MW_Storecreditpro_Model_Type::RECEIVE_FROM_FRIEND, 'amount' => $credit, 'balance' => $mwCustomer->getCreditBalance(), 'transaction_params' => $_customer->getId(), 'transaction_detail' => $transaction_detail, 'order_id' => 0, 'transaction_time' => now(), 'expired_time' => null, 'remaining_credit' => 0, 'status' => MW_Storecreditpro_Model_Statushistory::COMPLETE);
                     Mage::getModel('storecreditpro/history')->setData($historyData)->save();
                     Mage::helper('storecreditpro')->sendEmailCustomerCreditChanged($customer_friend->getId(), $historyData, $store_id);
                     $_customer->addCredit(-$credit);
                     $email_friend = Mage::getModel('customer/customer')->load($customer_friend->getId())->getEmail();
                     $transaction_detail_friend = Mage::helper('storecreditpro')->__('Send credit to friend %s', $email_friend);
                     $historyData = array('customer_id' => $_customer->getId(), 'transaction_type' => MW_Storecreditpro_Model_Type::SEND_TO_FRIEND, 'amount' => $credit, 'balance' => $_customer->getCreditBalance(), 'transaction_params' => $customer_friend->getId(), 'transaction_detail' => $transaction_detail_friend, 'order_id' => 0, 'transaction_time' => now(), 'expired_time' => null, 'remaining_credit' => 0, 'status' => MW_Storecreditpro_Model_Statushistory::COMPLETE);
                     Mage::getModel('storecreditpro/history')->setData($historyData)->save();
                     Mage::helper('storecreditpro')->sendEmailCustomerCreditChanged($_customer->getId(), $historyData, $store_id);
                     Mage::getSingleton('customer/session')->addSuccess($this->__("Your credits were sent successfuly"));
                     $this->_redirect('storecreditpro/index/index');
                 } else {
                     $_customer->addCredit(-$credit);
                     $email_friend = $this->getRequest()->getPost("email");
                     $transaction_detail_friend = Mage::helper('storecreditpro')->__('Send credit to friend %s', $email_friend);
                     $historyData = array('customer_id' => $_customer->getId(), 'transaction_type' => MW_Storecreditpro_Model_Type::SEND_TO_FRIEND, 'amount' => $credit, 'balance' => $_customer->getCreditBalance(), 'transaction_params' => $this->getRequest()->getPost("email"), 'transaction_detail' => $transaction_detail_friend, 'order_id' => 0, 'transaction_time' => now(), 'expired_time' => null, 'remaining_credit' => 0, 'status' => MW_Storecreditpro_Model_Statushistory::PENDING);
                     Mage::getModel('storecreditpro/history')->setData($historyData)->save();
                     Mage::helper('storecreditpro')->sendEmailCustomerCreditChanged($_customer->getId(), $historyData, $store_id);
                     Mage::getSingleton('customer/session')->addSuccess($this->__("Your credits were sent successfully"));
                 }
                 if (Mage::helper('storecreditpro')->allowSendEmailNotifications($store_id)) {
                     //Send mail to frend
                     $customer_name = Mage::getModel('customer/customer')->load($customer_id)->getName();
                     $store_name = Mage::getStoreConfig('general/store_information/name', $store_id);
                     $sender = Mage::getStoreConfig(self::XML_PATH_EMAIL_IDENTITY, $store_id);
                     $mailto = $this->getRequest()->getPost('email');
                     $name = $this->getRequest()->getPost('name');
                     $template = self::EMAIL_TO_RECIPIENT_TEMPLATE_XML_PATH;
                     $postObject = new Varien_Object();
                     $postObject->setData($this->getRequest()->getPost());
                     $postObject->setData('customer_name', $customer_name);
                     $postObject->setData('login_link', Mage::app()->getStore($store_id)->getUrl('customer/account/login'));
                     $postObject->setData('customer_link', Mage::app()->getStore($store_id)->getUrl('storecreditpro/index/index'));
                     $postObject->setData('register_link', Mage::app()->getStore($store_id)->getUrl('customer/account/create'));
                     $postObject->setStoreName($store_name);
                     Mage::helper('storecreditpro')->_sendEmailTransaction($sender, $mailto, $name, $template, $postObject->getData(), $store_id);
                 }
             } else {
                 Mage::getSingleton('customer/session')->addError($this->__("You can not send credits to yourself"));
             }
         } else {
             Mage::getSingleton('customer/session')->addError($this->__("You do not have enough credit to send to your friend"));
         }
     } else {
         Mage::getSingleton('customer/session')->addError($this->__("You do not have permission!"));
     }
     $this->_redirect('storecreditpro/index/index');
 }