Showing posts with label tips. Show all posts
Showing posts with label tips. Show all posts

Sunday, 4 October 2015

Reset admin password

Dive in the code of password validation

Open app/code/core/Mage/Admin/Model/Session.php and find the function called 'login'. And the code below should be found in the function.
$user->login($username, $password);

Open app/code/core/Mage/Admin/Model/User.php and find the login function. The following code will be spotted.
if ($this->authenticate($username, $password)) {

Follow the 'authenticate' method and you will find the code
Mage::helper('core')->validateHash($password, $this->getPassword()

Open app/code/core/Mage/Core/Helper/Data.php and move to 'validateHash' method. There is only one sentence of code:
$this->getEncryptor()->validateHash($password, $hash);

Open app/code/core/Mage/Core/Model/Encryption.php which is literally the password validation method.

$hashArr should be an array comprised of two elements. The first element is the hashed password and the last element is the random hash key, and the hash method follows the equation below:
Hashed Password = md5(Actual Password + Hash Key)

The password value in the database is a string which consist of Hashed Password as the first part and Hash Key as the second part and these two parts are delimited by a colon symbol(:)

Update the password by sql query

select password from admin_user where user_id=1; #user_id 1 should be replaced by the user_id whose password needs to be updated

A result, which is similar as ceccc111cf1c3600a7ad5d464934ea24:HH6gy344GGuoZzDm3U6dKSoXPcpuqIsQ, will be found.

If you want to use 123 as your password, execute the following sql query in the database:
select md5('ceccc111cf1c3600a7ad5d464934ea24123');# the result is 6711eaa5577250a42aefdb9c04ad90ed

Use the sql query below to update the password:
update admin_user set password='6711eaa5577250a42aefdb9c04ad90ed:HH6gy344GGuoZzDm3U6dKSoXPcpuqIsQ' where user_id=1 limit 1;

Here we are and the new password can be used to log in the admin


Wednesday, 10 June 2015

Add a responsive banner slider

As most of the websites are having a banner slider, it's a required web skill of adding a responsive slider. Here I will write down how to get a slider for Magento by using some slider extensions

First, I'm going to describe how to use Magento Responsive Banner Slider extension. 

Download the extension from the URL: http://www.magentocommerce.com/magento-connect/responsive-banner-slider.html
Install it from Magento Connect Manager if your Magento version is before 1.9. Otherwise, you need to manually download the module and copy the the files to your Magento folder. Cause there is an installation bug in this extension for Magento 1.9.
Go to System->Configuration->MKS Responsive Banner and click the general settings of the extension. Fill out the banner settings form which suits your website.
Go to Responsivebannerslider->Manage Responsivebannerslider. You will be led to a page where the images of the slider can be uploaded and set and you can add as many images as you want for the slider.
Put the below block code in the CMS pages  or any template files where you want to add the slider.
{{block type="responsivebannerslider/index" name="responsivebannerslider_index" template="responsivebannerslider/index.phtml"}}


Friday, 5 June 2015

Solution of Magento Common Errors

CMS: Upload Image icon doesn't show up when clicking Insert a Image icon

Since uploading image needs the permission of Media Gallery, so we need to add this permission to the user which was used to manage CMS system in order for the user to have the ability to upload and insert images.

CMS: The directory is not writable by the server

The error might occur when trying to upload images in CMS. 
The reason is that CMS is trying to upload images to media/wysiwyg folder, but the folder was not created when Magento installed. Therefore, what we need to do is just to create the folder and make sure nginx/php user has the permission of it.

Magento Connect: 404 Not found

I got some answers from the internet which were all about the permission of downloader/index.php and some folders. You can clear cache using magento-clear-cache.php.
However, the cause of my issue is that the configuration of Ngninx. In my configuration I didn't rewrite dowloader/ to dowloader/index.php which might be a common mistake if nginx is used as PHP server, because .htaccess file which is doing the rewrite in Magento won't take effect under nginx.
To figure out whether this is the one causing your 404, you just need to put index.php manually after downloader URL to see whether it will work or not. If it works, then you have the same issue as mine.
To solve the issue, you just need to adjust the nginx configuration to make the rewrite also worked for downloader folder.


Thursday, 4 June 2015

Magento Re-index from shell which is super-useful for large data store

Reason of re-indexing from shell

Magento do provide the functionality of re-indexing in admin pane, but it might cause some timeout failure, which may brings a somewhat failure of re-indexing procedure, because of php execution limit and nginx/apache timeout. However, the shell script can avoid the timeout and execution limit, so it's better to re-index from shell for large data stores.

How to re-index from shell

Log on the website server and go into the Magento root directory.
Run the command of php shell/indexer.php help which will show the manual of using the script.

Here are some useful commands provided by the script

Get a list of indexers: php shell/indexer.php info
Get the status of current indexes: php shell/indexer.php --status
Re-index all: php shell/indexer.php reindexall #which is not recommended especially for large data website
Run one of the indexers: php shell/indexer.php --reindex indexer #indexer is coming from the list of indexers

Magento index modes

There are two Magento index modes. The first one is 'Update on save' which means the index will be rebuilt whenever the change related to the index has been made. While the other one is 'Manual Update' which makes the re-indexing executed only when the re-indexing command is ran manually or it's operated in the admin panel.
To conclude, it's highly recommended to set the mode to 'Manually update' for large data stores.

Set up Magento index modes

Set the mode to 'Update on save': php shell/indexer.php --mode-realtime indexer #indexer is from the index list
Set the mode to 'Manually save': php shell/indexer.php --mode-manual indexer #indexer is from the index list
After it's set to 'Manually save', the re-indexing command need to be added in the Linux cron table  to make rebuilding the index took place at a specific time which is supposed to be an idle time.
Note: the index mode should be set to 'Manually save' when doing any importation or it will be very slow for the importing process.

What if the re-indexing process is stuck for some reason

Restart nginx and php-fpm to stop the process. 
Go into the root directory of Magento and check the locks under the folder of var/locks/. And delete the locks if you want to stop the stuck process.
Go into Mysql and  check the table named index_process. And set the status from working to pending if you want to stop the stuck process.
Use indexer script to check the status of indexers to make sure there is no running indexers.
Run the indexer from shell instead of from the admin panel.

What are the statuses of indexers and their meanings

In Magento there are three statuses of indexers, which are quite confusing from the names,  comprising 'pending', 'working' and 'require reindex'.
'pending' means the index has been rebuilt and there is no need to re-index it.
'working' indicates the re-indexing process of the index is running.
'require reindex' shows the index is out of date and it needs to be rebuilt.


Monday, 1 June 2015

Disable Magento Cache for Dev Purpose

Go into admin System->Cache Management

Disable all of the caches under this menu by selecting all the check boxes and choosing disable as the option.

After some changes in Magento, the index cache might need to be cleared

Go into System->Index Management to check whether there are indexes that need to be refreshed.

Magento Compilation is disabled by default, but it's better to check it in case something cached by it.

Go into System->Tools->Compilation, and disable it if it's enabled for some reason.

The changes of admin menu may probably not show up immediately after all the cache-related functionality has been disable

After disable all of the cache, there is an essential step to do which is log-out and re-log in Magento

Tuesday, 5 May 2015

Custom Layout not loaded

The cause of this issue 

The handle name is always lower-cased by magento which led my failure of loading my layouts.

An efficient way to sort it out

Magento's front-end including handles, layouts, blocks and templates. Among all of them, handles are the only kind of things that will cause failing to load the layouts without any errors or notices. So print the handles in the controller and compare it with the handles defined in the layout XML file.

Here is what I did. First, use the below code to print the handles in the controller:
var_dump($this->getLayout()->getUpdate()->getHandles());

Then, copy the handle name called 'importjson' in my case and search it case-sensitively in the layout file. The result is that 'importjson' couldn't be found in the file that only contains the string of 'importJson'.

To conclude, in Magento we should always pay attention to case-sensitive which could cause numerous issues and cost us a lot time to figure it out.

Tuesday, 14 April 2015

How to re-install module database

Where in database does magento record the database set-up of the module?

All of the modules and their database set-up versions are recorded in the table named 'core_resource'.

The steps of re-installing a module

1. Disable the module in the app configuration file located in the folder of 'app/etc/modules/' by changing the value of 'active' from true to false.

2. Find the module set-up record in the database table of 'core_resource' and delete the record.

3. Refresh any page of magento site and the module will be newly installed.