Rewriting Mage_Paypal_Model_Express_Checkout - magento

I have run into a problem where shipping options are not making it to the PayPal Express review page. If the buyer enters a free shipping coupon and then uses PayPal Express, when they return from the PP website, the review page where the submit the order doesn't have the free shipping option.
I found a thread where this was answered by adding code to the Mage_Paypal_Model_Express_Checkout class. This change works, but modifying core code is a no-no, so I'm trying to rewrite the class and I'm having trouble. I've rewritten core classes before, but this one is different somehow and I can't figure it out. Can someone point me in the right direction?
here's the contents of my config.xml. Does this look right?
<config>
<modules>
<VPS_Paypal>
<version>0.1.0</version>
</VPS_Paypal>
</modules>
<global>
<models>
<paypal>
<rewrite>
<express_checkout>
<class>VPS_Paypal_Model_Express_Checkout</class>
</express_checkout>
</rewrite>
</paypal>
</models>
</global>
</config>

I haven't tested this, but based on the class name I would think that adding this to the section of your config would work:
<paypal>
<rewrite>
<express_checkout>Your_Model_Class_Here</express_checkout>
</rewrite>
</paypal>
Your custom class should extend Mage_Paypal_Model_Express_Checkout and only override the method you want to change.

Related

Magento 1.9 - Customizations to Paypal Express Checkout not working

I am trying to customize the Magento Paypal Express Checkout functionality to pass the order total amount using current store's currency and rather than the base currency to Paypal. However, my customizations aren't appearing on the site.
Here is what I have created:
app/code/local/My/Paypal/Model/Express/Checkout.php
<?php
class My_Paypal_Model_Express_Checkout extends Mage_Paypal_Model_Express_Checkout {
public function getCheckoutShortcutImageUrl() {
//Copy pasted the original code with some modifications to use
// _quote->getGrandTotal()
}
public function start($returnUrl, $cancelUrl, $button = null) {
//Copy pasted original code with modifications to use
//_quote->getGrandTotal() and _quote->getStoreCurrencyCode()
}
}
?>
app/code/local/My/Paypal/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<My_Paypal>
<version>0.1.0</version>
</My_Paypal>
</modules>
<global>
<models>
<paypal>
<rewrite>
<express_checkout>My_Paypal_Model_Express_Checkout</express_checkout>
</rewrite>
</paypal>
</models>
<global>
</config>
app/etc/modules/My_Paypal.xml
<?xml version="1.0"?>
<config>
<modules>
<My_Paypal>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</My_Paypal>
</modules>
</config>
I see my module showing up correctly under System -> Configuration -> Advanced -> Advanced -> Disable Modules Output as Enable, while Mage_Poll and Mage_Tag are showing up as Disable.
Directly changing Mage_Paypal_Model_Express_Checkout works, so I know my code changes work, but the correct way of customizing a model doesn't seem to work.
I refresh and flush the Magento cache with each change, so it's not just a caching issue.
My guess is that there is something wrong with my config.xml, but at this point I can't seem to figure out what.
Any ideas? Alternatively, a better way of achieving what I want to do would also work.
Also, how do I debug Magento to understand what may be erroring out in my customization? Are there logs I can turn on or look at?
your way of implementing it is well enough. the only better way would be using events, but that is not always possible.
try to add dependency to paypal module and check if this model already has been rewritten elsewhere.
<config>
<modules>
<My_Paypal>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Paypal />
</depends>
</My_Paypal>
</modules>
</config>

Magento - how to rewrite an extension model, which has rewritten a core model?

i'm writing an extension, which needs to overwrite the Mage_Core_Model_Order-Class. I know how that works. The problem now is, that there´s another Extension (Webshopapps_Dropship), which also overrides/extends this class. Now, if i try to override the Class from the Dropship-Extension, it won´t work.
This is what i inserted in my config.xml
<global>
<models>
<dropship>
<rewrite>
<sales_order>My_Module_Model_Sales_Order</sales_order>
</rewrite>
</dropship>
</models>
</global>
I also try to depend my module from the Dropship-extension. But this also doesnt work.
Please help me, i can´t find, what is wrong.
Everytime i create the class via
$myOrderClass = Mage::getModel("sales/order");
i will get the Dropship-Class and not the one from my own extension.

Magento block override from two different modules

Hi I have some issues in overriding a magento core block. In my module I need to override Mage_Catalog_Block_Navigation
<blocks>
<catalog>
<rewrite>
<navigation>Mycompany_Mymodule_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
but this is already overridden by another magento extension from another company:
<blocks>
<catalog>
<rewrite>
<navigation>Othercompany_Othermodule_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
Both extension overrides different methods and they don't know abut each other, but magento reads the second company overrides and not my. I don't want to use module dependencies. Is there any way to not break the two extensions functionality.
Yes, you have to decide which one officially overwrites the core Block. Have that one inherit the one that isn't doing the override, and have that one inherit the core one.
My_Custom_Block extends Other_Custom_Block
Other_Custom_Block extends Mage_Core_Block
Mage_Core_Block extends Whatever_Magento_Wants
Edit the config.xml files so that only My_Custom_Block is the one that is overriding the core Block.
EDIT
Here's the XML you need:
<blocks>
<catalog>
<rewrite>
<navigation>Mycompany_Mymodule_Catalog_Block_Navigation</navigation>
</rewrite>
</catalog>
</blocks>
Thx Max.
I think, like your example, that the "My_Custom_Block" should be the last hierarchic class, so you don't touch anythings in "Other_Custom_Block" class.
Then you have only to comment the rewrite rule in "Other Company" config.xml.

Custom Account Controller Causes 404 On Address Book

I've encountered a problem in our Magento installations that I've been having a really hard time tracking down. Whenever a customer goes to the "My Account" page and clicks the "Address Book" link, it sends them to the default 404 CMS page. I searched around Google and found a few similar problems, but they weren't quite the same. However, one solution that was offered was that a custom login redirect module was the cause.
So I started disabling all of our custom modules one by one to see if that would fix the problem, and it turned out that disabling our custom Account Controller fixes the problem. I tried to track this down further by using Mage::log() in the overridden methods to see if they were getting called when trying to access /customer/address/, but nothing showed up in the logs.
The only lead I have left is that it's a problem with my controller configuration. This is the config.xml I have set up:
<?xml version="1.0"?>
<config>
<modules>
<mymodule_login>
<version>0.1.0</version>
</mymodule_login>
</modules>
<frontend>
<routers>
<mymodule_login>
<use>standard</use>
<args>
<module>MyModule_Login</module>
<frontName>customer</frontName>
</args>
</mymodule_login>
</routers>
</frontend>
<global>
<rewrite>
<mymodule_login>
<from><![CDATA[#^/account/#]]></from>
<to>/customer/account/</to>
</mymodule_login>
</rewrite>
<blocks>
<customer>
<rewrite>
<register-login>MyModule_Login_Block_View</register-login>
</rewrite>
</customer>
<login>
<class>RegisterLogin</class>
</login>
</blocks>
</global>
</config>
I think it might be a problem with the rewrite from #^/account/# to /customer/account/, but I don't know enough about Magento rewrites to determine if that's accurate or not. The methods I have overwritten are: loginPostAction, _loginPostRedirect, and _welcomeCustomer.
Dick Laurent was right - it was my configuration. All I did was add a second controller that overrode Mage_Customer_AddressController and now it works fine. The problem was that my frontend name was "customer" so it was expecting to find the corresponding controller in my custom module for when it went to the URL /customer/address/.
I had to override Mage_Customer_AccountController, however you can't simply just override just one controller, you have to override the whole module.
So here is how you solve in this situation. You create files that reference the parent.
NOTE: Replace {Namespace} with your custom namespace.
Here is my config.xml: (inside the folder app/code/local/{Namespace}/Customer/etc)
<?xml version="1.0"?>
<config>
<modules>
<{Namespace}_Customer>
<version>0.1.0</version>
</{Namespace}_Customer>
</modules>
<frontend>
<routers>
<customer>
<use>standard</use>
<args>
<module before="Mage_Customer">{Namespace}_Customer</module>
<frontName>customer</frontName>
</args>
</customer>
</routers>
</frontend>
</config>
Now overriding Mage_Customer_AccountController: (inside the folder app/code/local/{Namespace}/Customer/controllers)
<?php
require_once ('Mage/Customer/controllers/AccountController.php');
class {Namespace}_Customer_AccountController extends Mage_Customer_AccountController
{
protected function _loginPostRedirect()
{
$session = $this->_getSession();
if($session->getBeforeAuthUrl() == Mage::getUrl('checkout/onepage/index')){
$session->setBeforeAuthUrl(Mage::getUrl('checkout/cart'));
$this->_redirectUrl($session->getBeforeAuthUrl(true));
return;
}
return parent::_loginPostRedirect();
}
}
This redirects the customer back to their cart page after they login though checkout. We did this, because if there is an item in their cart from a previous session, Magento will combine the recent cart items with the ones from the previous session and proceed to payment without telling the customer. So to avoid customer complaints we simply redirect back to cart so the customer can see that this happens.
Now because we are overriding the entire module, we have to create the aforementioned files that reference the parent. The two other controllers under Mage_Customer are Mage_Customer_AddressController and Mage_Customer_ReviewController. Your Magento instance may vary as versions change, so make sure you check the parent folder, located at (app/code/core/Mage/Customer/controllers), and NEVER DIRECTLY EDIT CORE!
Here we reference the parent for Mage_Customer_AddressController: (inside the folder app/code/local/{Namespace}/Customer/controllers)
<?php
require_once ('Mage/Customer/controllers/AddressController.php');
class {Namespace}_Customer_AddressController extends Mage_Customer_AddressController
{
}
Likewise for Mage_Customer_ReviewController: (same file location)
<?php
require_once ('Mage/Customer/controllers/ReviewController.php');
class {Namespace}_Customer_ReviewController extends Mage_Customer_ReviewController
{
}
Without these files Magento simply can't find the controllers and throws a 404.
Lastly, create a file under app/etc/modules called {Namespace}_Customer.xml to enable your override, and address book should no longer 404.

custom attribute UI in Magento admin

I'm trying to change the way Magento shows options of an attribute with multiple select.
I have 10K options for this attribute.
How can I override the UI and use an Ajax based UI?
The admin will be able to filter options and present only ~20 each time.
I know how to use js and php for this but not in Magento.
Thanks
You can try to rewrite block class responsible for this attribute.
<global>
<blocks>
<adminhtml>
<rewrite>
<catalog_product_edit_tabs_price>Company_Module_Block_Adminhtml_Tabs_Price</catalog_product_edit_tabs_price>
</rewrite>
</adminhtml>
</blocks>
</global>
Then in your Company_Module_Block_Adminhtml_Tabs_Price you can re-declare function responsible for logic for price attribute (for example).
You should have a good knowledge of Magento for this.

Resources