|
Adding Barcodes to a PDF file (revised a little)
After posing that first message I got to poking around and figured out how to separate my local changes from the Magento core. Here is what I did....
We are going to override/overload a module so that we do not have to hack on the core Magento code. This way, upgrades will not affect our changes. To do this you basically need to create the directory structure under your local directory to mirror that of the Magento code. Then, create a few xml files to let Magento know it’s there. Finally, copy over the Shipment.php file to your local directory for modification.
The basic steps to achieve this are…
1) Create the directory structure
2) Create xml files
3) copy the php file and edit it.
*** Make sure your cache settings are disabled in Magento so you can see your changes ***
The file we want to copy and edit is {your_magento_install_dir}/app/code/core/Mage/Sales/Model/Order/Pdf/Shipment.php
So lets do it (commands are for unix)
cd {your_magento_install_dir}/app/code mkdir -p local/Local/Sales/Model/Order/Pdf mkdir -p local/Local/Sales/etc cp core/Mage/Sales/Model/Order/Pdf/Shipment.php local/Local/Sales/Model/Order/Pdf/Shipment.php
Now edit the new local Shipment.php file and put the barcode stuff in there. (see instructions in previous post)
Important: Change the class decloration from this....
class Mage_Sales_Model_Order_Pdf_Shipment extends Mage_Sales_Model_Order_Pdf_Abstract
To this…
class Local_Sales_Model_Order_Pdf_Shipment extends Mage_Sales_Model_Order_Pdf_Abstract
Then, create config.xml in the Sales/etc directory and put this in it…
<?xml version="1.0"?> <config> <global> <models> <shipmentpdf> <rewrite> <pdf_shipment>Local_Sales_Model_Order_Pdf_Shipment</pdf_shipment> </rewrite> </shipmentpdf> </models> </global> </config>
Then, create this file {your_magento_install_dir}app/etc/modules/Local_All.xml and put this in it…
<?xml version="1.0"?> <config> <modules> <Local_Sales> <active>true</active> <codePool>local</codePool> </Local_Sales> </modules> </config>
After you make some changes (and turn off caching) you should see your changes when you generate a packing slip.
Enjoy!
|