Magento Code Snippets Archives - ACTIVO

Add Magento Admin User Using MySQL Script

Posted by | Magento Code Snippets | No Comments

This script quickly adds a Magento Admin user directly into the database. It is possible to run this script from the command line or by copying and pasting into phpMyAdmin. Just make sure to edit the following fields with your personalized data and import. Most of these fields are trivial, I’m just listing them so you don’t miss anything.

  1. Set the salt portion of your password. You’ll rarely need to change this. If you do, just use two lower case letters of your choice.
  2. Set your password. At least 8 characters in length and at least one digit.
  3. Firstname: Enter admin’s first name.
  4. Lastname: Enter admin’s last name.
  5. Enter email of admin user.
  6. Enter username where ‘myuser’ is set. Notice ‘myuser’ shows up in two places.
  7. Enter Firstname again. This is more symbolic to label the rule.
 

shrink-magento-database

Shrinking Database Size for Magento

Posted by | Magento Code Snippets | No Comments

If you ever managed a medium to large Magento shop you very well know that its database size can grow quite a bit. In particular if the site has sizable catalog, large amount of traffic, and a nice number of daily orders. All of that translates to large increases in DB size.

What is not well understood is that Magento by default stores a lot of information that is not crucial for its overall operation. By default Magento stores some level of traffic logs, reports, and dataflow export/import information. Most of which is only needed in case one is debugging and troubleshooting certain operations of the eCommerce platform. Here is a small script I often use before I dump (using the command line mysqldump) the entire database:

The way I use it by issuing the following command line:

In some cases I was able to shrink the size of the DB from 1GB down to a 100M-200M in size. I hope you will find it useful.

TIP: you can save yourself additional space and repetitive cleaning by commenting out the observers that actually add the log information to the DB.

How to Check for HTTPS in Magento phtml Files?

Posted by | Magento Code Snippets | No Comments

These days our eCommerce pages are littered with third party social bookmarking tools, social media tools, facebook like buttons, add this buttons, and third party marketing scripts. It is easy to lose track of the most basic aspect of your shopping carts’ security: valid HTTPS pages. Here is a quick way to isolate all of these third party utilities and simply avoid using them in the HTTPS pages:

Read More

Bulk Copying Product Attributes in Magento

Posted by | Magento Code Snippets | No Comments

This static method can copy attributes between products in Magento very fast and relatively secure. We are bypassing the main Magento architecture and accessing the Database directly, but notice we are using the Zend framework for the db query and we still use DB transactions. It accepts the source product ID (not SKU), destination product ID, the array of attribute codes (‘size’, ‘color’, ‘name’, etc.), and the attribute type (‘varchar’, ‘int’, etc.).

Read More

How to Avoid the ‘___from_store’ Query Parameter When Switching Store Views in Magento

Posted by | Magento Code Snippets | No Comments

This is a simple fix that makes a big difference. For some reason it is set to show up by default, however some websites that are sensitive to SEO or want to avoid this parameter so you do not get any weird values in Google Analytics or any other Analytics that you may be using, here is how to remove the ‘___from_store’ query string:

Read More