PHP

Better PHP Extension Checklist for Magento

0

Installing a software such as Magento can be daunting. Magento has several dependencies that need to be met in order for it to run. As a developer, I encounter situations where I need to install software locally on my machine because it's easier to develop for. Running web pages locally enables me to save information faster and access information more efficiently.

Here is the full list of requirements to run Magento CE:

  • Supported Operating Systems:
    • Linux x86, x86-64
  • Supported Web Servers:
    • Apache 1.3.x
    • Apache 2.0.x
    • Apache 2.2.x
    • Nginx (starting from Magento 1.7 Community and 1.12 Enterprise versions)
  • Supported Browsers:
    • Microsoft Internet Explorer 7 and above
    • Mozilla Firefox 3.5 and above
    • Apple Safari 5 and above on Mac only
    • Google Chrome 7 and above
    • Adobe Flash browser plug-in should be installed
  • PHP Compatibility:
    • 5.2.13 - 5.3.15
    • Required extensions:
      • PDO_MySQL
      • simplexml
      • mcrypt
      • hash
      • GD
      • DOM
      • iconv
      • curl
      • SOAP (if Webservices API is to be used)
    • Safe_mode off
    • Memory_limit no less than 256Mb (preferably 512)
  • MySQL:
    • 4.1.20 or newer
    • InnoDB storage engine
  • SSL:
    • If HTTPS is used to work in the admin, SSL certificate should be valid. Self-signed SSL certificates are not supported
  • Server - hosting - setup:
    • Ability to run scheduled jobs (crontab) with PHP 5
    • Ability to override options in .htaccess files

This list is rather daunting and can be confusing to those who are new to the world of Magento development.

Magento published a small PHP file that checks the PHP extensions required for Magento to run. There is one thing Magento did not account for. Developers might not be using a LAMP stack to develop and run for Magento. I personally use XAMPP running on Windows 7. There is a shell_exec function in the original file that does not account for Windows-based systems.

We have created a small gist on github that checks your MySQL version using the mysql_get_server_info() function. This pulls your MySQL client version from phpinfo() rather than issuing a BASH command.

A copy of the gist can be found here: https://gist.github.com/4383809/download. Feel free to download and check your system!

Clean Magento Databases

0

Web application have a unique way of killing themselves it seems. Thankfully, magento has a nice database repair utility where you can compare a clean and working database against a corrupt database. If there are any indiscretions in the corrupted database, they will be resolved like magic! The best database to use as the "clean" one is a brand-spanking new database from a fresh off the press magento installation. However, magento is bloated and takes forever to install and maybe we simply don't want to wait.

Amazingly enough, we have finally compiled various magento version databases! No longer do you need to wait for things to install and consume bandwidth and disk space on your local machines or servers. It's as easy as downloading, extracting, and then importing the database on your local machine or server.

  • Installed on Win 7 x64_86
  • Installed via XAMPP 1.8.0
  • Apache 2.4.2
  • MySQL 5.5.25a
  • Exported in UTF-8 Encoding

SSH Access

Run the following commands:

mysql -u username -p

CREATE DATABASE mage_XXXX_clean; # Replace XXXX with the four-digit version
CREATE USER 'user_name'@'localhost' IDENTIFIED BY 'some_pass'; # Replace user_name with a username and some_pass with a password
GRANT ALL PRIVILEGES ON mage_XXX_clean.* TO 'user_name'@'localhost'; # Make sure mage_XXXX_clean is the name of the database you just created
quit

mysql -u user_name -p mage_XXXX_clean < mage_XXXX.sql

That's it, the database is now imported and ready to be used. Open up the database repair script, enter your credentials for your two databases and wait for the script to run.

cPanel

If you are fortunate enough to have cPanel then follow the steps below:

  1. Create a database
  2. Create a user
  3. Add user to database with all privileges
  4. Extract clean magento database
  5. Rename clean mage database to the database that was just created e.g. somethin_mageclean.sql (most cPanel installs will have the first 8 letters of your domain name as the user portion)
  6. Navigate to backup in cPanel and find the restore database option
  7. Upload the clean database .sql file

phpMyAdmin

  1. Click on databases and create a new database as Collation
  2. Navigate to users and either create a new user or add an existing user to the newly created database
  3. Select the recently created database and navigate to the import tab
  4. Upload database

In the event you encounter errors using this method, disable foreign key checks:

  1. With the database selected, go the the SQL field and enter in: SET foreign_key_checks = 0;
  2. Upload database
  3. When upload is complete run SET foreign_key_checks = 1;

Note: If your version isn't here, it will be soon! All databases will be gzipped. You will need a utility to extract them such as 7-zip

Magento Version Database Download Link
Magento CE 1.7.0.2 Magento CE 1.7.0.2 Database (891)
Magento CE 1.7.0.1 Magento CE 1.7.0.1 Database (572)
Magento CE 1.7.0.0 Magento CE 1.7.0.0 Database (568)
Magento CE 1.6.2.0 Magento CE 1.6.2.0 Database (628)
Magento CE 1.6.1.0 Magento CE 1.6.1.0 Database (625)
Magento CE 1.6.0.0 Magento CE 1.6.0.0 Database (608)
Magento CE 1.5.1.0 Magento CE 1.5.1.0 Database (579)
Magento CE 1.5.0.1 Magento CE 1.5.0.1 Database (610)
Magento CE 1.4.2.0 Magento CE 1.4.2.0 Database (604)
Magento CE 1.4.1.1 Magento CE 1.4.1.1 Database (593)
Magento CE 1.4.1.0 Magento CE 1.4.1.0 Database (595)
Magento CE 1.4.0.1 Magento CE 1.4.0.1 Database (604)
Magento CE 1.4.0.0 Magento CE 1.4.0.0 Database (577)

Using hover events with Magento cartdrop Extension

0

Many of you know that Magento is an open source E-Commerce platform that comes with many great features. One feature in particular I wish they would integrate automatically is the ability to show recently added items to your shopping cart via the header. Rather than reinventing the wheel, we can use a pre-made extension! http://www.magentocommerce.com/magento-connect/sharplogicians-cart-drop-down-3832.html. This handy extension is made by Sharp Logicians and is pretty nice. My only complaint about this is they chose to use a click event instead of a hover event. Click events can be misleading in my opinion. I have compiled a little tutorial and how to successfully covert their click event into a nice hover-over sliding element. The features include:

  • Animation queue buildup prevention
  • Animation queue rapid hover issues
  • 100% compatible with chrome, firefox, opera, safari, IE 7 - 10
  • No extra CSS required, use what the extension gives you already!

The Code

Note: if you just want the code click here.

The basic syntax of the jQuery hover event is as follows:

$('element').hover(
     function() {
          // code when moused over
     },
     function() {
          // code when moused out
     }
);

We know we want the element the slide down when we mouse over the link and we want it to slide up when we take our mouse off of the link. Our natural thought might be to write something like $j("span.trigger").hover(function()... but this will essentially make it impossible to use this extension. We need to be more broad about this. To visualize this important difference, see this fiddle we made http://jsfiddle.net/atomicpages/peBVU/!

That being said, we can take a quick look at the code and we see the parent element is .cartdrop. This is the element that we want to select when hovering because it is the parent element.

$j('.cartdrop').hover(
     function() {
          $j('.toggle_container').slideDown(300);
     },
     function() {
          $j('.toggle_container').slideUp(300);
     }
);

This provides very basic functionality and does the job quite well! We have one issue here though, animation queue build up. If you don't know what this is, checkout the jsfiddle page and then on the first example rapidly move your cursor on and off the element. If you take your mouse away you will notice the animation continues. We can easily prevent this from happening!

$j('.cartdrop').hover(
     function() {
          $j('.toggle_container').stop().slideDown(300);
     },
     function() {
          $j('.toggle_container').stop().slideUp(300);
     }
);

We can just add .stop() to stop the current animation from progressing. More documentation can be found here: http://api.jquery.com/stop/.

We had an issue with just using the stop method and using .stop(true, true) or .stop(true) using Google Chrome. We found a good solution was to actually set the height of the element as soon as we hover over the element.

  • .promise() - "Return a Promise object to observe when all actions of a certain type bound to the collection, queued or not, have finished."
  • .done() - "Add handlers to be called when the Deferred object is resolved."

For some reason this fixed all of our issues relating to the animation queue. To see the issue in action see here:

We found that adding the height of the .toggle_container right when the element is hovered over and changing the height to 0, this prevent any issues from happening. The full code is below:

/**
 * Custom jQuery script to handle hovers on cartdrop extension
 * @author Dennis Thompson AtomicPages LLC <http://www.atomicpages.net/>
 * @copyright AtomicPages LLC
 * @license MIT <http://opensource.org/licenses/mit-license.php/>
 */
var height = $j('.toggle_container').height();
$j('.cartdrop').hover(
     function () {
	$j('.toggle_container').addClass('open');
	$j('.toggle_container').css('height', height); // set the height
	$j('.toggle_container').stop().slideDown(300);
     },
     function () {
	$j('.toggle_container').removeClass('open');
	$j('.toggle_container').stop().slideUp(300);
	$j('.toggle_container').promise().done(function () { // let's wait until the animation is complete
		$j('.toggle_container').css('height', 0); // when animation is done set height to 0
	});
     }
);


Download the script!

Fixing Can’t get filling percentage magento error

2

Fixing magento errors can be quite cumbersome especially when you only receive a log message and magento saying that it can't produce any output for security reasons. One error we encountered was quite puzzling and involved an issue with memcached and the native magento caching.

"Can’t get filling percentage"

Is the error we're going to touch base on today. The only prerequisite is that you must have memcached installed. This tutorial only covers a fix to this error when caused by memcached.

Note: it is imperative that memcached is actually running. Type:

service memcached restart

If you encounter any error, contact your webmaster or troubleshoot the issue. We don't necessarily want to use service memcached reload here because it may or may not give us any errors.

Step 1

Verify your app/etc/local.xml file and make sure you. Here is the configuration we used and it works quite well for us:

<config>
	<global>
		<install>
			<date><![CDATA[Thu, 24 Mar 2012 08:15:24 +0000]]></date>
		</install>
		<crypt>
			<key><![CDATA[foobar]]></key>
		</crypt>
		<disable_local_modules>false</disable_local_modules>
		<resources>
			<db>
				<table_prefix><![CDATA[]]></table_prefix>
			</db>
			<default_setup>
				<connection>
					<host><![CDATA[localhost]]></host>
					<username><![CDATA[foo]]></username>
					<password><![CDATA[bar]]></password>
					<dbname><![CDATA[foo]]></dbname>
					<active>1</active>
				</connection>
			</default_setup>
		</resources>
		<session_save><![CDATA[db]]></session_save>
		<!-- begin cache config -->
		<cache>
			<prefix>alphanumeric</prefix>
			<backend><![CDATA[memcached]]></backend>
            <slow_backend><![CDATA[database]]></slow_backend>
			<memcached>
				<servers>
					<server>
						<host><![CDATA[127.0.0.1]]></host>
						<port><![CDATA[11211]]></port>
						<persistent><![CDATA[1]]></persistent>
						<weight><![CDATA[1]]></weight>
						<timeout><![CDATA[10]]></timeout>
                        <retry_interval><![CDATA[10]]></retry_interval>
                        <status><![CDATA[1]]></status>
					</server>
				</servers>
				<compression><![CDATA[0]]></compression>
                <cache_dir><![CDATA[]]></cache_dir>
                <hashed_directory_level><![CDATA[]]></hashed_directory_level>
                <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
                <file_name_prefix><![CDATA[]]></file_name_prefix>
			</memcached>
		</cache>
		<!-- end cache config -->
	</global>
	<admin>
		<routers>
			<adminhtml>
				<args>
					<frontName><![CDATA[admin]]></frontName>
				</args>
			</adminhtml>
		</routers>
	</admin>
</config>

Verifying that your config file is correct, we need to do one more thing to make sure that magento actually sees this updated config file and not your old cached copy.

With SSH

Navigate to your document root of your magento install.

cd var/cache
rm -rf *

The above commands will completely clear out any remaining cache that magneto might be reading from. Reload your site and see if the issue persists.

With FTP/SCP

Open your favorite FTP/SCP client and navigate to the directory where magento is installed.
Open the var directory
Open the cache directory
Select all of the items and press delete.

Open var/sessions and delete all of the contents in there IF you are using your file system to store the sessions.

Via SSH:

cd /path/to/magento/
rm -rf var/cache/*
# use the following code if you are using your file system to store session data
# if you are not sure then check the app/etc/local.xml file
# look for <session_save><![CDATA[files]]></session_save>
rm -rf var/session/*

If you are using your database to store sessions, be sure you clear these too otherwise the error can persist!
Open phpmyadmin and truncate the core_session table or do it via command-line (see below):

mysql -p -u username database
mysql> TRUNCATE TABLE core_session;

Step 2

Seeing the same error or even a different error? Fear not! We still have some tricks up our sleeves.
Assuming the pecl extension is correctly configured then type the following WHILE logged onto your server via ssh. We must be on the server for this to work.

telnet 127.0.0.1 11211
flush_all

You will see the following output:

telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
flush_all
OK

You have successfully cleared the cache. Try reloading your page now and it should resolve this error.

If this does NOT resolve your error, post comments on this post and any solutions you have found!

Upgrading Magento 1.5.0.1 to 1.6.2.0

3

Upgrading Magento is always scary - kind of like flashing your BIOS on a PC. It is always important to backup your entire file system and magento database prior to upgrading to the most recent version to avoid catastrophic results.

This tutorial is for those of you who are at whits end and you just want to curl up and die in a hole because you attempted to upgrade magento and you encountered errors like:

Error in file: "app/code/core/Mage/Sales/sql/sales_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php" - Column "base_shipping_hidden_tax_amount" does not exists on table "sales_flat_creditmemo"

Error in file: "/app/code/core/Mage/Customer/sql/customer_setup/mysql4-upgrade-1.5.9.9-1.6.0.0.php" - SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '0-918' for key 'UNQ_BY_CUSTOMER'

Not only are these errors annoying but magento has a very unhelpful error system that often gives cryptic errors or it stores them in random files in the /var/reports directory.

Before you begin any of this, be sure to back up your entire file system.

Fixing Integrity constraint violation: 1062 Duplicate entry '0-918' for key 'UNQ_BY_CUSTOMER'

This fix actually isn't too bad as you might think. Even if you have no coding experience or experience connecting to your server via FTP, this will be easy.

If you are not familiar with connecting to a server via FTP, we have a lovely tutorial explaining how to do this. If you are familiar then please continue reading!

Navigate to the root of your magento installation and find the app directory. Once there, enter the app directory and then enter the etc directory. You will see a few files (see image).

Open the config.xml file in your favorite text editor (we recommend using notepad++ for ease of use for those of you who do not have an IDE). Around line 41 you will see the following:

<initStatements>SET NAMES utf8</initStatements>

Comment out this line like the following:

!-- <initStatements>SET NAMES utf8</initStatements> -->

And then add this line below the commented out code

<initstatements>SET NAMES utf8; SET FOREIGN_KEY_CHECKS=0; SET UNIQUE_CHECKS=0;</initstatements>

Now that this issue is resolved, try to load your magento site again. Your site is working again! But there may be a greater issue here so keep reading...

Fixing Column "base_shipping_hidden_tax_amount" does not exists on table "sales_flat_creditmemo" or other MySQL Related Errors

If you have the error above or you have other general MySQL errors in magento then there still is hope.

Step 1

Navigate to the /var/cache directory of your magento installation and delete all of the cache.
Navigate to the /var/sessions directory of your magento installation and delete all of the sessions.

Step 2

Go to this the magento website or download the magento database repair tool directly. Unzip this file and you will see a php file.

Place the php file in the root directory of your magento installation and continue to the next step.

Step 3

Install a fresh copy of Magento CE 1.6.2.0 or you can simply download this sample database for reference if you would like to avoid having to install a fresh copy of magento.

Import the fresh database via phpMyAdmin (or by using your favorite database managment tool) and wait until it is fully completed with NO errors! Remote databases are OK.

Note: if you are accessing your database via ssh then see here:
To export an entire database:
mysqldump -u username -p database_name > database_name.sql

To import an entire database:
mysql -u username -p database_name < database_name.sql

Step 4

Now that you have a copy of the database you can upgrade with and that we can reference, it is time to finally repair this database and get it working! We need to download the Magento Database Repair Tool.

Step 5

Extract the file anywhere within your file system (the document root directory will suffice) and then type in your web browser: http://yourdomain.com/magento-db-repair-tool-1.0.php and you will see this page:
Magento Database Repair Tool

Note: this script doesn't care where the databases are located. You can connect to a remote database or a database that is on your localhost. Just ensure you enable access to your database remotely via your hosting control panel.

Type in the required information (be sure to include any and all prefixes you have) and then click continue. This script will match the corrupted database to the good database and repair any incorrect SQL table structures and repair any important data in those tables. Things like usernames, password, products will NOT be affected so do not worry!

When this process is complete you will see the following:
Magento Database Repair Complete

Final Step

Try entering in the URL of your magento installation to ensure everything worked correctly. If it did not then restore your file system and database and make sure you went through the motions correctly. Be sure to document and research any errors on the magento forums and see if anyone else has encountered/solved these errors!

But remember that line of code we replaced?

<initStatements>SET NAMES utf8</initStatements>

Be sure to replace our edited line of XML with the original as this is a security risk!

Hope this helps all those out there that are struggling with this!

Go to Top