Magento: Admin login redrecting to old url after a url change (even though the database was updated)

If you have the problem that you have moved a magento database (and perhaps files to) from one server to another, you have update
web/unsecure/base_url & web/secure/base_url in the database to point at the new address, but the admin panel login is still redirecting to the old address, then the solution is fairly simple.

Make the var folder writable to the web server and clear out the var/session and var/cache folders.

Magento: Enabling Template/Block Hints in the Admin Panel

If you would like to turn on Template hits and block names in the admin panel this can be quickly done via the database.

INSERT INTO core_config_data (scope, scope_id, path, VALUE)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1);

Note, don’t forget to add your prefix if you are using one.

To turn this off once you are done, either delete these rows from the database, or set the values to 0. (If you set them to 0 you can later reactivate this by just swapping it back to 1, but the insert statement won’t work any more.

Magento deleting test orders (clearing orderhistory)

Just ran into the case that I needed to clear the order history of a magento installation (basically we had made fake orders when we were testing and wanted the statistics to be correct when we started for real).

Executing the following in the database solved this issue (warning if you are using a database prefix, don’t forget to update this script before executing)

SET FOREIGN_KEY_CHECKS=0;
 
-- reset orders 
TRUNCATE `sales_order`;
TRUNCATE `sales_order_datetime`;
TRUNCATE `sales_order_decimal`;
TRUNCATE `sales_order_entity`;
TRUNCATE `sales_order_entity_datetime`;
TRUNCATE `sales_order_entity_decimal`;
TRUNCATE `sales_order_entity_int`;
TRUNCATE `sales_order_entity_text`;
TRUNCATE `sales_order_entity_varchar`;
TRUNCATE `sales_order_int`;
TRUNCATE `sales_order_text`;
TRUNCATE `sales_order_varchar`;
TRUNCATE `sales_flat_quote`;
TRUNCATE `sales_flat_quote_address`;
TRUNCATE `sales_flat_quote_address_item`;
TRUNCATE `sales_flat_quote_item`;
TRUNCATE `sales_flat_quote_item_option`;
TRUNCATE `sales_flat_order_item`;
TRUNCATE `sendfriend_log`;
TRUNCATE `tag`;
TRUNCATE `tag_relation`;
TRUNCATE `tag_summary`;
TRUNCATE `wishlist`;
TRUNCATE `log_quote`;
TRUNCATE `report_event`;
TRUNCATE `sales_order_tax`;
TRUNCATE `sales_flat_quote_shipping_rate`;
TRUNCATE `sales_flat_quote_payment`;
 
ALTER TABLE `sales_order` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_int` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_text` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_varchar` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_address_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_item_option` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_order_item` AUTO_INCREMENT=1;
ALTER TABLE `sendfriend_log` AUTO_INCREMENT=1;
ALTER TABLE `tag` AUTO_INCREMENT=1;
ALTER TABLE `tag_relation` AUTO_INCREMENT=1;
ALTER TABLE `tag_summary` AUTO_INCREMENT=1;
ALTER TABLE `wishlist` AUTO_INCREMENT=1;
ALTER TABLE `log_quote` AUTO_INCREMENT=1;
ALTER TABLE `report_event` AUTO_INCREMENT=1;
ALTER TABLE `sales_order_tax` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_shipping_rate` AUTO_INCREMENT=1;
ALTER TABLE `sales_flat_quote_payment` AUTO_INCREMENT=1;
 
-- reset customers
TRUNCATE `customer_address_entity`;
TRUNCATE `customer_address_entity_datetime`;
TRUNCATE `customer_address_entity_decimal`;
TRUNCATE `customer_address_entity_int`;
TRUNCATE `customer_address_entity_text`;
TRUNCATE `customer_address_entity_varchar`;
TRUNCATE `customer_entity`;
TRUNCATE `customer_entity_datetime`;
TRUNCATE `customer_entity_decimal`;
TRUNCATE `customer_entity_int`;
TRUNCATE `customer_entity_text`;
TRUNCATE `customer_entity_varchar`;
TRUNCATE `log_customer`;
TRUNCATE `log_visitor`;
TRUNCATE `log_visitor_info`;
 
ALTER TABLE `customer_address_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_address_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_datetime` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_decimal` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_int` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_text` AUTO_INCREMENT=1;
ALTER TABLE `customer_entity_varchar` AUTO_INCREMENT=1;
ALTER TABLE `log_customer` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor` AUTO_INCREMENT=1;
ALTER TABLE `log_visitor_info` AUTO_INCREMENT=1;
 
-- Reset all ID counters
TRUNCATE `eav_entity_store`;
ALTER TABLE  `eav_entity_store` AUTO_INCREMENT=1;
 
 
-- Clear logs
TRUNCATE `log_url_info`;
TRUNCATE `log_url`;
 
ALTER TABLE `log_url_info` AUTO_INCREMENT=1;
ALTER TABLE `log_url` AUTO_INCREMENT=1;
 
SET FOREIGN_KEY_CHECKS=1;

This is mostly based on a very nice post by the guys at inchoo

And it should go without saying, make a backup before trying this out.
(was tested on 1.3.2.4)

Magento: Invalid transactional email code: x

If you start seeing this error (both when trying to order) and as emails to the sales address then the error is most likely that someone has deleted the template with id x but that is still set to be used in the database.

The solution for this is to update “System-Configuration-Sales Emails” in admin and save existing templates instead of the template that is now removed.

Note: Also it might be good to consider why this happened, is there some (real) problem or was the template file(s) updated and some old database template was removed [perhaps there is an educational need].

Magento: Send åäö (and other international characters) to DIBS

If your store uses DIBS to manage payments, then the risk is that you have to worry about characters like åäö.

What we had to do is to make the form post the data as ISO-8859-1.
We did this by adding accept-charset=”iso-8859-1″ to the forms that we send to DIBS.

In “/app/design/frontend/default/blank/template/dibs/standard/redirect_paymentwindow.phtml”

56
<form action="https://payment.architrade.com/paymentweb/start.action" method="post" name="dibs" id="dibs" accept-charset="iso-8859-1">

Once we had done this then the order details were shown correctly on the DIBS page (yes, the Chinese chars are just a test, I have no idea what it might say)
Details on DIBS including åäö

Magento: Adding piwik tracking

Using piwik to track Magento visitors is a easy thing to do.

In Magento Connect there is a plugin to install

See my earlier post if you don’t wish to turn your site to alpha on all packages.

For the settings, most are self explaining, the token can be found in piwik under API and is labeled API key, please read the warnings about using it and consider if you will need it.

Magento: Failed to download package X within preferred state “stable”, latest release is version 0.4, stability “alpha” (or “beta”), use “channel://…

If you do not wish to move your entire server to use alpha mode (or beta) but keep the mainline in stable, but still wish to install the actual package; you just
enter the information from channel and on and the plug in will install.

$:/var/www/magento$ ./pear install magento-community/Florent_Piwik
Failed to download magento-community/Florent_Piwik within preferred state "stable", latest release is version 0.4, stability "alpha", use "channel://connect.magentocommerce.com/community/Florent_Piwik-0.4" to install
install failed
$/var/www/magento$ ./pear install channel://connect.magentocommerce.com/community/Florent_Piwik-0.4
downloading Florent_Piwik-0.4.tgz ...
Starting to download Florent_Piwik-0.4.tgz (4,163 bytes)
.....done: 4,163 bytes
install ok: channel://connect.magentocommerce.com/community/Florent_Piwik-0.4

Magento: Starting SOAP (adding a user)

In order to get SOAP up and running you will need to add a web services user in the admin panel.

    First add a role for the user. (Roles are used to limit the permissions of the user)

    • System->Web Services->Roles->Add new role
    • Give the role a name
    • Set permissions for the role
  • Then create the user with these permissions
    • System->Web Services->Users->Add new user
    • Add information about the user (the API key is the password used for SOAP)
    • Under roles bind the user with the previously created role

Magento: Installing on a debian server

To install magento on a fresh server use the following.

  • Install apache, mysql and PHP5 “$ apt-get install apache2 mysql-server php5 php5-mysql php-soap php5-mcrypt php5-curl php5-gd”
  • Edit the vhost config for the apache site [/etc/apache2/sites-enabled/000-default]
    • Verify that “AllowOverride” is set to All for the magento directory
  • Make sure that mof_rewrite is loaded; use “$ a2enmod rewrite” and then reload apache2
  • Edit /etc/php5/apache2/php.ini
    • “memory_limit” [the manual says] no less than 256Mb (preferably 512)
    • “max_execution_time” [this is the max time that a script may be left running] SOAP requests take time, so make suer it is at a reasonable time
    • “upload_max_filesize” Set this to a size that is reasonable depending on what you plan to upload (manuals might be large)
    • “post_max_size” Set this to a size that is reasonable depending on what you plan to post (manuals might be large); also make sure that the value and the modifier is correct (so that it says 8M and not just 8 for instance)
    • “display_errors” Set to Off
    • “log_errors” Set to On
    • “error_log” Set to a file that you will be able to find [if you wish to have it in a subdir; create that as root and give it permissions as apache log dir]
  • download magento (lastest version from magento
  • Upack it (I choose bzip2 format) “$ tar -jxvvf magento-downloader-1.3.2.1.tar.bz2” and make sure the files gets put in the directory you wish
  • Some directories have to be writable to the webserver (and all subdirectories, where there are)
    • var
    • var/.htaccess
    • app/etc
    • media
  • If you are using the downloader installation
    • “$./pear mage-setup .”
    • “$./pear install magento-core/Mage_All_Latest”
    • “$rm -rf downloader/pearlib/cache/* downloader/pearlib/download/*”
  • Create database and database user [this is to do it manually via mysql console]
    • “$mysql -uroot -p”
    • “mysql> create database magento;”
    • “mysql> use mysql;”
    • “mysql> INSERT INTO user (Host,User,Password) VALUES (‘localhost’, ‘magento’, PASSWORD(‘password’));”
    • “mysql> GRANT ALL ON magento.* TO ‘magento’;”
    • “mysql> FLUSH PRIVILEGES;”
    • “mysql> exit”
  • Go to the webserver and complete the installation
  • If you get stuck on the configuration page [that you get back to it even after adding correct information]:
    • Check “AllowOverride” in the apache config.
    • Check “post_max_size2 in the php.ini [also check so that the value is either absolute or has a modifier; 8 means 8 bytes while 8M means 8Mb]

Magento: Selling string (cloth or any other item with a decimal value)

Some items (such as string, cloth, fluids etc) can be sold in decimal values.

This example will show how to sell string in meters (price etc) but where the customer can order any length – but at least 30 centimeters.

In admin->catalog make the string as a product and under inventory set “Minimum Qty Allowed in Shopping Cart” to “0.3” and “Qty Uses Decimals” to yes. Set up the price as the price per meter.
Also please make sure that the information about the product states that the any length (over 0,3 m) can be ordered and that the price is per meter.

When the customer adds 2.5678 m in the basket, magento will calculate the correct price and show it to the customer.