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.
Signature
http://www.karmatradingco.com
http://www.kentbusinessforum.co.uk
http://www.greenshops.org.uk