Arabic words in invoice pdf print Magento - 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.

Related

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.

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.

Magento - Clean custom Account/Registration Fields

I followed this tutorial to add fields in the registration form of a customer under Magento, I succeed to run the example, but I know that It is not clean, for upates later...
What' the best way to rewrite all the files used in the tutorial, in a clean way :
app/design/frontend/default/yourtheme/template/customer/form/register.phtml
app/design/frontend/default/yourtheme/template/customer/form/edit.phtml
app/code/core/Mage/Customer/Model/Entity/Setup.php
app/code/core/Mage/Customer/etc/config.xml
app/code/core/Mage/Customer/controllers/AccountController.php
Thanks a lot
You need to create your own module. Never edit files in app/code/core/ folder. If you want to add functionality to Magento, you need to rewrite the base classes.
Alan Storm has good tutorials to follow:
How to create a simple 'Hello World' module in Magento?
To rewrite a controller (AccountController in your case), and after you create you own module, you can follow this tutorial.
Configure the Layout
In your app/code/local/MyCompany/Module/etc/config.xml:
<?xml version="1.0"?>
<config>
<frontend>
<layout>
<updates>
<mydesign>
<file>myfile.xml</file>
</mydesign>
</updates>
</layout>
(...)
Then you could update your layout in app/design/frontend/default/mydesign/layout/myfile.xml.

Resources