Skip to content

Instantly share code, notes, and snippets.

@ashsmith
Created August 16, 2012 19:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ashsmith/3372950 to your computer and use it in GitHub Desktop.
Save ashsmith/3372950 to your computer and use it in GitHub Desktop.
[Not Finished] Override Shipping Method and Payment Steps on Magento Checkout.
<?xml version="1.0" encoding="UTF-8"?>
<!--app/code/local/Meteorify/Checkout/etc/config.xml-->
<config>
<modules>
<Meteorify_Checkout>
<version>0.0.1</version>
</Meteorify_Checkout>
</modules>
<global>
<blocks>
<checkout>
<rewrite>
<onepage>Meteorify_Checkout_Block_Onepage</onepage>
</rewrite>
</checkout>
</blocks>
</global>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Meteorify_Checkout before="Mage_Checkout">Meteorify_Checkout</Meteorify_Checkout>
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>
<?xml version="1.0"?>
<!-- app/etc/modules/Meteorify_Checkout.xml -->
<config>
<modules>
<Meteorify_Checkout>
<active>true</active>
<codePool>local</codePool>
</Meteorify_Checkout>
</modules>
</config>
<?php
//app/code/local/Meteorify/Checkout/Blocks/Onepage.php
include("Mage/Checkout/Block/Onepage.php");
class Meteorify_Checkout_Block_Onepage extends Mage_Checkout_Block_Onepage
{
public function getSteps()
{
$steps = array();
if (!$this->isCustomerLoggedIn()) {
$steps['login'] = $this->getCheckout()->getStepData('login');
}
$stepCodes = array('billing', 'shipping', 'review');
foreach ($stepCodes as $step) {
$steps[$step] = $this->getCheckout()->getStepData($step);
}
return $steps;
}
}
<?php
//app/code/local/Meteorify/Checkout/controllers/OnepageController.php
include("Mage/Checkout/controllers/OnepageController.php");
class Meteorify_Checkout_OnepageController extends Mage_Checkout_OnepageController {
public function saveBillingAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);
if (!isset($result['error'])) {
if ($this->getOnepage()->getQuote()->isVirtual()) {
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->getLayout()->getBlock('root')->toHtml()
);
}
elseif (isset($data['use_for_shipping']) && $data['use_for_shipping'] == 1) {
$this->saveShippingMethodAction();
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
$result['allow_sections'] = array('shipping','review');
$result['duplicateBillingInfo'] = 'true';
}
else {
$result['goto_section'] = 'shipping';
}
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
public function saveShippingAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('shipping', array());
$customerAddressId = $this->getRequest()->getPost('shipping_address_id', false);
$result = $this->getOnepage()->saveShipping($data, $customerAddressId);
if (!isset($result['error'])) {
$this->saveShippingMethodAction();
$this->loadLayout('checkout_onepage_review');
$result['goto_section'] = 'review';
$result['update_section'] = array(
'name' => 'review',
'html' => $this->_getReviewHtml()
);
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
public function saveShippingMethodAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
$this->savePaymentAction();
$data = $this->getRequest()->getPost('shipping_method', 'flatrate_flatrate'); //Change to your Shipping Method
$result = $this->getOnepage()->saveShippingMethod($data);
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
public function savePaymentAction()
{
$this->_expireAjax();
if ($this->getRequest()->isPost()) {
$data = $this->getRequest()->getPost('payment', array('method'=>'worldpay_cc')); //Change to your Payment Processor
try {
$result = $this->getOnepage()->savePayment($data);
}
catch (Mage_Payment_Exception $e) {
if ($e->getFields()) {
$result['fields'] = $e->getFields();
}
$result['error'] = $e->getMessage();
}
catch (Exception $e) {
$result['error'] = $e->getMessage();
}
$redirectUrl = $this->getOnePage()->getQuote()->getPayment()->getCheckoutRedirectUrl();
if ($redirectUrl) {
$result['redirect'] = $redirectUrl;
}
$this->getResponse()->setBody(Zend_Json::encode($result));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment