Question

I'm trying to override a model class to prevent customers changing the shipping address and method at the (final) order review stage of checkout, using this suggestion. This is the point at which the customer has been returned from PayPal in order to check over the order before finally clicking the 'Place Order' button. We pre-agree shipping costs with our customers via a quotation so giving them the option to change shipping method doesn't make any sense.

This is my first attempt at doing this in Magento. It feels like I'm nearly there but it's not working:

Review Order Shipping Method is still editable

If anyone with experience of overriding model classes in Magento could tell me where I'm going wrong that would be fantastic.

(1)
(a) Create /app/code/local/Lms/Paypal/Model/Express and copy in /app/code/core/Mage/Paypal/Model/Express/Checkout.php

(b) Rename class in Checkout.php from: Mage_Paypal_Model_Express_Checkout to: Lms_Paypal_Model_Express_Checkout extends Mage_Paypal_Model_Express_Checkout

(c) Clear out the class body and replace with just this function:

/**
 * Check whether order review has enough data to initialize
 *
 * @param $token
 * @throws Mage_Core_Exception
 */
public function prepareOrderReview($token = null)
{
    parent::prepareOrderReview($token);
    $this->_quote->setMayEditShippingAddress(false);
    $this->_quote->setMayEditShippingMethod(false);
    $this->_ignoreAddressValidation();
    $this->_quote->collectTotals()->save();
}

(2)
(a) Now create dir /app/code/local/Lms/Paypal/etc/
(b) Create Config.xml file in that dir and put this code there:

<?xml version="1.0"?>
<config>
    <modules>
        <lms_paypal>
            <version>0.1</version>
        </lms_paypal>
    </modules>
    <global>
       <models>
          <paypal>
              <rewrite>
                  <express>Lms_Paypal_Model_Express</express>
              </rewrite>
          </paypal>
       </models>
    </global>
</config>

(3)
(a) Now go to /app/etc/modules/
(b) Create Lms_Paypal.xml in that dir and put this code in Lms_Paypal.xml:

<?xml version="1.0"?>  
<config>  
    <modules>  
        <Lms_Paypal>  
            <active>true</active>  
            <codePool>local</codePool>  
        </Lms_Paypal>  
    </modules>  
</config> 
Was it helpful?

Solution

Your going wrong way in /app/code/local/Lms/Paypal/etc/config.xml and model file

/app/code/local/Lms/Paypal/Model/Express/Checkout.php

Replace config.xml file code from

<?xml version="1.0"?>
<config>
    <modules>
        <lms_paypal>
            <version>0.1</version>
        </lms_paypal>
    </modules>
    <global>
       <models>
          <paypal>
              <rewrite>
                  <express>Lms_Paypal_Model_Express</express>
              </rewrite>
          </paypal>
       </models>
    </global>
</config>

To

<?xml version="1.0"?>
<config>
    <modules>
        <Lms_Paypal>
            <version>0.1</version>
        </Lms_Paypal>
    </modules>
    <global>
       <models>
          <paypal>
              <rewrite>
                  <express_checkout>Lms_Paypal_Model_Express_Checkout</express_checkout>
              </rewrite>
          </paypal>
       </models>
    </global>
</config>

Also replace code in file app/code/local/Lms/Paypal/Model/Express/Checkout.php from

public function prepareOrderReview($token = null)
{
    parent::prepareOrderReview($token);
    $this->_quote->setMayEditShippingAddress(false);
    $this->_quote->setMayEditShippingMethod(false);
    $this->_ignoreAddressValidation();
    $this->_quote->collectTotals()->save();
}

To

class Lms_Paypal_Model_Express_Checkout extends Mage_Paypal_Model_Express_Checkout
{

    public function prepareOrderReview($token = null)
    {
        $payment = $this->_quote->getPayment();
        if (!$payment || !$payment->getAdditionalInformation(self::PAYMENT_INFO_TRANSPORT_PAYER_ID)) {
            Mage::throwException(Mage::helper('paypal')->__('Payer is not identified.'));
        }
        $this->_quote->setMayEditShippingAddress(false);
        $this->_quote->setMayEditShippingMethod(false);
        $this->_ignoreAddressValidation();
        $this->_quote->collectTotals()->save();
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top