Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

poll disapears after voting
 
ryckezas
Jr. Member
 
Total Posts:  14
Joined:  2008-04-14
 

Hello,
I’m new with Magento, and been trying to find the solution, but with no success.
Can anybody tell my how always show poll with results after voting. Cuz now it disappears and that’s bad for me.
Any help appreciated.

 
Magento Community Magento Community
Magento Community
Magento Community
 
CougarD
Jr. Member
 
Total Posts:  23
Joined:  2008-02-25
 

I would also like to know how to keep the poll on display.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ryckezas
Jr. Member
 
Total Posts:  14
Joined:  2008-04-14
 

I found the solution myself
In Poll/block/ActivePoll.php change constuctor method to:
public function __construct()
{
parent::__construct();

$pollModel = Mage::getModel(’poll/poll’);
$votedIds = $pollModel->getVotedPollsIds();
$pollId = 0;
if (count($votedIds) > 0) {
foreach ($votedIds as $key=>$pol) {
$pollId = $pol;
}
} else {
$pollId = ( Mage::getSingleton(’core/session’)->getJustVotedPoll() )
? Mage::getSingleton(’core/session’)->getJustVotedPoll()
: $pollModel->setExcludeFilter($votedIds)->setStoreFilter(Mage::app()->getStore()->getId())->getRandomId();
}

$poll = $pollModel->load($pollId);

if( !$pollId) {
return false;
}

$pollAnswers = Mage::getModel(’poll/poll_answer’)
->getResourceCollection()
->addPollFilter($pollId)
->load()
->countPercent($poll);

$this->assign(’poll’, $poll)
->assign(’poll_answers’, $pollAnswers)
->assign(’action’, Mage::getUrl(’poll/vote/add’, array(’poll_id’ => $pollId)));

$this->_voted = Mage::getModel(’poll/poll’)->isVoted($pollId);
Mage::getSingleton(’core/session’)->setJustVotedPoll(false);
}

and in model/Poll.php
change getVotedPollsIds() method to:
public function getVotedPollsIds()
{
$idsArray = array();
foreach( $_COOKIE as $cookieName => $cookieValue ) {
$pattern = “/^” . $this->_pollCookieDefaultName . “([0-9]*?)$/”;
if( preg_match($pattern, $cookieName, $m) ) {
if( $m[1] != Mage::getSingleton(’core/session’)->getJustVotedPoll() ) {
if ($m[1] == $this->getRandomId()) //mano pataisymai
$idsArray[$m[1]] = $m[1];
}
}
}
return $idsArray;
}

that’s it smile I’m using magento 1.0 version
Good luck

 
Magento Community Magento Community
Magento Community
Magento Community
 
pauljg1
Sr. Member
 
Avatar
Total Posts:  179
Joined:  2008-02-22
 

Ive tryed that but get a fatal error.  Is it line 38 to 51 in the the activepoll.php that needs replacing?

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
ryckezas
Jr. Member
 
Total Posts:  14
Joined:  2008-04-14
 

Yes, hm interesting works fine for me, I thing I didn’t change anything else

 
Magento Community Magento Community
Magento Community
Magento Community
 
CougarD
Jr. Member
 
Total Posts:  23
Joined:  2008-02-25
 

Can you paste the entire code from your ActivePoll.php for us please?

 
Magento Community Magento Community
Magento Community
Magento Community
 
CougarD
Jr. Member
 
Total Posts:  23
Joined:  2008-02-25
 

got it…

The code posted above changes when copied and pasted into a terminal (i’m using nano).

all of the quotes change to dots. As an example..

the posted code shows…

$pollModel Mage::getModel(’poll/poll’);

but when pasted shows…

$pollModel Mage::getModel(.poll/poll.);

So thanks to ryckezas for the solution and here is a step by step to keeping the poll shown once a vote has been cast…

First make a back up of your files

cp app/code/core/Mage/Poll/Model/Poll.php app/code/core/Mage/Poll/Model/Poll.php.original
cp app
/code/core/Mage/Poll/Block/ActivePoll.php app/code/core/Mage/Poll/Block/ActivePoll.php.original

Now edit ActivePoll.php and replace the public function __construct() function. Change the code from…

public function __construct()
    
{
        parent
::__construct();

        
$pollModel Mage::getModel('poll/poll');
        
$votedIds $pollModel->getVotedPollsIds();
        
$pollId = ( Mage::getSingleton('core/session')->getJustVotedPoll() )
            ? 
Mage::getSingleton('core/session')->getJustVotedPoll()
            : 
$pollModel->setExcludeFilter($votedIds)->setStoreFilter(Mage::app()->getStore()->getId())->getRandomId();
        
$poll $pollModel->load($pollId);

        if( !
$pollId || in_array($pollId$votedIds) ) {
            
return false;
        
}

        $pollAnswers 
Mage::getModel('poll/poll_answer')
            ->
getResourceCollection()
            ->
addPollFilter($pollId)
            ->
load()
            ->
countPercent($poll);

        
$this->assign('poll'$poll)
             ->
assign('poll_answers'$pollAnswers)
             ->
assign('action'Mage::getUrl('poll/vote/add', array('poll_id' => $pollId)));

        
$this->_voted Mage::getModel('poll/poll')->isVoted($pollId);
        
Mage::getSingleton('core/session')->setJustVotedPoll(false);
    
}

to..

public function __construct()
    
{
         parent
::__construct();

         
$pollModel Mage::getModel('poll/poll');
         
$votedIds $pollModel->getVotedPollsIds();
         
$pollId 0;
         if (
count($votedIds) > 0{
           
foreach ($votedIds as $key=>$pol{
             $pollId 
$pol;
           
}
         } 
else {
           $pollId 
= ( Mage::getSingleton('core/session')->getJustVotedPoll() )
           ? 
Mage::getSingleton('core/session')->getJustVotedPoll() : $pollModel->setExcludeFilter($votedIds)->setStoreFilter(Mage::app()->getStore()->getId())->getRandomId();
        
}

        $poll 
$pollModel->load($pollId);

        if( !
$pollId{
          
return false;
        
}

        $pollAnswers 
Mage::getModel('poll/poll_answer')
        ->
getResourceCollection()
        ->
addPollFilter($pollId)
        ->
load()
        ->
countPercent($poll);

        
$this->assign('poll'$poll)
        ->
assign('poll_answers'$pollAnswers)
        ->
assign('action'Mage::getUrl('poll/vote/add', array('poll_id' => $pollId)));

       
$this->_voted Mage::getModel('poll/poll')->isVoted($pollId);
       
Mage::getSingleton('core/session')->setJustVotedPoll(false);
}

Now edit Poll.php and replace the public function getVotedPollsIds() function. Change the code from

public function getVotedPollsIds()
    
{
        $idsArray 
= array();
        foreach( 
$_COOKIE as $cookieName => $cookieValue {
            $pattern 
"/^" $this->_pollCookieDefaultName "([0-9]*?)$/";
            if( 
preg_match($pattern$cookieName$m) ) {
                
if( $m[1] != Mage::getSingleton('core/session')->getJustVotedPoll() ) {
                    $idsArray[$m[1]] 
$m[1];
                
}
            }
        }
        
return $idsArray;
    
}

to..

public function getVotedPollsIds()
    
{
       $idsArray 
= array();
       foreach( 
$_COOKIE as $cookieName => $cookieValue {
         $pattern 
"/^" $this->_pollCookieDefaultName "([0-9]*?)$/";
         if( 
preg_match($pattern$cookieName$m) ) {
           
if( $m[1] != Mage::getSingleton('core/session')->getJustVotedPoll() ) {
             
if ($m[1] == $this->getRandomId()) //mano pataisymai
             
$idsArray[$m[1]] $m[1];
           
}
         }
       }
       
return $idsArray;
     
}

That’s it.

Check your site and marvel at how great you are (with a lot of help from ryckezas).

Matt.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ryckezas
Jr. Member
 
Total Posts:  14
Joined:  2008-04-14
 

Next time I’ll know how to paste code smile

 
Magento Community Magento Community
Magento Community
Magento Community
 
pauljg1
Sr. Member
 
Avatar
Total Posts:  179
Joined:  2008-02-22
 

Cheers guys that worked for me....

 
Magento Community Magento Community
Magento Community
Magento Community
 
Greven
Member
 
Total Posts:  36
Joined:  2007-08-31
Florence, AL
 

I’m getting this problem too and I’m using version 1.0.19870.  What is up?

 
Magento Community Magento Community
Magento Community
Magento Community
 
marknet
Member
 
Total Posts:  46
Joined:  2008-06-19
 

I’m also getting this.  why would they make it dissapear??

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top