Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save federivo/7356222 to your computer and use it in GitHub Desktop.
Save federivo/7356222 to your computer and use it in GitHub Desktop.
class Mage_Paypal_Block_Standard_Redirect extends Mage_Core_Block_Abstract
{
protected function _toHtml()
{
$standard = Mage::getModel('paypal/standard');
$form = new Varien_Data_Form();
$form->setAction($standard->getConfig()->getPaypalUrl())
->setId('paypal_standard_checkout')
->setName('paypal_standard_checkout')
->setMethod('POST')
->setUseContainer(true);
foreach ($standard->getStandardCheckoutFormFields() as $field=>$value) {
$form->addField($field, 'hidden', array('name'=>$field, 'value'=>$value));
}
$idSuffix = Mage::helper('core')->uniqHash();
$submitButton = new Varien_Data_Form_Element_Submit(array(
'value' => $this->__('Click here if you are not redirected within 10 seconds...'),
));
$id = "submit_to_paypal_button_{$idSuffix}";
$submitButton->setId($id);
$form->addElement($submitButton);
// $html = '<html><body>';
$html = '';
$html.= $this->__('You will be redirected to the PayPal website in a few seconds.');
$html.= $form->toHtml();
$html.= '<script type="text/javascript">document.getElementById("paypal_standard_checkout").submit();</script>'; // uncomment to style view
// $html.= '</body></html>';
return $html;
}
}
/**
* When a customer chooses Paypal on Checkout/Payment page
*
*/
public function redirectAction()
{
$session = Mage::getSingleton('checkout/session');
$session->setPaypalStandardQuoteId($session->getQuoteId());
// + core hack to load template layout @ 2012-08-17
// $this->getResponse()->setBody($this->getLayout()->createBlock('paypal/standard_redirect')->toHtml()); // not needed
// load layout from paypal.xml
$this->loadLayout();
// redner layout
$this->renderLayout();
// = core hack to load template layout @ 2012-08-17
$session->unsQuoteId();
$session->unsRedirectUrl();
}
<paypal_standard_redirect translate="label">
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<block type="paypal/standard_redirect" name="paypal.standard.redirect" />
</reference>
</paypal_standard_redirect>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment