How to set up Magento with USPS shipping methods and get permission to use the USPS production API
by Asher Bond on Jun.18, 2009, under ecommerce
Are you getting this error from Magento?
United States Postal Service:
This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.
This is because you aren’t getting proper access to the USPS API. Magento, by default comes with the following URL set up in the shipping configuration for USPS:
http://production.shippingapis.com/ShippingAPI.dll
The problem is that by default, you don’t have access to USPS’s production API. They have to approve you first. Keep in mind that they only allow you to use it on one web site per account, so if you’re setting Magento up for a client, customer, or other business entity other than your own you should set up a separate USPS account for them.
You can set up your USPS WebTools account here:
http://www.usps.com/webtools/
Once you have set up your account, they will give you access to the testing environment. The URL for the USPS test API is:
http://testing.shippingapis.com/ShippingAPITest.dll
Now, before you paste that into Magento, you should be aware that the USPS test environment only supports very specific data. According to their own documentation:
ZipOrigination: 10022
ZipDestination: 20008 (is set during Checkout process by user)
Pounds: 10
Ounces: 5 (weight can be set for every product on Administration > Products)
Size: LARGE
Machinable: TRUETo test international shipping use the following values:
Pounds: 2
Ounces: 0
MailType: Package
Country: Albaniaor
Pounds: 0
Ounces: 1
MailType: Postcards or Aerogrammes
Country: AlgeriaAll other parameters’ values won’t work in the test environment.
This is why most Magento consultants and installation service providers typically just ask USPS to turn on production mode. When you are approved by USPS for the production API, you should use the following URL:
http://production.shippingapis.com/ShippingAPI.dll
But remember, it’s very important that you set up a separate USPS account for each Magento web site (or at least one per domain). USPS will disable your access to their production server if you are caught using your account on multiple web sites. That would make all of your Magento customers very upset, all at the same time.
To request access to the USPS production API, fill out the form here:
http://www.usps.com/webtools/webtoolsapirequestform.htm
Be sure that in your request, you explain that you are using third party software (Magento) and that you only want access to the API so that you can calculate shipping costs associated with using USPS.
If you leave out this information they will reject your request or ask you to submit a valid test before they give you access. Third party software doesn’t need to be tested as long as you tell them you are using Magento.
USPS doesn’t allow you to use their API for batch processing or data cleansing, so be sure to NOT check these boxes on the request form.
Once USPS gives you access to their production API server, Magento should work with all USPS shipping options. If you are still having trouble, check that you have access to USPS’s production API server.
USPS Tech Support: 1-800-344-7779 (7:00 AM to 11:00 PM EST daily)
Once you have it correctly configured and you have access to the production API, you should be able to place an order and check out to see a list of USPS shipping options with the costs of each calcualted based on the weight of the product you are ordering.
You will need to remove shipping options that are irrelevant, for example USPS Library Mail is only for shipping academic things like books between academic institutions or libraries.
Click here to read about different shipping methods such as Parcel Post.
How to Select Related Posts (by tags and category relevance) in Wordpress
by Asher Bond on May.21, 2009, under databases, wordpress
- The first step is to get the post ID of the blog post you are viewing. You can get the id of a post by using $post->ID in Wordpress. Let’s pretend it’s 3987.
- You will also need to know the term ids for categories and tags associated with this blog post
Here is some PHP code you can use in wordpress to get the tags of your post ID.
Let’s assume the result is one category (264) and one tag (41).
- If you are not using Wordpress Mu, you can simply select from wp_term_relationships and wp_posts
- If you are using Wordpress Mu, you will need to specify the tables as wp_MU-BLOG-ID#_term_relationships and wp_MU-BLOG-ID#_posts. Let’s assume we are using Wordpress Mu and our blog ID is 1. The tables we are working with are wp_1_term_relationships and wp_1_posts
Notice that we have limited our results to the 5 most relevant posts. It is recommended that you limit this query because it can be a difficult query to process if you are running it on a blog that has thousands of posts. You can change LIMIT 5 to LIMIT 25 or so on blogs that are hosting less than 5,000 posts without seeing much of a difference in performance. On larger, more frequently updated blogs or Wordpress MU sites which are hosting a lot of blogs on the same server, it is recommended that you cache the results of this query and only use it once an hour or once every time a blog entry has been updated.
Magento Installation gives error: PHP Extention “pdo_mysql” must be loaded and PHP Extension “mcrypt” must be loaded
by Asher Bond on May.05, 2009, under ecommerce
I was installing Magento (E-commerce software) and got the following errors:
o PHP Extension “pdo_mysql” must be loaded
o PHP Extension “mcrypt” must be loaded
To add these extentions, I had to recompile php adding these two parameters to my PHP 5 configure script:
–with-mcrypt
–with-pdo-mysql
configure: error: xml2-config not found. Please check your libxml2 installation.
by Asher Bond on May.05, 2009, under computing, internet
I got this error when trying to configure php 5.2.6:
configure: error: xml2-config not found. Please check your libxml2 installation.
I’m using Debian and it showed that I had libxml2 installed (and it was the latest version).
It turns out that the latest stable version of libxml2 doesn’t include a file named xml2-config. I suppose I could have linked that file to the config file that the stable version of libxml2 uses, but the easy fix is to just install the newer development version of libxml2 using the following command:
apt-get install libxml2-dev
That’s all I needed!
Designing and Optimizing Associative Database Models for Scalable Social Web Applications
by Asher Bond on Apr.28, 2009, under databases
Usually I design web application databases for MySQL, but the methods listed here are compatible with Oracle or any relational database management system. I’m not going to guide you through your own design process, but here are the basic database design principles you will need to know as you optimize your database for social applications:
- Use unsigned numeric integers (properly scaled for the size of your tables) without leading zeros.
- Start out with third normal form (3NF). Use associative tables to eliminate redundancy at first.
- Avoid storing files in the database. Use numeric filenames to associate data records with the file system.
- If necessary, use table caching and views to optimize performance based on use patterns. This should be done in conjunction with software app testing.
- If you need to shorten URIs passed between APIs or URLs for the user, make a relationship table referencing the longer URI with a shorter handle. Use numeric handles for small data sets or alpha numeric for larger data sets.
- For time related queries, associate the numeric primary key of long tables with relevant timestamps (hourly, daily, weekly, monthly or other time intervals that your social web application would query.) This will reduce query time for long tables.
How to Find and Replace text inside a data field in SQL (string manipulation)
by Asher Bond on Oct.22, 2008, under computing, databases
WordPress Mu Tips: How to Import and Export Large Blogs Without The Hassle of Splitting The Files Up
by Asher Bond on Oct.09, 2008, under computing, wordpress
First, log in as a site administrator, then go to the blog you want to export from and choose manage -> export, and save your xml file.
Now log into the blog your importing to as a site administrator and choose manage -> import -> Wordpress, and load up the xml file.
You probably get an error message like:
The uploaded file exceeds the upload_max_filesize directive in php.ini.
You could edit your php.ini, but I don’t recommend this because it’s the sledgehammer approach. You can probably use a little more finesse by simply editing your .htaccess file (assuming your web server allows .htaccess to override php.ini).
First try this.. edit:
/path/to/your_wordpress_mu_directory/.htaccess
Add these lines to the top (adjust the values how you need to):
Now try again. If you get the same problem, you will need to edit your php.ini or get your systems administrator / web hosting provider to do it for you.
If you are successful, you will probably get a different error:
This file is too big. Files must be less than 1500 Kb in size.
The good news is that this means you have already configured php to allow Wordpress to import your large xml file, but you still need to configure Wordpress Mu to allow this. When you install Wordpress, MU… it creates a record for each blog setting a variable called “fileupload_maxk” to 1500. This is what is limiting you.
Here’s the SQL code you can use to fix it by changing the variable(s) for every mu blog to a higher number (in this case 15000 bytes, but you can change it to a higher or lower number.)
BE SURE TO PUT IN YOUR DATABASE NAME HERE:
When you create new blogs, they will still default to 1500. If you want to change this also, you must edit two files:
/path/to/your_wordpress_mu_directory/wp-includes/wpmu-functions.php
and
/path/to/your_wordpress_mu_directory/wp-admin/includes/mu.php
Just change:
to
(….. or some number of bytes you want instead of 15000.)
That’s it, you should be able to import wordpress blogs as large as you want now.
How To Fix Your Start Menu and Bring Back Task Manager After Antivirus 2008 (or some other virus) removed it
by Asher Bond on Aug.06, 2008, under computing
“Antivirus 2008″ a.k.a “Vista Antivirus 2008″ is actually a virus. When you boot up, it runs all kinds of stuff you don’t want in the background of your computer. One of the worst things it does is disable your ability to stop processes from running in the background.
You know you’re in trouble when you hit CTRL+ALT+DELETE and you get the message:
“Task Manager has been disabled by your Administrator”
LULZ! You can’t even get to your Task manager to stop who knows what from running in the background of your computer. Wow you really got owned this time.
BEFORE YOU START
- Boot into safe mode with networking and run Symantec’s Norton Antivirus or Avast (if you want a free one) from www.avast.com to make sure the virus isn’t running in the background anymore. You might have to download this from another computer or buy it from the store. Some viruses will even redirect you to their own web site when you try to go to symantec.com, trendmicro.com, etc.
- Don’t put credit card information into a computer that might have a virus. It’s better to download the trial or buy it in a store.
- Don’t use shady “virus scanners” like StopZilla or Viruses acting like anti-viruses such as “error cleaner” or “Vista Antivirus 2008″ etc.
- Make sure that you have the latest update of your virus scanning software. What makes you think it’s gonna find the virus if the software hasn’t been updated for weeks.
- Vista AntiVirus is probably running on every time your system boots up and it’s probably running as vav.exe. You might want to find and delete that file if your Antivirus program missed it for some reason. It’s probably under C:\Program Files\VAV. You can’t delete it while it’s running, but you can rename it to novav.exe and delete the other files in this folder. When vav.exe can’t find the files, it will crash and you can then delete it. Also delete folders named “Antivirus 2008.”
- Run Trend Micro’s Hijackthis and remove malicious files from the system boot process. If you aren’t sure if the file is malicous or not, look to see when the file was last modified. If you got the virus recently, then that file may be one of the malicious ones. Look the filename up on google from another computer and see what people are saying about it. Watch out for .dll (especially random letters like c:\WINDOWS\xokvrpwg.dll) and .exe files. Also check for system policies like “DisableRegedit=1″. Viruses often change your desktop using Desktop component 0… file://somedirectory\index.htm. Delete these.
- Continue with the rest of these instructions once you have scanned your computer and cleaned out the viruses.
Here’s how to fix your Task Manager:
- Don’t panic. Don’t download any more “error cleaners” or garbage that probably messed up your computer in the first place.
- Shut down your computer (by force if you have to) and boot it into safe mode.
(If you don’t know how to get to safe mode, all you have to do is hold down F8 during the boot up process). LOG IN AS ADMINISTRATOR. Don’t see Administrator as an option? Hit CTRL+ALT+DELETE and type Administrator. - Once you’re LOGGED IN AS ADMINISTRATOR in SAFE MODE, click “Start”, then go to “Run”… Oh noez.. where’s run? Wow, you sure got owned this time. You can’t even get the run menu up in SAFE MODE. Don’t worry, you still don’t have to scrap everything and do a clean re-installation.
- Right click the task bar and go to “properties”.
- Click the “Start Menu” tab.
- Click the “Customize…” button.
- Click the “Advanced” tab.
- In the “Start menu items:” list, go through and click all the buttons that say “Display as a link”.
- Click “OK” after you are done clicking all the “Display as a link” buttons.
- Click “OK” again to get out of the “Taskbar and Start Menu Properties”.
- Now you should have your Start Menu back to normal. Try to find the “run” button. If you can’t see it, it’s probably because you’re in Safe Mode and it’s scrolling off the screen. Don’t panic, just hit the up arrow on your computer once. This should highlight the “shutdown” button. Hit the up arrow on your keyboard again and you will be at “Log Off”. If you don’t see “Log Off”, then you’re not logged in as Administrator and you need to go back to step 1. Hit the up arrow a third time and you will be at “run” (even though you can’t see it). Now hit enter.
- Now that you have the “run” menu up, type regedit in the “Open” box. and click “OK”.
- You probably will get a box that pops up saying “Registry editing has been disabled by your administrator” LULZ! You can’t even get to regedit? Wow, you sure got owned this time. Don’t panic.
- WINDOWS XP PROFESSIONAL: Go to Start, Run and type gpedit.msc and press ENTER. This should bring up a screen that says “Group Policy”.
- If that didn’t bring up “Group Policy” then you don’t have Windows XP Professional. I guess that means you’re not really much of a PC professional are you? That’s ok, you aren’t missing much.. you will have to type in this nice long command though:
.
- If you’re at the “Group Policy” screen, Click “User Configuration”, then click “Administrative Templates”, then click “System”. Double-click “Prevent Access to registry editing tools” and set it to “Disabled”.
Note: If the setting already reads “Not Configured”, set it to “Enabled”, and click “Apply”. Then revert it back to “Disabled”. This ensures that the “DisableRegistryTools” registry value is removed successfully.
Repeat this step for every item that says “Disable…” or “Prevent Access to…” (for example “Prevent Access to the command prompt”). Repeat this step for the CTRL+ALT+DEL options as well. This is where you can disable the policy of “Remove Task Manager”. When you’re finished, close the “Group Policy” screen. - If you still don’t have regedit back, it’s possible that the virus may have put a regedit.com file in your windows directory. Windows chooses to open .com files before it opens .exe files. If you get something different when you run regedit.exe, then you should delete regedit.com from your windows directory. Do a file search for regedit* and see what comes up.
dev/null, screen, and ptmx permission problems in xen vps
by Asher Bond on Jul.08, 2008, under computing, internet
I got switched to a Xen VPS (debian linux) recently and discovered that some applications couldn’t write to /dev/null. It turns out that /dev/null was actually only readable and writable by root. I logged in as root and changed the permissions so that /dev/null was readable and writable by all.
chmod 666 /dev/null
This solved the problem.
I was still having trouble with some shell accounts, though, because no users could access screen (virtual terminals). The error message was that no PTYs were available. I solved this problem by giving these users access to the /dev/ptmx directory. This directory was initially only readable, writable, and executable by root, but I made it so that anyone in the admin group could read write and execute this directory.
chown root:adm /dev/ptmx
chmod 770 /dev/ptmx
If you want any user to be able to use screen, you will have to do this:
chmod 777 /dev/ptmx
Addthis.com fully functional share dropdown menu code for Wordpress
by Asher Bond on Jun.29, 2008, under internet, wordpress
If you have addthis.com and you aren’t satisfied with the plain share button that’s available for Wordpress, you can use this code to change it to the fully functional dropdown share menu. Just add this code to the end of your blog posts. You will most likely want to add it to the archive.php, index.php, and single.php files in your theme directory ( /path/to/wordpress/site/wp-content/themes/sometheme/single.php etc.)
I just made one php file called addthis_button.php that had this code in it:
Then I added the code to include it in each of these files: single.php, index.php, and archive.php:
