0

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> 
0

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();
    }
}
|improve this answer|||||
  • Hey Abdul, thanks very much for your suggestion. I made these changes but unfortunately it's still not working. – Randall Mar 7 '16 at 18:46
  • updated ans pls check and also remove magento Cache in admin side. – Abdul Mar 8 '16 at 5:07
  • Hi Abdul, thanks, tried again but still no luck. This time I'm getting a fatal error though so maybe some progress. Calling '<base_url>/paypal/express/start/' I get: 'Fatal error: Call to a member function setCustomerWithAddressChange() on a non-object in <path_to_root>/app/code/core/Mage/Paypal/Controller/Express/Abstract.php on line 72' – Randall Mar 8 '16 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.