Magento: Tax Rules set, but customer not charged tax
This morning I received a job to troubleshoot why a customer was not charged sales tax even though the customer lived in the zip code that the Tax Rule was set for. My first inclination was that perhaps his billing address was different from his shipping address and that the rule applied to his shipping address and not his billing address. That was not the case though.
After closer examination I realized the customer inputted a ZIP+4 (XXXXX-XXXX) style US Zip Code. When I looked at the Tax Rules they were all written like this:
“US-FL-32304-Rate 1,US,FL,32304,7.5,”
In order to fix the issue I created a wildcarded rule for every Tax Rule set that looks like this:
“US-FL-32304-*-Rate 1,US,FL,32304-*,7.5,”
Special thanks to my new buddy <Groenleer> on #magento (freenodes) for helping me troubleshoot this!!!
PHP: Convert curly quotes to straight quotes
A client of mine writes, “Take a look at the personal message (from our web form) on the quote below….what is happening with the characters in those fields. I believe there was likely abbreviation for foot: 8’”
Cause: This is typically caused by someone creating string of text in Microsoft Word and then pasting it into a web form.
Solution: Set up the following search and replace parameters in your PHP script:
$search = array("\xe2\x80\x9c", "\xe2\x80\x9d", "\xe2\x80\x98", "\xe2\x80\x99");
$replace = array('"', '"', "'", "'");
$formmessage = str_replace($search, $replace, $_POST['message']);
Magento: display and round prices to 3rd decimal point
Second time now I’ve had the client request that set their Magento prices to display and round to the third (3rd) decimal point. This time I will share with you how I performed this change in Magento (ver. 1.3.2.4).
First I FTP to my lib/Zend/Currency.php file and change the following:
protected $_options = array( 'position' => self::STANDARD, 'script' => null, 'format' => null, 'display' => self::NO_SYMBOL, 'precision' => 2, 'name' => null, 'currency' => null, 'symbol' => null );
to
protected $_options = array( 'position' => self::STANDARD, 'script' => null, 'format' => null, 'display' => self::NO_SYMBOL, 'precision' => 3, 'name' => null, 'currency' => null, 'symbol' => null );
Please note that if you upgrade Magento this will be overwritten and this change will be required again after upgrade!!!
Second, copy app/code/core/Mage/Core/Model/Store.php to app/code/local/Mage/Core/Model/Store.php. By doing this you protect this file from being overwritten during upgrades. Next change the following code in that file from:
public function roundPrice($price)
{
return round($price, 2);
}
to
public function roundPrice($price,$roundTo=3)
{
return round($price, $roundTo);
}
Lastly, I suggest copying app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php to app/code/local/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Price.php. Then you can change the following code in that file from:
public function getEscapedValue($index=null)
{
$value = $this->getValue();
if (!is_numeric($value)) {
return null;
}
return number_format($value, 2, null, '');
}
to
public function getEscapedValue($index=null)
{
$value = $this->getValue();
if (!is_numeric($value)) {
return null;
}
return number_format($value, 3, null, '');
}
Clear your Magento Cache and now you have prices that extend to the third (3rd) decimal point both on the front end and in the admin section of Magento!!!
If you have any suggestions on how to improve this post please feel free to drop me a line!
Client says “proceed to checkout” empties cart and returns to homepage
A customer would come to the website, place items in their shopping cart, and then click the “proceed to checkout button” from the shopping cart. Rather than take them to the cart, our Magento website would immediately forward them to the home page and empty all the items from their cart.
Cause: ISPs like AOL, Comcast, and Shaw.ca use a technique of changing IP addresses that cause security settings in Magento to empty the cart and not allow people to check out.
Fix: Change the Session Validation settings in the Magento Admin, found under System > Configurations > Web, to ‘no’ on everything except “Validate HTTP_USER_AGENT.” After doing this, go to System > Cache Management and refresh the configuration cache to apply the changes.
syntax error [Break on this error] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML…3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">”
I received some clients website files today in which Firefox was throwing a syntax error on the DOCTYPE. To fix this make sure that each of your javascript calls contains type=”text/javascript”. The client had only language=”javascript”. This attribute has been deprecated. It was used to select other programming languages and specific versions of JavaScript. You don’t need it. Don’t use it.
After I added the TYPE the file validated just fine at W3C.
Types of Includes
The include statement is only one of four statements that you can use to include another PHP file in a currently running script. Those four statements are:
- include
- require
- include_once
- require_once
include and require are almost identical. The only difference between them is what happens when the specified file is unable to be included (that is, if it does not exist, or if the web server doesn’t have permission to read it). With include, a warning is displayed[1] and the script continues to run. With require, an error is displayed and the script stops.
In general, therefore, you should use require whenever the main script is unable to work without the script to be included. I do recommend using include whenever possible, however. Even if the db.inc.php file for your site is unable to be loaded, for example, you might still want to let the script for your front page continue to load. None of the content from the database will display, but the user might be able to use the Contact Us link at the bottom of the page to let you know about the problem!
include_once and require_once work just like include and require, respectively — but if the specified file has already been included at least once for the current page request (using any of the four statements described here), the statement will be ignored. This is handy for include files that perform a task that only needs to be done once , like connecting to the database.
Figure 1 shows include_once in action. In the figure, index.php includes two files: categories.inc.php and top10.inc.php. Both of these files use include_once to include db.inc.php, as they both need a database connection in order to do their job. As shown, PHP will ignore the attempt to include db.inc.php in top10.inc.php because the file was already included in categories.inc.php. As a result, only one database connection is created.
Figure 1. Use include_once to avoid opening a second database connection
include_once and require_once are also useful for loading function libraries.
[1] In production environments, warnings and errors are usually disabled in php.ini . In such environments, a failed include has no visible effect (aside from the lack of content that would normally have been generated by the include file); a failed require causes the page to stop at the point of failure. When a failed require occurs before any content is sent to the browser, the unlucky user will see nothing but a blank page!
Types of Includes
by Kevin Yank
How to easily suspend a client website on Media Temple grid server hosting
In this economy getting your small business web hosting clients to pay for their web hosting can prove to be quite a challenge. I don’t charge very much to my clients for web hosting so I expect to be paid on time for their annual renewals. Therefore I have taken a zero tolerance policy towards late pays. With that said I would like to share a couple of things I do to my clients that FAIL to pay on time.
The first thing I do is disable their email. Media Temple Grid Server account holders can log into their Account Center and click on the Admin button and then on the (gs) Grid-Service Control Panel page click on Enable/Disable Email from this page you can disable the whole domain’s email capabilities.
Now that we have that done we can disable their web site. I chose to take care of this task programmatically through use of a very simple shell script (Linux Shell Scripting Tutorial). The following is script I created and you can take this and fill in the blanks for your own script:
clear echo "What website would you like to suspend?" read website mv /nfs/c02/h11/mnt/XXXXX/domains/$website/html /nfs/c02/h11/mnt/XXXXX/domains/$website/html.bak mkdir /nfs/c02/h11/mnt/XXXXX/domains/$website/html touch /nfs/c02/h11/mnt/XXXXX/domains/$website/html/index.html echo "Website Suspended" > /nfs/c02/h11/mnt/XXXXX/domains/$website/html/index.html
Now to explain the script a bit:
- Open vi and paste this in and replace XXXXX with your account number. You will also need to replace the part at the beginning of the paths that starts with ” /nfs/c02/h11/mnt/” as that part is specific to the server you are on.
- Once you have that done save your script with an “sh” extension (ie disablesite.sh). I saved my script in my home directory so that I can execute it right after I log in through SSH.
- Finally, to execute the script, navigate to the directory you saved it in an then type “sh yourscriptname.sh” and hit enter! The script will clear the screen and leave you with a question… “What website would you like to suspend?”. Answer that question with the precise domain name of directory you want to suspend and hit Enter again. At this point the script will rename that domains html directory to html.bak and create a new html directory with a new index.html file that displays “Website Suspended”.
There are many other things one could do with this script like set up a Cron job to check a file that contains expiration dates for each of your sites and automatically disables them for you. Whatever you do be very careful in how you set up your script as this is pretty powerful and you could easily mess things up for yourself .
Also, it’s worth noting that if you use this script on your clients site you could very well embarrass them to the point where they just decide to not use your services ever again.
Navicat for MySQL
I must humbly admit that Navicat beats my trusty and beloved phpmyadmin for speed, usability, and functionality sake. If you are a dbadmin and haven’t tried it yet give it a whirl and I think you’ll be pleasantly surprised how easy yet robust this piece of software is.
http://www.navicat.com/en/products/navicat_mysql/mysql_overview.html
