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

Page 1 of 2
Customizing Checkout Process: Showing certain Payment Method IF specific Shipping Method is selected. 
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi All,

Anyone have a quick reference to which files will need to be modified in order to do the following:
- retrieve the selected Shipping Method?
- display specific Payment Method only if a specific Shipping method is selected

Also, how would I find the value of the “shipping” variable that gets passed into the “Step 4: Payment Method”?

I know of the following files off-hand that might be involved,
- app/code/core/Mage/Checkout/Model/Type/Multishipping.php
- app/code/core/Mage/Checkout/Model/Type/Onepage.php
- - app/code/core/Mage/Checkout/controllers/OnepageController.php

Thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

It looks like this is the file and function that might need modified?
File- app/code/core/Mage/Checkout/controllers/OnepageController.php
Function-

public function savePaymentAction()

public function savePaymentAction()
    
{
        $this
->_expireAjax();
        if (
$this->getRequest()->isPost()) {
            $data 
$this->getRequest()->getPost('payment', array());
            
/*
            * first to check payment information entered is correct or not
            */

            
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();
            
}

            
if (empty($result['error'])) {
                $this
->loadLayout('checkout_onepage_review');
                
$result['review_html'$this->getLayout()->getBlock('root')->toHtml();
            
}

            
if ($redirectUrl $this->getOnePage()->getQuote()->getPayment()->getCheckoutRedirectUrl()) {
                $result[
'redirect'$redirectUrl;
            
}

            $this
->getResponse()->setBody(Zend_Json::encode($result));
        
}
    }

Not sure how to integrate the condition though, and if this is the correct/only function that needs modified.

Any ideas?

Thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

I wonder, would there be a way to change it via the XML layout in “$this->loadLayout(’checkout_onepage_review’);” ?

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Any news on this?

Moshe, have any ideas? Or has this been done before?

Thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

As I’m looking into this more, I wonder if it would be possible to create this dependency with XML interaction.
Would any XML files need to be modified in addition to the PHP pages?

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

As I’m looking through Firebug via Firefox, I’m noticing the following things…

“From Step 3 - Shipping Information”: When I select “Pick-Up” Shipping Method, this gets posted ->

shipping_method=freeshipping_freeshipping

And in the “response” - all labels/fields for available

So, I need to simply find out where and how (with the Zend Framework) to create a simple condition to do the following:
- If “shipping_method” value is equal to “freeshipping_freshipping”
- And if so, do not grab “p_method_newmodule” (my new module) within the response getting sent back

We’re getting closer.

Thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Maybe this function can include the condition? (here’s the file: app/code/core/Mage/Checkout/controllers/OnepageController.php)

public function saveShippingMethodAction()
    
{
        $this
->_expireAjax();
        if (
$this->getRequest()->isPost()) {
            $data 
$this->getRequest()->getPost('shipping_method''');
            
$result $this->getOnepage()->saveShippingMethod($data);
            
/*
            $result will have erro data if shipping method is empty
            */
            
if(!$result{
                Mage
::dispatchEvent('checkout_controller_onepage_save_shipping_method', array('request'=>$this->getRequest()));
                
$this->getResponse()->setBody(Zend_Json::encode($result));

                
$result['payment_methods_html'$this->_getPaymentMethodsHtml();
            
}
            $this
->getResponse()->setBody(Zend_Json::encode($result));
        
}

    }

The necessary changes that I believe are needed include,
1. get the selected/saved Shipping Method
2. somehow (whether via solely PHP or PHP and XML) disable the “New Payment Module” I created from getting displayed.

Anyone?

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hey All,

Just wanting to know if we can get some community participation on this to make some headway?

I’m still unsure as to what changes need to be made, and where they need to be initiated.
I’d greatly appreciate some assistance.

Many thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi @Moshe,

Any help on this?

There’s been a lot of views, and thus it seems the community is interested.

Thanks for your time and effort,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi All,

We’re still working this and desiring to find a solution.

Hopefully this will benefit others in the community as well.

We’ll keep you posted.

Thanks,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
evL
Member
 
Total Posts:  32
Joined:  2008-04-23
 

There’s no need to modify the core if you want to show/hide methods

Just go into the template files that show the payment methods and do a condition that retrieves the order shipping method ($this->getOrder()->getShippingMethod() I think)

 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Thanks for the note @evL,

I’ve been trying to figure out where the change should be made. Because it’s not really a change in business logic, I should probably tackle this from within the presentation layer.

If I’ll be able to get the shipping method from within the template file, (which I think you’re correct), then I could just throw in the condition before the foreach loop of all payment methods.

I’ll test it out later on today when I get a chance. And I’ll keep you updated.

Thanks again,
Lee

 
Magento Community Magento Community
Magento Community
Magento Community
 
miso
Jr. Member
 
Total Posts:  15
Joined:  2008-04-17
 

My solution (shipping IF condition is in payment method):

class Mage_Ird_Model_Payment_Method_Cashondelivery extends Mage_Payment_Model_Method_Abstract
{
    
protected $_code  'cashondelivery';

    public function 
isAvailable($quote=null)
    
{
        $shipping 
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod(); 
        
        if (
eregi("upssk"$shipping)) {
            
return true;
        
}
        
return false;
    
}

}
 
Magento Community Magento Community
Magento Community
Magento Community
 
leetaylordoes
Sr. Member
 
Total Posts:  227
Joined:  2008-02-05
San Diego, CA
 

Hi All,

Big thanks to @Miso!

I wasn’t sure where to accomplish this at, and I’m very appreciative of your post in reply. It’s a big help to us.

Here’s what my file looks like that was edited (app/code/local/Mage/NewModule/ModelPaymentMethod.php):

<?php
 
/**
* Our latest Payment Module Adapter
*/
class Mage_NewModule_Model_PaymentMethod extends Mage_Payment_Model_Method_Abstract
{
    
protected $_code  'newmodule';
    
//protected $_formBlockType = 'payment/form_checkmo';
    //protected $_infoBlockType = 'payment/info_cod';

    /**
     * Assign data to info model instance
     *
     * @param   mixed $data
     * @return  Mage_Payment_Model_Method_Checkmo
     */
    
public function isAvailable($quote=null)
        
{
            $shipping 
Mage::getSingleton('checkout/session')->getQuote()->getShippingAddress()->getShippingMethod(); 

            if (
eregi("freeshipping_freeshipping"$shipping)) {
                
return true;
            
}
            
return false;
        
}

}

P.s.
Attached is a full working copy of the following:
- New Payment Method for “Cash On Delivery” with dependency to show only if the Free shipping method has been selected.

File Attachments
COD_PaymentMethod.zip  (File Size: 14KB - Downloads: 361)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Janek
Jr. Member
 
Total Posts:  16
Joined:  2008-02-17
 

OK, great idea with COD smile
but next question is - how to hide other payment methods? as COD is in logic conflict with other payments

Because COD has additional fees, I put it on separate shipping methods, created by my own
my
Mage::getSingleton(’checkout/session’)->getQuote()->getShippingAddress()->getShippingMethod()
returns “postal_service_cod”

I would like to disable (hide on onepage checkout) other payment methods, but COD, if customer choose “postal_service_cod”.
Is this possible without modify core? maybe some functions overloading…
any little hint highly appreciated smile

DJ

 
Magento Community Magento Community
Magento Community
Magento Community
 
matponta
Member
 
Total Posts:  39
Joined:  2008-05-20
Italy
 

Very interested in this, have you found a solution?

Mattia

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top
Page 1 of 2