示例#1
0
文件: Poll.php 项目: rajarshc/Rooja
 public function addVote(Mage_Poll_Model_Poll_Vote $vote)
 {
     if (Mage::getModel('customer/session')->getCustomerId()) {
         $ruleCollection = Mage::getSingleton('rewards/special_validator')->getApplicableRulesOnPoll();
         $hasRecievedPoints = false;
         //Grab all the newsletter point transfers dealing with this customer
         $transferCollection = Mage::getModel('rewards/transfer')->getTransfersAssociatedWithPoll($this->getId());
         foreach ($transferCollection as $transfer) {
             if ($transfer->getCustomerId() == Mage::getModel('customer/session')->getCustomerId()) {
                 $revokedTransfers = Mage::getModel('rewards/transfer')->getTransfersAssociatedWithTransfer($transfer->getId());
                 //If there are no revoked transfers, then the customer has already recieved points for this newsletter
                 //And therefore should not get anymore
                 if ($revokedTransfers->getSize() == 0) {
                     $hasRecievedPoints = true;
                 }
             }
         }
         if (!$hasRecievedPoints) {
             Mage::dispatchEvent('rewards_poll_new_vote', array('poll' => &$this));
             foreach ($ruleCollection as $rule) {
                 if (!$rule->getId()) {
                     continue;
                 }
                 try {
                     //Create the transfer
                     $is_transfer_successful = Mage::helper('rewards/transfer')->transferPollPoints($rule->getPointsAmount(), $rule->getPointsCurrencyId(), $this->getId(), $rule->getId());
                 } catch (Exception $ex) {
                     Mage::getSingleton('core/session')->addError($ex->getMessage());
                 }
                 if ($is_transfer_successful) {
                     //Alert the customer on the distributed points
                     Mage::getSingleton('core/session')->addSuccess(Mage::helper('rewards')->__('You received %s for voting', (string) Mage::getModel('rewards/points')->set($rule)));
                 }
             }
         }
     }
     return parent::addVote($vote);
 }