I am trying to create a custom module for MAGENTO CHECKOUT in which I want to remove SHIPPING ADDRESS AND SHIPPING METHOD steps.
So my code looks like below:
app/etc/Mona_Test.xml
<?xml version="1.0"?>
<config>
<modules>
<Mona_Test>
<active>true</active>
<codePool>local</codePool>
</Mona_Test>
</modules>
</config>
app/code/local/Mona/Test/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Mona_Test>
<version>1.0</version>
</Mona_Test>
</modules>
<global>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Mona_Test before="Mage_Checkout">Mona_Test</Mona_Test>
</modules>
</args>
</checkout>
</routers>
</frontend>
<blocks>
<test>
<class>Mona_Test_Block</class>
</test>
<checkout>
<rewrite>
<onepage_abstract>Mona_Test_Block_Onepage_Abstract</onepage_abstract>
</rewrite>
</checkout>
</blocks>
<models>
<test>
<class>Mona_Test_Model</class>
</test>
<checkout>
<rewrite>
<type_onepage>Mona_Test_Model_Type_Onepage</type_onepage>
</rewrite>
</checkout>
</models>
</global>
</config>
app/code/local/Mona/Test/Blocks/Onepage/Abstract.php
<?php
class Mona_Test_Block_Onepage_Abstract extends Mage_Checkout_Block_Onepage_Abstract {
protected function _getStepCodes()
{
return array('login', 'billing', 'payment', 'review');
}
}
?>
app/code/local/Mona/Test/controllers/OnepageController.php
<?php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Mona_Test_OnepageController extends Mage_Checkout_OnepageController
{
protected $_sectionUpdateFunctions = array(
'payment-method' => '_getPaymentMethodsHtml',
'review' => '_getReviewHtml',
);
public function saveBillingAction()
{
if ($this->_expireAjax()) {
return;
}
$data = $this->getRequest()->getPost('billing', array());
$customerAddressId = $this->getRequest()->getPost('billing_address_id', false);
if (isset($data['email'])) {
$data['email'] = trim($data['email']);
}
$result = $this->getOnepage()->saveBilling($data, $customerAddressId);
if (!isset($result['error'])) {
/* check quote for virtual */
if ($this->getOnepage()->getQuote()->isVirtual()) {
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getPaymentMethodsHtml()
);
} else {
$result['goto_section'] = 'payment';
}
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
public function saveShippingAction()
{
if ($this->_expireAjax()) {
return;
}
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'])) {
$result['goto_section'] = 'payment';
$result['update_section'] = array(
'name' => 'payment-method',
'html' => $this->_getShippingMethodsHtml()
);
}
$this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
}
}
app/code/local/Mona/Test/Model/Type/Onepage.php
<?php
class Mona_Test_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage
{
public function saveShippingMethod($shippingMethod)
{
if (empty($shippingMethod)) {
$shippingMethod = 'freeshipping_freeshipping';
}
$rate = $this->getQuote()->getShippingAddress()->getShippingRateByCode($shippingMethod);
if (!$rate) {
return array('error' => -1, 'message' => Mage::helper('checkout')->__('Invalid shipping method.'));
}
$this->getQuote()->getShippingAddress()
->setShippingMethod($shippingMethod);
$this->getCheckout()
->setStepData('shipping_method', 'complete', true)
->setStepData('payment', 'allow', true);
return array();
}
}
?>
Its not working. what more should i do? Any solutions to it will be greatful.
Its not working.
? – Flakes