Magento 1.9 - Customizations to Paypal Express Checkout not working - magento

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>

Related

Arabic words in invoice pdf print Magento

I'm trying to fix this problem by using integration TCPDF in magento but i don't know how do that
this is my try in this file
\app\code\core\Mage\Sales\Model\Order\Pdf\Abstract.php
require_once('TCPDF/TCPDF.php');
$pdf = new TCPDF_TCPDF
(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true,'UTF-8', false);
I don't know waht i'm doing wrong. thank you.
1) Don't edit core files.
2) There are multiple invoice generators in magento: invoice from the backend, invoice on success page etc. So make sure that you are editing and testing the right one. The example below works for invoices in the backend.
3) There may be custom modules that are overwriting your xml, like Webshopapps_Invoicing, check that or it will not work (that's the issue that I had when trying something similar).
After you copied TCPDF to your magento lib folder so that you will have now root/TCPDF/TCPDF.php edit TCPDF.php by changing the class name from tcpdf to TCPDF_TCPDF
Go into code/local/Yourcompany and create the folder invoices. In this folder create etc/config.xml with this content:
<?xml version="1.0"?>
<config>
<modules>
<Yourcompany_Invoices>
<version>0.0.1</version>
</Yourcompany_Invoices>
</modules>
<global>
<models>
<sales>
<rewrite>
<order_pdf_invoice>Yourcompany_Invoices_Sales_Model_Order_Pdf_Invoice</order_pdf_invoice>
</rewrite>
</sales>
</models>
</global>
</config>
Create another folder structure in code/local/Yourcompany like this Sales/Model/Order/Pdf and add Invoice.php:
class Yourcompany_Invoices_Sales_Model_Order_Pdf_Invoice extends Mage_Sales_Model_Order_Pdf_Invoice {
// it can be another class if you have a custom module overwriting it, like Webshopapps_Invoicing_Sales_Model_Order_Pdf_Invoice
$pdf = new TCPDF_TCPDF();//your stuff here
}
Then submit a test order and go into admin and check a pdf invoice.

Magento rewrite extension controller

I am trying to do small change in community module MDN_Organizer in Magento 1.9 and it is turning out to be nightmare for me.
I need to change also one Grid so I created in code/local folders MDN / Organizer / Block / Task and new file Grip.php
For that, I have to rewrite one Action in controller TaskController which is in folder MDN / Organizer / Controllers / TaskController.php
Is it possible to rewrite that controller in local MDN / Organizer folder? Or Do I need to put controller to my own modules?
Can controller have the same name?
How etc/config should looks?
Controller is for admin.
You need to create new module you can keep in local or community it is not matter
But add code in you file
app\etc\modules\Mycompany_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Mycompany_Modulename>
<active>true</active>
<codePool>local</codePool>
<depends>
<MDN_Organizer/>
</depends>
</Mycompany_Modulename>
</modules>
</config>

how to change email format from html to text in magento for admin?

in magento on order confirmation email is sent to admin in HTML format,
but i want to change it to plain text format so how and from where i can change that format only for admin, customer should get email in HTMl format as it is.
Can anyone please give me solution for this?
Thanks.
For future readers, do not edit core files as others suggest. You can achieve this in config alone with a tiny custom module.
I have AheadWorks' blog module installed, you may not, or you may have other modules that need their email format overridden. So, adjust accordingly.
Create app/etc/modules/YourNameSpace_EmailFormat.xml and add to <depends>, so your config is loaded last:
<?xml version="1.0"?>
<config>
<modules>
<YourNameSpace_EmailFormat>
<active>true</active>
<codePool>local</codePool>
<depends>
<Mage_Contacts/>
<AW_Blog/>
</depends>
</YourNameSpace_EmailFormat>
</modules>
</config>
Create app/code/local/YourNameSpace/EmailFormat/etc/config.xml, adding elements for all the templates you wish to override:
<?xml version="1.0"?>
<config>
<modules>
<YourNameSpace_EmailFormat>
<version>1</version>
</YourNameSpace_EmailFormat>
</modules>
<global>
<template>
<email>
<customer_create_account_email_template>
<type>text</type>
</customer_create_account_email_template>
</email>
</template>
</global>
</config>
That's it. I needed the reverse, so I had <type> set to html. This goes very well with Yireo's Email Override module so you can easily customise your templates. If converting plain text emails to HTML, be sure to change template tags like {{var foo.bar}} to {{htmlescape var=$foo.bar}} to prevent malicious code injections.
First create custom email template from Transactions emails and text type set as plain. Note down that template Id. and use in below file.
At \app\code\local\Mage\Sales\Model\Order.php sendNewOrderEmail() load manually template is and sent variables to that and send email.
you have to override and extend the Mage_Core_Model_Email_Template model to achieve this and set the correct header from there and you can't separate those by user and you ahve to build your own logic for that

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.

Rewriting Mage_Paypal_Model_Express_Checkout

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.

Resources